comcord/events/messages.go

89 lines
1.8 KiB
Go
Raw Normal View History

2023-07-08 20:51:26 +00:00
package events
import (
2023-07-16 20:58:14 +00:00
"fmt"
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/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/discord"
2023-07-08 20:51:26 +00:00
)
func MessageCreate(msg *gateway.MessageCreateEvent) {
client := state.GetClient()
self, err := client.MeStore.Me()
if err != nil {
return
}
if msg.Author.ID == self.ID {
2023-07-08 20:51:26 +00:00
return
}
channel, err := client.ChannelStore.Channel(msg.ChannelID)
2023-07-08 20:51:26 +00:00
if err != nil {
return
}
isDM := channel.Type == discord.DirectMessage || channel.Type == discord.GroupDM
2023-07-09 04:42:58 +00:00
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 {
lines := lib.ProcessMessage(msg.Message, lib.MessageOptions{NoColor: state.HasNoColor()})
2023-07-16 20:58:14 +00:00
for _, line := range lines {
fmt.Print(line)
}
2023-07-08 20:51:26 +00:00
}
2023-07-09 04:42:58 +00:00
if isDM {
state.SetLastDM(msg.ChannelID.String())
2023-07-08 20:51:26 +00:00
}
}
func MessageUpdate(msg *gateway.MessageUpdateEvent) {
client := state.GetClient()
self, err := client.MeStore.Me()
if err != nil {
return
}
if msg.Author.ID == self.ID {
return
}
/*old, err := client.MessageStore.Message(msg.ChannelID, msg.ID)
if err != nil {
return
}
if msg.Content == old.Content {
2023-07-09 20:00:49 +00:00
return
}*/
2023-07-09 20:00:49 +00:00
// dont process embed updates as messages
if !msg.EditedTimestamp.IsValid() {
2023-07-16 06:22:04 +00:00
return
}
channel, err := client.ChannelStore.Channel(msg.ChannelID)
2023-07-09 20:00:49 +00:00
if err != nil {
return
}
isDM := channel.Type == discord.DirectMessage || channel.Type == discord.GroupDM
2023-07-08 20:51:26 +00:00
2023-07-09 20:00:49 +00:00
if state.IsInPrompt() {
state.AddMessageToQueue(msg.Message)
} else {
lines := lib.ProcessMessage(msg.Message, lib.MessageOptions{NoColor: state.HasNoColor()})
2023-07-16 20:58:14 +00:00
for _, line := range lines {
fmt.Print(line)
}
2023-07-09 20:00:49 +00:00
}
if isDM {
state.SetLastDM(msg.ChannelID.String())
2023-07-09 20:00:49 +00:00
}
2023-07-08 20:51:26 +00:00
}