mirror of https://github.com/velour/catbase.git
listening to thread responses to rpg threads only
This commit is contained in:
parent
d9bb7ec3c0
commit
54b83cd444
|
@ -93,6 +93,7 @@ func New(config *config.Config, connector Connector) Bot {
|
||||||
|
|
||||||
connector.RegisterMessageReceived(bot.MsgReceived)
|
connector.RegisterMessageReceived(bot.MsgReceived)
|
||||||
connector.RegisterEventReceived(bot.EventReceived)
|
connector.RegisterEventReceived(bot.EventReceived)
|
||||||
|
connector.RegisterReplyMessageReceived(bot.ReplyMsgReceived)
|
||||||
|
|
||||||
return bot
|
return bot
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,6 @@ func (b *bot) MsgReceived(msg msg.Message) {
|
||||||
|
|
||||||
// msg := b.buildMessage(client, inMsg)
|
// msg := b.buildMessage(client, inMsg)
|
||||||
// do need to look up user and fix it
|
// do need to look up user and fix it
|
||||||
|
|
||||||
log.Println(msg.User.Name)
|
|
||||||
|
|
||||||
if strings.HasPrefix(msg.Body, "help ") && msg.Command {
|
if strings.HasPrefix(msg.Body, "help ") && msg.Command {
|
||||||
parts := strings.Fields(strings.ToLower(msg.Body))
|
parts := strings.Fields(strings.ToLower(msg.Body))
|
||||||
b.checkHelp(msg.Channel, parts)
|
b.checkHelp(msg.Channel, parts)
|
||||||
|
@ -55,6 +52,18 @@ func (b *bot) EventReceived(msg msg.Message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle incoming replys
|
||||||
|
func (b *bot) ReplyMsgReceived(msg msg.Message, identifier string) {
|
||||||
|
log.Println("Received message: ", msg)
|
||||||
|
|
||||||
|
for _, name := range b.pluginOrdering {
|
||||||
|
p := b.plugins[name]
|
||||||
|
if p.ReplyMessage(msg, identifier) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *bot) SendMessage(channel, message string) string {
|
func (b *bot) SendMessage(channel, message string) string {
|
||||||
return b.conn.SendMessage(channel, message)
|
return b.conn.SendMessage(channel, message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ type Bot interface {
|
||||||
React(string, string, msg.Message) bool
|
React(string, string, msg.Message) bool
|
||||||
Edit(string, string, string) bool
|
Edit(string, string, string) bool
|
||||||
MsgReceived(msg.Message)
|
MsgReceived(msg.Message)
|
||||||
|
ReplyMsgReceived(msg.Message, string)
|
||||||
EventReceived(msg.Message)
|
EventReceived(msg.Message)
|
||||||
Filter(msg.Message, string) string
|
Filter(msg.Message, string) string
|
||||||
LastMessage(string) (msg.Message, error)
|
LastMessage(string) (msg.Message, error)
|
||||||
|
@ -33,6 +34,7 @@ type Bot interface {
|
||||||
type Connector interface {
|
type Connector interface {
|
||||||
RegisterEventReceived(func(message msg.Message))
|
RegisterEventReceived(func(message msg.Message))
|
||||||
RegisterMessageReceived(func(message msg.Message))
|
RegisterMessageReceived(func(message msg.Message))
|
||||||
|
RegisterReplyMessageReceived(func(msg.Message, string))
|
||||||
|
|
||||||
SendMessage(channel, message string) string
|
SendMessage(channel, message string) string
|
||||||
SendAction(channel, message string) string
|
SendAction(channel, message string) string
|
||||||
|
@ -50,6 +52,7 @@ type Connector interface {
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
Message(message msg.Message) bool
|
Message(message msg.Message) bool
|
||||||
Event(kind string, message msg.Message) bool
|
Event(kind string, message msg.Message) bool
|
||||||
|
ReplyMessage(msg.Message, string) bool
|
||||||
BotMessage(message msg.Message) bool
|
BotMessage(message msg.Message) bool
|
||||||
Help(channel string, parts []string)
|
Help(channel string, parts []string)
|
||||||
RegisterWeb() *string
|
RegisterWeb() *string
|
||||||
|
|
|
@ -44,6 +44,7 @@ type Irc struct {
|
||||||
|
|
||||||
eventReceived func(msg.Message)
|
eventReceived func(msg.Message)
|
||||||
messageReceived func(msg.Message)
|
messageReceived func(msg.Message)
|
||||||
|
replyMessageReceived func(msg.Message, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(c *config.Config) *Irc {
|
func New(c *config.Config) *Irc {
|
||||||
|
@ -61,6 +62,10 @@ func (i *Irc) RegisterMessageReceived(f func(msg.Message)) {
|
||||||
i.messageReceived = f
|
i.messageReceived = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Irc) RegisterReplyMessageReceived(f func(msg.Message, string)) {
|
||||||
|
i.replyMessageReceived = f
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Irc) JoinChannel(channel string) {
|
func (i *Irc) JoinChannel(channel string) {
|
||||||
log.Printf("Joining channel: %s", channel)
|
log.Printf("Joining channel: %s", channel)
|
||||||
i.Client.Out <- irc.Msg{Cmd: irc.JOIN, Args: []string{channel}}
|
i.Client.Out <- irc.Msg{Cmd: irc.JOIN, Args: []string{channel}}
|
||||||
|
|
|
@ -117,3 +117,5 @@ func (p *AdminPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *AdminPlugin) RegisterWeb() *string {
|
func (p *AdminPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *AdminPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -935,3 +935,5 @@ func (p *BabblerPlugin) babbleSeedBookends(babblerName string, start, end []stri
|
||||||
|
|
||||||
return strings.Join(words, " "), nil
|
return strings.Join(words, " "), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *BabblerPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -461,3 +461,5 @@ func (p *BeersPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *BeersPlugin) RegisterWeb() *string {
|
func (p *BeersPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *BeersPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -364,3 +364,5 @@ func (p *CounterPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *CounterPlugin) RegisterWeb() *string {
|
func (p *CounterPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *CounterPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -100,3 +100,5 @@ func (p *DicePlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *DicePlugin) RegisterWeb() *string {
|
func (p *DicePlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *DicePlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -231,3 +231,5 @@ func (p *DowntimePlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *DowntimePlugin) RegisterWeb() *string {
|
func (p *DowntimePlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *DowntimePlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -112,3 +112,5 @@ func (p *EmojifyMePlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *EmojifyMePlugin) RegisterWeb() *string {
|
func (p *EmojifyMePlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *EmojifyMePlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -764,3 +764,5 @@ func (p *Factoid) serveQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Factoid) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -170,3 +170,5 @@ func (p *RememberPlugin) recordMsg(message msg.Message) {
|
||||||
log.Printf("Logging message: %s: %s", message.User.Name, message.Body)
|
log.Printf("Logging message: %s: %s", message.User.Name, message.Body)
|
||||||
p.Log[message.Channel] = append(p.Log[message.Channel], message)
|
p.Log[message.Channel] = append(p.Log[message.Channel], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *RememberPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -228,3 +228,5 @@ func (p *FirstPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *FirstPlugin) RegisterWeb() *string {
|
func (p *FirstPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *FirstPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -236,3 +236,5 @@ func (p *InventoryPlugin) RegisterWeb() *string {
|
||||||
// nothing to register
|
// nothing to register
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *InventoryPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -76,3 +76,5 @@ func (p *LeftpadPlugin) RegisterWeb() *string {
|
||||||
// nothing to register
|
// nothing to register
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *LeftpadPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -80,3 +80,5 @@ func (p *ReactionPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *ReactionPlugin) RegisterWeb() *string {
|
func (p *ReactionPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ReactionPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -322,3 +322,5 @@ func reminderer(p *ReminderPlugin) {
|
||||||
p.queueUpNextReminder()
|
p.queueUpNextReminder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ReminderPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -2,7 +2,6 @@ package rpgORdie
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
// "log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
|
@ -11,11 +10,13 @@ import (
|
||||||
|
|
||||||
type RPGPlugin struct {
|
type RPGPlugin struct {
|
||||||
Bot bot.Bot
|
Bot bot.Bot
|
||||||
|
listenFor map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(b bot.Bot) *RPGPlugin {
|
func New(b bot.Bot) *RPGPlugin {
|
||||||
return &RPGPlugin{
|
return &RPGPlugin{
|
||||||
Bot: b,
|
Bot: b,
|
||||||
|
listenFor: map[string]bool{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,17 +24,20 @@ func (p *RPGPlugin) Message(message msg.Message) bool {
|
||||||
if strings.ToLower(message.Body) == "start rpg" {
|
if strings.ToLower(message.Body) == "start rpg" {
|
||||||
ts := p.Bot.SendMessage(message.Channel, "I'll edit this.")
|
ts := p.Bot.SendMessage(message.Channel, "I'll edit this.")
|
||||||
|
|
||||||
|
p.listenFor[ts] = true
|
||||||
|
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
edited := ""
|
edited := ""
|
||||||
for i := 0; i <= 5; i++ {
|
for i := 0; i <= 5; i++ {
|
||||||
p.Bot.Edit(message.Channel, edited, ts)
|
p.Bot.Edit(message.Channel, edited, ts)
|
||||||
edited += ":fire:"
|
edited += ":fire:"
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(500 * time.Millisecond)
|
||||||
}
|
}
|
||||||
p.Bot.Edit(message.Channel, "HECK YES", ts)
|
p.Bot.Edit(message.Channel, "HECK YES", ts)
|
||||||
|
|
||||||
p.Bot.ReplyToMessageIdentifier(message.Channel, "How's this reply?", ts)
|
p.Bot.ReplyToMessageIdentifier(message.Channel, "How's this reply?", ts)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -57,3 +61,13 @@ func (p *RPGPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *RPGPlugin) RegisterWeb() *string {
|
func (p *RPGPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *RPGPlugin) ReplyMessage(message msg.Message, identifier string) bool {
|
||||||
|
if strings.ToLower(message.User.Name) != strings.ToLower(p.Bot.Config().Nick) {
|
||||||
|
if _, ok := p.listenFor[identifier]; ok {
|
||||||
|
p.Bot.ReplyToMessageIdentifier(message.Channel, "Pong", identifier)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -117,3 +117,5 @@ func (p *RSSPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *RSSPlugin) RegisterWeb() *string {
|
func (p *RSSPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *RSSPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -275,3 +275,5 @@ func (p *StatsPlugin) mkSightingStat(message msg.Message) stats {
|
||||||
func (p *StatsPlugin) mkChannelStat(message msg.Message) stats {
|
func (p *StatsPlugin) mkChannelStat(message msg.Message) stats {
|
||||||
return stats{stat{mkDay(), "channel", message.Channel, 1}}
|
return stats{stat{mkDay(), "channel", message.Channel, 1}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *StatsPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -119,3 +119,5 @@ func (p *TalkerPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *TalkerPlugin) RegisterWeb() *string {
|
func (p *TalkerPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *TalkerPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -238,3 +238,5 @@ func (p *TwitchPlugin) checkTwitch(channel string, twitcher *Twitcher, alwaysPri
|
||||||
twitcher.game = game
|
twitcher.game = game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *TwitchPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -66,3 +66,5 @@ func (p *YourPlugin) BotMessage(message msg.Message) bool {
|
||||||
func (p *YourPlugin) RegisterWeb() *string {
|
func (p *YourPlugin) RegisterWeb() *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *YourPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -122,3 +122,5 @@ func (p *ZorkPlugin) Help(ch string, _ []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ZorkPlugin) RegisterWeb() *string { return nil }
|
func (p *ZorkPlugin) RegisterWeb() *string { return nil }
|
||||||
|
|
||||||
|
func (p *ZorkPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
||||||
|
|
|
@ -41,6 +41,7 @@ type Slack struct {
|
||||||
|
|
||||||
eventReceived func(msg.Message)
|
eventReceived func(msg.Message)
|
||||||
messageReceived func(msg.Message)
|
messageReceived func(msg.Message)
|
||||||
|
replyMessageReceived func(msg.Message, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
var idCounter uint64
|
var idCounter uint64
|
||||||
|
@ -134,6 +135,7 @@ type slackMessage struct {
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Ts string `json:"ts"`
|
Ts string `json:"ts"`
|
||||||
|
ThreadTs string `json:"thread_ts"`
|
||||||
Error struct {
|
Error struct {
|
||||||
Code uint64 `json:"code"`
|
Code uint64 `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
|
@ -193,6 +195,10 @@ func (s *Slack) RegisterMessageReceived(f func(msg.Message)) {
|
||||||
s.messageReceived = f
|
s.messageReceived = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Slack) RegisterReplyMessageReceived(f func(msg.Message, string)) {
|
||||||
|
s.replyMessageReceived = f
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string, error) {
|
func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string, error) {
|
||||||
postUrl := "https://slack.com/api/chat.postMessage"
|
postUrl := "https://slack.com/api/chat.postMessage"
|
||||||
if meMessage {
|
if meMessage {
|
||||||
|
@ -384,19 +390,17 @@ func (s *Slack) Serve() error {
|
||||||
}
|
}
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case "message":
|
case "message":
|
||||||
if !msg.Hidden {
|
if !msg.Hidden && msg.ThreadTs == "" {
|
||||||
m := s.buildMessage(msg)
|
m := s.buildMessage(msg)
|
||||||
|
|
||||||
log.Println()
|
|
||||||
log.Println(m)
|
|
||||||
log.Println()
|
|
||||||
|
|
||||||
if m.Time.Before(s.lastRecieved) {
|
if m.Time.Before(s.lastRecieved) {
|
||||||
log.Printf("Ignoring message: %+v\nlastRecieved: %v msg: %v", msg.ID, s.lastRecieved, m.Time)
|
log.Printf("Ignoring message: %+v\nlastRecieved: %v msg: %v", msg.ID, s.lastRecieved, m.Time)
|
||||||
} else {
|
} else {
|
||||||
s.lastRecieved = m.Time
|
s.lastRecieved = m.Time
|
||||||
s.messageReceived(s.buildMessage(msg))
|
s.messageReceived(m)
|
||||||
}
|
}
|
||||||
|
} else if msg.ThreadTs != "" {
|
||||||
|
//we're throwing away some information here by not parsing the correct reply object type, but that's okay
|
||||||
|
s.replyMessageReceived(s.buildLightReplyMessage(msg), msg.ThreadTs)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("THAT MESSAGE WAS HIDDEN: %+v", msg.ID)
|
log.Printf("THAT MESSAGE WAS HIDDEN: %+v", msg.ID)
|
||||||
}
|
}
|
||||||
|
@ -453,6 +457,40 @@ func (s *Slack) buildMessage(m slackMessage) msg.Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Slack) buildLightReplyMessage(m slackMessage) msg.Message {
|
||||||
|
text := html.UnescapeString(m.Text)
|
||||||
|
|
||||||
|
text = fixText(s.getUser, text)
|
||||||
|
|
||||||
|
isCmd, text := bot.IsCmd(s.config, text)
|
||||||
|
|
||||||
|
isAction := m.SubType == "me_message"
|
||||||
|
|
||||||
|
u, _ := s.getUser(m.User)
|
||||||
|
if m.Username != "" {
|
||||||
|
u = m.Username
|
||||||
|
}
|
||||||
|
|
||||||
|
tstamp := slackTStoTime(m.Ts)
|
||||||
|
|
||||||
|
return msg.Message{
|
||||||
|
User: &user.User{
|
||||||
|
ID: m.User,
|
||||||
|
Name: u,
|
||||||
|
},
|
||||||
|
Body: text,
|
||||||
|
Raw: m.Text,
|
||||||
|
Channel: m.Channel,
|
||||||
|
Command: isCmd,
|
||||||
|
Action: isAction,
|
||||||
|
Host: string(m.ID),
|
||||||
|
Time: tstamp,
|
||||||
|
AdditionalData: map[string]string{
|
||||||
|
"RAW_SLACK_TIMESTAMP": m.Ts,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// markAllChannelsRead gets a list of all channels and marks each as read
|
// markAllChannelsRead gets a list of all channels and marks each as read
|
||||||
func (s *Slack) markAllChannelsRead() {
|
func (s *Slack) markAllChannelsRead() {
|
||||||
chs := s.getAllChannels()
|
chs := s.getAllChannels()
|
||||||
|
|
Loading…
Reference in New Issue