diff --git a/bot/interfaces.go b/bot/interfaces.go index 5ca34ff..4880d5c 100644 --- a/bot/interfaces.go +++ b/bot/interfaces.go @@ -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 diff --git a/connectors/discord/discord.go b/connectors/discord/discord.go index 0b0dabc..4886c4a 100644 --- a/connectors/discord/discord.go +++ b/connectors/discord/discord.go @@ -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: diff --git a/connectors/slackapp/slackApp.go b/connectors/slackapp/slackApp.go index 4bde948..c150e02 100644 --- a/connectors/slackapp/slackApp.go +++ b/connectors/slackapp/slackApp.go @@ -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, diff --git a/plugins/meme/meme.go b/plugins/meme/meme.go index da19318..71c8d97 100644 --- a/plugins/meme/meme.go +++ b/plugins/meme/meme.go @@ -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, }