diff --git a/common/templates/context.go b/common/templates/context.go index d41731250c..ed32a21c22 100644 --- a/common/templates/context.go +++ b/common/templates/context.go @@ -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) diff --git a/common/templates/context_funcs.go b/common/templates/context_funcs.go index ef1856feef..9d27e200d7 100644 --- a/common/templates/context_funcs.go +++ b/common/templates/context_funcs.go @@ -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 { diff --git a/frontend/static/js/yagFuncs.js b/frontend/static/js/yagFuncs.js index 7af10a6314..1cb59aaffb 100644 --- a/frontend/static/js/yagFuncs.js +++ b/frontend/static/js/yagFuncs.js @@ -205,4 +205,6 @@ var yagFuncs = { dbBottomEntries: true, dbCount: true, dbRank: true, + suppressEmbeds: true, + unsuppressEmbeds: true, }; diff --git a/lib/template/parse/parse_test.go b/lib/template/parse/parse_test.go index 306a86832c..f7ee240264 100644 --- a/lib/template/parse/parse_test.go +++ b/lib/template/parse/parse_test.go @@ -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 }, }