comcord/events/messages.go

62 lines
1.4 KiB
Go
Raw Normal View History

2023-07-08 20:51:26 +00:00
package events
import (
2023-07-09 04:42:58 +00:00
"github.com/Cynosphere/comcord/lib"
2023-07-08 20:51:26 +00:00
"github.com/Cynosphere/comcord/state"
"github.com/bwmarrin/discordgo"
)
func MessageCreate(session *discordgo.Session, msg *discordgo.MessageCreate) {
2023-07-09 04:42:58 +00:00
if msg.Author.ID == session.State.User.ID {
2023-07-08 20:51:26 +00:00
return
}
channel, err := session.State.Channel(msg.ChannelID)
if err != nil {
return
}
2023-07-09 04:42:58 +00:00
isDM := channel.Type == discordgo.ChannelTypeDM || channel.Type == discordgo.ChannelTypeGroupDM
2023-07-08 20:51:26 +00:00
if state.IsInPrompt() {
2023-07-09 04:42:58 +00:00
state.AddMessageToQueue(msg.Message)
2023-07-08 20:51:26 +00:00
} else {
2023-07-09 04:42:58 +00:00
lib.ProcessMessage(session, msg.Message, lib.MessageOptions{NoColor: state.HasNoColor()})
2023-07-08 20:51:26 +00:00
}
2023-07-09 04:42:58 +00:00
if isDM {
2023-07-08 20:51:26 +00:00
state.SetLastDM(msg.ChannelID)
}
}
func MessageUpdate(session *discordgo.Session, msg *discordgo.MessageUpdate) {
if msg.Author == nil {
return
}
2023-07-09 20:00:49 +00:00
if msg.Author.ID == session.State.User.ID {
return
}
2023-07-16 19:12:51 +00:00
if msg.BeforeUpdate != nil && msg.Content == msg.BeforeUpdate.Content {
2023-07-16 06:22:04 +00:00
return
}
2023-07-09 20:00:49 +00:00
channel, err := session.State.Channel(msg.ChannelID)
if err != nil {
return
}
isDM := channel.Type == discordgo.ChannelTypeDM || channel.Type == discordgo.ChannelTypeGroupDM
2023-07-08 20:51:26 +00:00
2023-07-09 20:00:49 +00:00
if state.IsInPrompt() {
state.AddMessageToQueue(msg.Message)
} else {
lib.ProcessMessage(session, msg.Message, lib.MessageOptions{NoColor: state.HasNoColor()})
}
if isDM {
state.SetLastDM(msg.ChannelID)
}
2023-07-08 20:51:26 +00:00
}