Skip to content

Commit

Permalink
add templates to pin and unpin messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lemm-e committed Nov 15, 2021
1 parent b137687 commit d2de464
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/templates/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ func baseContextFuncs(c *Context) {
c.addContextFunc("sendMessageNoEscapeRetID", c.tmplSendMessage(false, true))
c.addContextFunc("editMessage", c.tmplEditMessage(true))
c.addContextFunc("editMessageNoEscape", c.tmplEditMessage(false))
c.addContextFunc("pinMessage", c.tmplPinMessage)
c.addContextFunc("unpinMessage", c.tmplUnpinMessage)

// Mentions
c.addContextFunc("mentionEveryone", c.tmplMentionEveryone)
Expand Down
30 changes: 30 additions & 0 deletions common/templates/context_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,36 @@ func (c *Context) tmplEditMessage(filterSpecialMentions bool) func(channel inter
}
}

func (c *Context) tmplPinMessage(channel, msgID interface{}) (string, error) {
cID := c.ChannelArgNoDM(channel)
if cID == 0 {
return "", errors.New("unknown channel")
}

mID := ToInt64(msgID)
err := common.BotSession.ChannelMessagePin(cID, mID)
if err != nil {
return "", err
}

return "", nil
}

func (c *Context) tmplUnpinMessage(channel, msgID interface{}) (string, error) {
cID := c.ChannelArgNoDM(channel)
if cID == 0 {
return "", errors.New("unknown channel")
}

mID := ToInt64(msgID)
err := common.BotSession.ChannelMessageUnpin(cID, mID)
if err != nil {
return "", err
}

return "", nil
}

func (c *Context) tmplMentionEveryone() string {
c.CurrentFrame.MentionEveryone = true
return "@everyone"
Expand Down

0 comments on commit d2de464

Please sign in to comment.