sometimes you have an id, sometimes a message, we should support relpying to both

This commit is contained in:
skkiesel 2017-10-31 10:16:41 -04:00
parent 3009a646e6
commit d9bb7ec3c0
6 changed files with 23 additions and 8 deletions

View File

@ -63,8 +63,12 @@ func (b *bot) SendAction(channel, message string) string {
return b.conn.SendAction(channel, message)
}
func (b *bot) ReplyToMessage(channel, message, identifier string) (string, bool) {
return b.conn.ReplyToMessage(channel, message, identifier)
func (b *bot) ReplyToMessageIdentifier(channel, message, identifier string) (string, bool) {
return b.conn.ReplyToMessageIdentifier(channel, message, identifier)
}
func (b *bot) ReplyToMessage(channel, message string, replyTo msg.Message) (string, bool) {
return b.conn.ReplyToMessage(channel, message, replyTo)
}
func (b *bot) React(channel, reaction string, message msg.Message) bool {

View File

@ -17,7 +17,8 @@ type Bot interface {
AddHandler(string, Handler)
SendMessage(string, string) string
SendAction(string, string) string
ReplyToMessage(channel, message, identifier string) (string, bool)
ReplyToMessageIdentifier(string, string, string) (string, bool)
ReplyToMessage(string, string, msg.Message) (string, bool)
React(string, string, msg.Message) bool
Edit(string, string, string) bool
MsgReceived(msg.Message)
@ -35,7 +36,8 @@ type Connector interface {
SendMessage(channel, message string) string
SendAction(channel, message string) string
ReplyToMessage(channel, message, identifier string) (string, bool)
ReplyToMessageIdentifier(string, string, string) (string, bool)
ReplyToMessage(string, string, msg.Message) (string, bool)
React(string, string, msg.Message) bool
Edit(string, string, string) bool
GetEmojiList() map[string]string

View File

@ -39,7 +39,8 @@ func (mb *MockBot) SendAction(ch string, msg string) string {
mb.Actions = append(mb.Actions, msg)
return fmt.Sprintf("a-%d", len(mb.Actions)-1)
}
func (mb *MockBot) ReplyToMessage(channel, message, identifier string) (string, bool) { return "", false }
func (mb *MockBot) ReplyToMessageIdentifier(channel, message, identifier string) (string, bool) { return "", false }
func (mb *MockBot) ReplyToMessage(channel, message string, replyTo msg.Message) (string, bool) { return "", false }
func (mb *MockBot) MsgReceived(msg msg.Message) {}
func (mb *MockBot) EventReceived(msg msg.Message) {}
func (mb *MockBot) Filter(msg msg.Message, s string) string { return "" }

View File

@ -101,7 +101,11 @@ func (i *Irc) SendAction(channel, message string) string {
return "NO_IRC_IDENTIFIERS"
}
func (i *Irc) ReplyToMessage(channel, message, identifier string) (string, bool) {
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
}

View File

@ -33,7 +33,7 @@ func (p *RPGPlugin) Message(message msg.Message) bool {
}
p.Bot.Edit(message.Channel, "HECK YES", ts)
p.Bot.ReplyToMessage(message.Channel, "How's this reply?", ts)
p.Bot.ReplyToMessageIdentifier(message.Channel, "How's this reply?", ts)
}
return false
}

View File

@ -247,7 +247,7 @@ func (s *Slack) SendAction(channel, message string) string {
return identifier
}
func (s *Slack) ReplyToMessage(channel, message, identifier string) (string, bool) {
func (s *Slack) ReplyToMessageIdentifier(channel, message, identifier string) (string, bool) {
resp, err := http.PostForm("https://slack.com/api/chat.postMessage",
url.Values{"token": {s.config.Slack.Token},
"channel": {channel},
@ -288,6 +288,10 @@ func (s *Slack) ReplyToMessage(channel, message, identifier string) (string, boo
return mr.Timestamp, err == nil
}
func (s *Slack) ReplyToMessage(channel, message string, replyTo msg.Message) (string, bool) {
return s.ReplyToMessageIdentifier(channel, message, replyTo.AdditionalData["RAW_SLACK_TIMESTAMP"])
}
func (s *Slack) React(channel, reaction string, message msg.Message) bool {
log.Printf("Reacting in %s: %s", channel, reaction)
resp, err := http.PostForm("https://slack.com/api/reactions.add",