Skip to content

Commit

Permalink
extract own bot message event disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
maribowman committed Jan 6, 2024
1 parent ba15d26 commit 3ceea28
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (bot *DiscordBot) Ready(session *discordgo.Session, ready *discordgo.Ready)
}

func (bot *DiscordBot) MessageDispatch(session *discordgo.Session, message *discordgo.MessageCreate) {
if message.Author.ID == config.Config.Discord.BotID {
return
}

if handler, ok := bot.handlers[message.ChannelID]; ok {
handler.MessageEvent(session, message)
} else {
Expand Down
4 changes: 0 additions & 4 deletions app/service/grocery_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ func (handler *GroceryHandler) ReadyEvent(session *discordgo.Session, ready *dis
}

func (handler *GroceryHandler) MessageEvent(session *discordgo.Session, message *discordgo.MessageCreate) {
if message.Author.ID == handler.botID {
return
}

channelMessages, err := session.ChannelMessages(handler.channelID, 100, "", "", "")
if err != nil {
return
Expand Down
5 changes: 1 addition & 4 deletions app/service/tk_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ func NewTkHandler(botID string, channelID string) model.BotHandler {

func (handler *TkHandler) ReadyEvent(session *discordgo.Session, ready *discordgo.Ready) {
handler.MessageEvent(session, &discordgo.MessageCreate{Message: &discordgo.Message{Author: &discordgo.User{ID: "init"}}})
log.Debug().Msg("Initialized grocery handler")
}

func (handler *TkHandler) MessageEvent(session *discordgo.Session, message *discordgo.MessageCreate) {
if message.Author.ID == handler.botID {
return
}

channelMessages, err := session.ChannelMessages(message.ChannelID, 100, "", "", "")
if err != nil {
return
Expand Down

0 comments on commit 3ceea28

Please sign in to comment.