Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suppressEmbeds and unsuppressEmbeds functions for CC #1792

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/templates/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,9 @@ func baseContextFuncs(c *Context) {
c.addContextFunc("pinMessage", c.tmplPinMessage(false))
c.addContextFunc("publishMessage", c.tmplPublishMessage)
c.addContextFunc("publishResponse", c.tmplPublishResponse)
c.addContextFunc("suppressEmbeds", c.tmplSuppressEmbeds(true))
c.addContextFunc("unpinMessage", c.tmplPinMessage(true))
c.addContextFunc("unsuppressEmbeds", c.tmplSuppressEmbeds(false))

// Message send functions
c.addContextFunc("sendDM", c.tmplSendDM)
Expand Down
37 changes: 37 additions & 0 deletions common/templates/context_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,43 @@ func (c *Context) tmplPinMessage(unpin bool) func(channel, msgID interface{}) (s
}
}

func (c *Context) tmplSuppressEmbeds(suppress bool) func(channel, msgID interface{}) (string, error) {
return func(channel, msgID interface{}) (string, error) {
if c.IncreaseCheckGenericAPICall() {
return "", ErrTooManyAPICalls
}

cID := c.ChannelArgNoDM(channel)
if cID == 0 {
return "", errors.New("unknown channel")
}

mID := ToInt64(msgID)

message, _ := common.BotSession.ChannelMessage(cID, mID)
if message == nil {
return "", errors.New("unknown message")
}

newFlags := message.Flags | discordgo.MessageFlagsSuppressEmbeds
if !suppress {
newFlags = newFlags ^ discordgo.MessageFlagsSuppressEmbeds
}

msgEdit := &discordgo.MessageEdit{
ID: mID,
Channel: cID,
Flags: newFlags,
}

var err error

_, err = common.BotSession.ChannelMessageEditComplex(msgEdit)

return "", err
}
}

func (c *Context) tmplPublishMessage(channel, msgID interface{}) (string, error) {
// Too heavily ratelimited by Discord to allow rapid feeds to publish
if c.ExecutedFrom == ExecutedFromLeave || c.ExecutedFrom == ExecutedFromJoin {
Expand Down
2 changes: 2 additions & 0 deletions frontend/static/js/yagFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,6 @@ var yagFuncs = {
dbBottomEntries: true,
dbCount: true,
dbRank: true,
suppressEmbeds: true,
unsuppressEmbeds: true,
};
2 changes: 2 additions & 0 deletions lib/template/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,4 +800,6 @@ var funcs = map[string]interface{}{
"userArg": func() interface{} { return nil },
"verb": func() interface{} { return nil },
"weekNumber": func() interface{} { return nil },
"suppressEmbeds": func() interface{} { return nil },
"unsuppressEmbeds": func() interface{} { return nil },
}