Skip to content

Commit

Permalink
templates: add msg forward guild checks
Browse files Browse the repository at this point in the history
Signed-off-by: SoggySaussages <[email protected]>
  • Loading branch information
SoggySaussages committed Nov 15, 2024
1 parent 0c8ecfa commit 374cc53
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions common/templates/context_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ func (c *Context) tmplSendDM(s ...interface{}) string {
}
msgSend.Components = append(serverInfo, msgSend.Components...)

if msgSend.Reference != nil {
if msgSend.Reference.Type == discordgo.MessageReferenceTypeForward {
if originChannel := c.ChannelArgNoDM(msgSend.Reference.ChannelID); originChannel != 0 {
hasPerms, _ := bot.BotHasPermissionGS(c.GS, originChannel, discordgo.PermissionViewChannel|discordgo.PermissionReadMessageHistory)
if !hasPerms {
msgSend.Reference = &discordgo.MessageReference{}
}
} else {
msgSend.Reference = &discordgo.MessageReference{}
}
}
}

channel, err := common.BotSession.UserChannelCreate(c.MS.User.ID)
if err != nil {
return ""
Expand Down Expand Up @@ -390,6 +403,19 @@ func (c *Context) tmplSendMessage(filterSpecialMentions bool, returnID bool) fun
msgSend.Components = append(serverInfo, msgSend.Components...)
}

if msgSend.Reference != nil {
if msgSend.Reference.Type == discordgo.MessageReferenceTypeForward {
if originChannel := c.ChannelArgNoDM(msgSend.Reference.ChannelID); originChannel != 0 {
hasPerms, _ := bot.BotHasPermissionGS(c.GS, originChannel, discordgo.PermissionViewChannel|discordgo.PermissionReadMessageHistory)
if !hasPerms {
msgSend.Reference = &discordgo.MessageReference{}
}
} else {
msgSend.Reference = &discordgo.MessageReference{}
}
}
}

m, err = common.BotSession.ChannelMessageSendComplex(cid, msgSend)

if err == nil && returnID {
Expand Down

0 comments on commit 374cc53

Please sign in to comment.