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"
|
2023-07-27 02:27:04 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/gateway"
|
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
2023-07-08 20:51:26 +00:00
|
|
|
)
|
|
|
|
|
2023-07-27 02:27:04 +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
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
channel, err := client.ChannelStore.Channel(msg.ChannelID)
|
2023-07-08 20:51:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
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 {
|
2023-07-27 02:27:04 +00:00
|
|
|
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 {
|
2023-07-27 02:27:04 +00:00
|
|
|
state.SetLastDM(msg.ChannelID.String())
|
2023-07-08 20:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +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
|
|
|
|
}
|
|
|
|
|
2023-07-27 03:55:55 +00:00
|
|
|
/*old, err := client.MessageStore.Message(msg.ChannelID, msg.ID)
|
2023-07-27 02:27:04 +00:00
|
|
|
if err != nil {
|
2023-07-15 02:46:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
if msg.Content == old.Content {
|
2023-07-09 20:00:49 +00:00
|
|
|
return
|
2023-07-27 03:55:55 +00:00
|
|
|
}*/
|
2023-07-09 20:00:49 +00:00
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
// dont process embed updates as messages
|
|
|
|
if !msg.EditedTimestamp.IsValid() {
|
2023-07-16 06:22:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
channel, err := client.ChannelStore.Channel(msg.ChannelID)
|
2023-07-09 20:00:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
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 {
|
2023-07-27 02:27:04 +00:00
|
|
|
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 {
|
2023-07-27 02:27:04 +00:00
|
|
|
state.SetLastDM(msg.ChannelID.String())
|
2023-07-09 20:00:49 +00:00
|
|
|
}
|
2023-07-08 20:51:26 +00:00
|
|
|
}
|