Skip to content

Conversation

@bmeneg
Copy link

@bmeneg bmeneg commented Aug 28, 2017

Correcting the last PR closed: no changes were made on callback interface, thus not breaking Slack/Telegram calls.

This allow implementation of commands/plugins that relies on JOIN events like the "greetings" command that we were thinking about.

A simple example of using this feature would be like the following one:

package greetings

import (
	"fmt"
	"github.com/meleca/bot"
)

func SayHello(cmd *bot.EventCmd) (string, error) {
	if cmd.EventCode == "JOIN" {
		message := "hello " + cmd.User.Nick
		return message, nil
	}
	return "", nil
}

func init() {
	bot.RegisterEventCommand(
		"greetings",
		SayHello)
}

If you guys think something could be done in a better way, please let me know.

PS.: this PR solves issue #1

bmeneg added 2 commits August 28, 2017 10:04
Every message or event that has a callback registered passes its
information through a generic callback interface, which doesn't care
about the source event. It always waits a message to be present, and
because of that it's impossible to register 'events-only' commands.

New field 'EventCode' on 'Message' structure allows callbacks to events
that doesn't require explicit message text, that just the name or code
of that event would be enough.
Add support for commands that relies on JOIN event from users in the
channel. This support to JOIN was made through the new features on
callbacks' interface.

For now, just JOIN event can be monitored by commands.
@bmeneg bmeneg requested review from julianolf and luizdepra August 28, 2017 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant