69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package events
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/Cynosphere/comcord/lib"
|
|
"github.com/Cynosphere/comcord/state"
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
func MessageCreate(session *discordgo.Session, msg *discordgo.MessageCreate) {
|
|
if msg.Author.ID == session.State.User.ID {
|
|
return
|
|
}
|
|
|
|
channel, err := session.State.Channel(msg.ChannelID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
isDM := channel.Type == discordgo.ChannelTypeDM || channel.Type == discordgo.ChannelTypeGroupDM
|
|
|
|
if state.IsInPrompt() {
|
|
state.AddMessageToQueue(msg.Message)
|
|
} else {
|
|
lines := lib.ProcessMessage(session, msg.Message, lib.MessageOptions{NoColor: state.HasNoColor()})
|
|
for _, line := range lines {
|
|
fmt.Print(line)
|
|
}
|
|
}
|
|
|
|
if isDM {
|
|
state.SetLastDM(msg.ChannelID)
|
|
}
|
|
}
|
|
|
|
func MessageUpdate(session *discordgo.Session, msg *discordgo.MessageUpdate) {
|
|
if msg.Author == nil {
|
|
return
|
|
}
|
|
|
|
if msg.Author.ID == session.State.User.ID {
|
|
return
|
|
}
|
|
|
|
if msg.BeforeUpdate != nil && msg.Content == msg.BeforeUpdate.Content {
|
|
return
|
|
}
|
|
|
|
channel, err := session.State.Channel(msg.ChannelID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
isDM := channel.Type == discordgo.ChannelTypeDM || channel.Type == discordgo.ChannelTypeGroupDM
|
|
|
|
if state.IsInPrompt() {
|
|
state.AddMessageToQueue(msg.Message)
|
|
} else {
|
|
lines := lib.ProcessMessage(session, msg.Message, lib.MessageOptions{NoColor: state.HasNoColor()})
|
|
for _, line := range lines {
|
|
fmt.Print(line)
|
|
}
|
|
}
|
|
|
|
if isDM {
|
|
state.SetLastDM(msg.ChannelID)
|
|
}
|
|
}
|