2025-07-09 20:11:12 +00:00
|
|
|
package bolt
|
|
|
|
|
|
2025-08-17 20:37:22 -04:00
|
|
|
import (
|
|
|
|
|
"fmt"
|
2025-07-09 20:11:12 +00:00
|
|
|
|
2025-08-17 20:37:22 -04:00
|
|
|
dg "github.com/bwmarrin/discordgo"
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-26 22:59:13 -05:00
|
|
|
const (
|
|
|
|
|
// the max discord allows for basic messages
|
|
|
|
|
MSG_MAX_LENGTH = 2000
|
|
|
|
|
)
|
|
|
|
|
|
2025-09-07 01:10:48 -04:00
|
|
|
// the message struct is passed to the command payload providing basic
|
|
|
|
|
// message information and needed methods
|
|
|
|
|
type Message struct {
|
|
|
|
|
Author string //username of message author
|
|
|
|
|
ID string //discord ID of message author
|
|
|
|
|
msgID string //id string of message
|
|
|
|
|
Words []string //words from message split on whitespace
|
|
|
|
|
Content string //entire message content
|
|
|
|
|
Channel string //message channel
|
|
|
|
|
channelID string //id of channel message was sent in
|
|
|
|
|
Server string //message guild
|
|
|
|
|
serverID string //id of guild message was sent in
|
|
|
|
|
Attachments []MessageAttachment
|
|
|
|
|
sesh *bolt
|
|
|
|
|
}
|
2025-07-09 20:11:12 +00:00
|
|
|
|
2025-09-07 01:10:48 -04:00
|
|
|
// applies reaction to message
|
|
|
|
|
func (m *Message) React(emoji Reaction) error {
|
|
|
|
|
return m.sesh.MessageReactionAdd(m.channelID, m.msgID, fmt.Sprint(emoji))
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-26 22:59:13 -05:00
|
|
|
// sends response to message, if the response length is greater than 2000 characters the
|
|
|
|
|
// messages are split and sent seperatly
|
2025-09-07 01:10:48 -04:00
|
|
|
func (m *Message) Respond(res string) error {
|
2026-01-26 22:59:13 -05:00
|
|
|
if len(res) > MSG_MAX_LENGTH {
|
|
|
|
|
for len(res) > 0 {
|
|
|
|
|
//send full chunk size allowed by discord
|
|
|
|
|
sc := res[:MSG_MAX_LENGTH]
|
|
|
|
|
rep := m.sesh.createReply(sc, m.msgID, m.channelID, m.serverID)
|
|
|
|
|
_, err := m.sesh.ChannelMessageSendComplex(m.channelID, rep)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
res = res[MSG_MAX_LENGTH:]
|
|
|
|
|
|
|
|
|
|
//if we have left than a full chunk send the rest and break the loop
|
|
|
|
|
if len(res) < MSG_MAX_LENGTH {
|
|
|
|
|
final := m.sesh.createReply(res, m.msgID, m.channelID, m.serverID)
|
|
|
|
|
_, err := m.sesh.ChannelMessageSendComplex(m.channelID, final)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//short enough message to send in one message
|
2025-09-07 01:10:48 -04:00
|
|
|
rep := m.sesh.createReply(res, m.msgID, m.channelID, m.serverID)
|
|
|
|
|
_, err := m.sesh.ChannelMessageSendComplex(m.channelID, rep)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deletes the message from the channel
|
|
|
|
|
func (m *Message) Delete() error {
|
|
|
|
|
return m.sesh.ChannelMessageDelete(m.channelID, m.msgID, nil)
|
|
|
|
|
}
|
2025-07-09 20:11:12 +00:00
|
|
|
|
2025-09-07 01:10:48 -04:00
|
|
|
// this struct has all of the needed information from the messageCreate event so that
|
|
|
|
|
// commands can be run asynchronously. Passing the messageCreate to payloads can block routines
|
2025-08-17 20:37:22 -04:00
|
|
|
type MessageCreateEvent struct {
|
|
|
|
|
AuthorUsername string
|
|
|
|
|
AuthorID string
|
|
|
|
|
AuthorRoles []string
|
|
|
|
|
MsgID string
|
|
|
|
|
Msg string
|
|
|
|
|
MsgChanID string
|
|
|
|
|
MsgChanName string
|
|
|
|
|
MsgGuildID string
|
|
|
|
|
MsgGuildName string
|
|
|
|
|
MsgAttachments []*dg.MessageAttachment
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-07 01:10:48 -04:00
|
|
|
// message attachment details
|
2025-07-09 20:11:12 +00:00
|
|
|
type MessageAttachment struct {
|
|
|
|
|
ID string
|
|
|
|
|
URL string
|
|
|
|
|
ProxyURL string
|
|
|
|
|
Filename string
|
|
|
|
|
ContentType string
|
|
|
|
|
Width int
|
|
|
|
|
Height int
|
|
|
|
|
Size int
|
|
|
|
|
DurationSecs float64
|
|
|
|
|
}
|