From 3620208f33c9b466fdbcb45ed6902073f45ac3d6 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Tue, 5 Feb 2019 11:20:43 -0500 Subject: [PATCH] irc: Update IRC connector to new structure --- bot/interfaces.go | 10 ++++++++-- irc/irc.go | 41 +++++++++++++++++------------------------ main.go | 3 +-- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/bot/interfaces.go b/bot/interfaces.go index ec2aa6e..7320ead 100644 --- a/bot/interfaces.go +++ b/bot/interfaces.go @@ -34,12 +34,16 @@ type kind int type Callback func(int, msg.Message, ...interface{}) bool +// Bot interface serves to allow mocking of the actual bot type Bot interface { + // Config allows access to the bot's configuration system Config() *config.Config + // DB gives access to the current database DB() *sqlx.DB + // Who lists users in a particular channel Who(string) []user.User + // AddPlugin registers a new plugin handler AddPlugin(string, Plugin) - // First arg should be one of bot.Message/Reply/Action/etc Send(int, ...interface{}) (error, string) // First arg should be one of bot.Message/Reply/Action/etc @@ -55,6 +59,7 @@ type Bot interface { RegisterFilter(string, func(string) string) } +// Connector represents a server connection to a chat service type Connector interface { RegisterEventReceived(func(message msg.Message)) RegisterMessageReceived(func(message msg.Message)) @@ -68,7 +73,8 @@ type Connector interface { Who(string) []string } -// Interface used for compatibility with the Plugin interface +// Plugin interface used for compatibility with the Plugin interface +// Probably can disappear once RegisterWeb gets inverted type Plugin interface { RegisterWeb() *string } diff --git a/irc/irc.go b/irc/irc.go index 7a89110..086c0c8 100644 --- a/irc/irc.go +++ b/irc/irc.go @@ -66,12 +66,24 @@ func (i *Irc) RegisterReplyMessageReceived(f func(msg.Message, string)) { i.replyMessageReceived = f } +func (i *Irc) Send(kind int, args ...interface{}) (error, string) { + switch kind { + case bot.Reply: + case bot.Message: + return i.sendMessage(args[0].(string), args[1].(string)) + case bot.Action: + return i.sendAction(args[0].(string), args[1].(string)) + default: + } + return nil, "" +} + func (i *Irc) JoinChannel(channel string) { log.Printf("Joining channel: %s", channel) i.Client.Out <- irc.Msg{Cmd: irc.JOIN, Args: []string{channel}} } -func (i *Irc) SendMessage(channel, message string) string { +func (i *Irc) sendMessage(channel, message string) (error, string) { for len(message) > 0 { m := irc.Msg{ Cmd: "PRIVMSG", @@ -95,37 +107,18 @@ func (i *Irc) SendMessage(channel, message string) string { i.Client.Out <- m } - return "NO_IRC_IDENTIFIERS" + return nil, "NO_IRC_IDENTIFIERS" } // Sends action to channel -func (i *Irc) SendAction(channel, message string) string { +func (i *Irc) sendAction(channel, message string) (error, string) { message = actionPrefix + " " + message + "\x01" - i.SendMessage(channel, message) - return "NO_IRC_IDENTIFIERS" -} - -func (i *Irc) ReplyToMessageIdentifier(channel, message, identifier string) (string, bool) { - return "NO_IRC_IDENTIFIERS", false -} - -func (i *Irc) ReplyToMessage(channel, message string, replyTo msg.Message) (string, bool) { - return "NO_IRC_IDENTIFIERS", false -} - -func (i *Irc) React(channel, reaction string, message msg.Message) bool { - //we're not goign to do anything because it's IRC - return false -} - -func (i *Irc) Edit(channel, newMessage, identifier string) bool { - //we're not goign to do anything because it's IRC - return false + return i.sendMessage(channel, message) } func (i *Irc) GetEmojiList() map[string]string { - //we're not goign to do anything because it's IRC + //we're not going to do anything because it's IRC return make(map[string]string) } diff --git a/main.go b/main.go index 18ff59f..95527c8 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,6 @@ import ( "github.com/velour/catbase/plugins/twitch" "github.com/velour/catbase/plugins/your" "github.com/velour/catbase/plugins/zork" - "github.com/velour/catbase/slack" ) var ( @@ -71,7 +70,7 @@ func main() { case "irc": client = irc.New(c) case "slack": - client = slack.New(c) + //client = slack.New(c) default: log.Fatalf("Unknown connection type: %s", c.Get("type", "UNSET")) }