|
|
|
@ -316,6 +316,7 @@ func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (st
|
|
|
|
|
// Upload a file if it exists
|
|
|
|
|
if msg.Extra != nil {
|
|
|
|
|
for _, rmsg := range helper.HandleExtra(msg, b.General) {
|
|
|
|
|
// TODO: Use ClipOrSplitMessage
|
|
|
|
|
rmsg.Text = helper.ClipMessage(rmsg.Text, MessageLength, b.GetString("MessageClipped"))
|
|
|
|
|
if _, err := b.c.ChannelMessageSend(channelID, rmsg.Username+rmsg.Text); err != nil {
|
|
|
|
|
b.Log.Errorf("Could not send message %#v: %s", rmsg, err)
|
|
|
|
@ -327,35 +328,53 @@ func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (st
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg.Text = helper.ClipMessage(msg.Text, MessageLength, b.GetString("MessageClipped"))
|
|
|
|
|
msg.Text = b.replaceUserMentions(msg.Text)
|
|
|
|
|
|
|
|
|
|
// Edit message
|
|
|
|
|
if msg.ID != "" {
|
|
|
|
|
_, err := b.c.ChannelMessageEdit(channelID, msg.ID, msg.Username+msg.Text)
|
|
|
|
|
return msg.ID, err
|
|
|
|
|
// Exploit that a discord message ID is actually just a large number, and we encode a list of IDs by separating them with ";".
|
|
|
|
|
var msgIds = strings.Split(msg.ID, ";")
|
|
|
|
|
msgParts := helper.ClipOrSplitMessage(b.replaceUserMentions(msg.Text), MessageLength, b.GetString("MessageClipped"), len(msgIds))
|
|
|
|
|
for len(msgParts) < len(msgIds) {
|
|
|
|
|
msgParts = append(msgParts, "((obsoleted by edit))")
|
|
|
|
|
}
|
|
|
|
|
for i := range msgParts {
|
|
|
|
|
// In case of split-messages where some parts remain the same (i.e. only a typo-fix in a huge message), this causes some noop-updates.
|
|
|
|
|
// TODO: Optimize away noop-updates of un-edited messages
|
|
|
|
|
// TODO: Use RemoteNickFormat instead of this broken concatenation
|
|
|
|
|
_, err := b.c.ChannelMessageEdit(channelID, msgIds[i], msg.Username+msgParts[i])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return msg.ID, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m := discordgo.MessageSend{
|
|
|
|
|
Content: msg.Username + msg.Text,
|
|
|
|
|
AllowedMentions: b.getAllowedMentions(),
|
|
|
|
|
}
|
|
|
|
|
msgParts := helper.ClipOrSplitMessage(b.replaceUserMentions(msg.Text), MessageLength, b.GetString("MessageClipped"), b.GetInt("MessageSplitMaxCount"))
|
|
|
|
|
var msgIds = []string{}
|
|
|
|
|
|
|
|
|
|
if msg.ParentValid() {
|
|
|
|
|
m.Reference = &discordgo.MessageReference{
|
|
|
|
|
MessageID: msg.ParentID,
|
|
|
|
|
ChannelID: channelID,
|
|
|
|
|
GuildID: b.guildID,
|
|
|
|
|
for _, msgPart := range msgParts {
|
|
|
|
|
m := discordgo.MessageSend{
|
|
|
|
|
Content: msg.Username + msgPart,
|
|
|
|
|
AllowedMentions: b.getAllowedMentions(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Post normal message
|
|
|
|
|
res, err := b.c.ChannelMessageSendComplex(channelID, &m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
if msg.ParentValid() {
|
|
|
|
|
m.Reference = &discordgo.MessageReference{
|
|
|
|
|
MessageID: msg.ParentID,
|
|
|
|
|
ChannelID: channelID,
|
|
|
|
|
GuildID: b.guildID,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Post normal message
|
|
|
|
|
res, err := b.c.ChannelMessageSendComplex(channelID, &m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
msgIds = append(msgIds, res.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res.ID, nil
|
|
|
|
|
// Exploit that a discord message ID is actually just a large number, so we encode a list of IDs by separating them with ";".
|
|
|
|
|
return strings.Join(msgIds, ";"), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleUploadFile handles native upload of files
|
|
|
|
|