meme/bot: add ephemeral messages

This commit is contained in:
Chris Sexton 2020-10-24 09:54:18 -04:00 committed by Chris Sexton
parent fed1951e66
commit a30be0df8f
4 changed files with 14 additions and 2 deletions

View File

@ -15,6 +15,8 @@ const (
// Message any standard chat
Message
// Send a disappearing message to a user in chat
Ephemeral
// Reply something containing a message reference
Reply
// Action any /me action
@ -33,6 +35,8 @@ const (
Delete
)
type EphemeralID string
type ImageAttachment struct {
URL string
AltTxt string

View File

@ -42,6 +42,8 @@ func (d *Discord) RegisterEvent(callback bot.Callback) {
func (d Discord) Send(kind bot.Kind, args ...interface{}) (string, error) {
switch kind {
case bot.Ephemeral:
return d.sendMessage(args[0].(string), args[2].(string), false, args...)
case bot.Message:
return d.sendMessage(args[0].(string), args[1].(string), false, args...)
case bot.Action:

View File

@ -234,6 +234,9 @@ func (s *SlackApp) Send(kind bot.Kind, args ...interface{}) (string, error) {
switch kind {
case bot.Message:
return s.sendMessage(args[0].(string), args[1].(string), false, args...)
case bot.Ephemeral:
args[1] = bot.EphemeralID(args[1].(string))
return s.sendMessage(args[0].(string), args[2].(string), false, args...)
case bot.Action:
return s.sendMessage(args[0].(string), args[1].(string), true, args...)
case bot.Edit:
@ -271,6 +274,8 @@ func (s *SlackApp) sendMessage(channel, message string, meMessage bool, args ...
if len(args) > 0 {
for _, a := range args {
switch a := a.(type) {
case bot.EphemeralID:
options = append(options, slack.MsgOptionPostEphemeral(string(a)))
case bot.ImageAttachment:
attachments = append(attachments, slack.Attachment{
ImageURL: a.URL,

View File

@ -196,7 +196,7 @@ func (p *MemePlugin) sendMeme(c bot.Connector, channel, channelName, msgID strin
id, w, h, err := p.genMeme(format, bullyImg, config)
if err != nil {
msg := fmt.Sprintf("Hey %v, I couldn't download that image you asked for.", from.Name)
p.bot.Send(c, bot.Message, channel, msg)
p.bot.Send(c, bot.Ephemeral, channel, from.ID, msg)
return
}
baseURL := p.c.Get("BaseURL", ``)
@ -239,12 +239,13 @@ func (p *MemePlugin) slashMeme(c bot.Connector) http.HandlerFunc {
log.Debug().Msgf("Meme:\n%+v", r.PostForm.Get("text"))
channel := r.PostForm.Get("channel_id")
channelName := r.PostForm.Get("channel_name")
userID := r.PostForm.Get("user_id")
from := r.PostForm.Get("user_name")
text := r.PostForm.Get("text")
log.Debug().Msgf("channel: %s", channel)
user := &user.User{
ID: from, // HACK but should work fine
ID: userID, // HACK but should work fine
Name: from,
}