Compare commits
2 Commits
7376e8f857
...
c291f68005
| Author | SHA1 | Date | |
|---|---|---|---|
| c291f68005 | |||
|
759a188a8e
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,3 +25,4 @@ go.work.sum
|
|||||||
# env file
|
# env file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
/cmd/*
|
||||||
35
message.go
35
message.go
@@ -6,6 +6,11 @@ import (
|
|||||||
dg "github.com/bwmarrin/discordgo"
|
dg "github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// the max discord allows for basic messages
|
||||||
|
MSG_MAX_LENGTH = 2000
|
||||||
|
)
|
||||||
|
|
||||||
// the message struct is passed to the command payload providing basic
|
// the message struct is passed to the command payload providing basic
|
||||||
// message information and needed methods
|
// message information and needed methods
|
||||||
type Message struct {
|
type Message struct {
|
||||||
@@ -27,8 +32,36 @@ func (m *Message) React(emoji Reaction) error {
|
|||||||
return m.sesh.MessageReactionAdd(m.channelID, m.msgID, fmt.Sprint(emoji))
|
return m.sesh.MessageReactionAdd(m.channelID, m.msgID, fmt.Sprint(emoji))
|
||||||
}
|
}
|
||||||
|
|
||||||
// sends response to message
|
// sends response to message, if the response length is greater than 2000 characters the
|
||||||
|
// messages are split and sent seperatly
|
||||||
func (m *Message) Respond(res string) error {
|
func (m *Message) Respond(res string) error {
|
||||||
|
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
|
||||||
rep := m.sesh.createReply(res, m.msgID, m.channelID, m.serverID)
|
rep := m.sesh.createReply(res, m.msgID, m.channelID, m.serverID)
|
||||||
_, err := m.sesh.ChannelMessageSendComplex(m.channelID, rep)
|
_, err := m.sesh.ChannelMessageSendComplex(m.channelID, rep)
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user