mirror of https://github.com/velour/catbase.git
meme/bot: add ephemeral messages
This commit is contained in:
parent
fed1951e66
commit
a30be0df8f
|
@ -15,6 +15,8 @@ const (
|
||||||
|
|
||||||
// Message any standard chat
|
// Message any standard chat
|
||||||
Message
|
Message
|
||||||
|
// Send a disappearing message to a user in chat
|
||||||
|
Ephemeral
|
||||||
// Reply something containing a message reference
|
// Reply something containing a message reference
|
||||||
Reply
|
Reply
|
||||||
// Action any /me action
|
// Action any /me action
|
||||||
|
@ -33,6 +35,8 @@ const (
|
||||||
Delete
|
Delete
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type EphemeralID string
|
||||||
|
|
||||||
type ImageAttachment struct {
|
type ImageAttachment struct {
|
||||||
URL string
|
URL string
|
||||||
AltTxt string
|
AltTxt string
|
||||||
|
|
|
@ -42,6 +42,8 @@ func (d *Discord) RegisterEvent(callback bot.Callback) {
|
||||||
func (d Discord) Send(kind bot.Kind, args ...interface{}) (string, error) {
|
func (d Discord) Send(kind bot.Kind, args ...interface{}) (string, error) {
|
||||||
|
|
||||||
switch kind {
|
switch kind {
|
||||||
|
case bot.Ephemeral:
|
||||||
|
return d.sendMessage(args[0].(string), args[2].(string), false, args...)
|
||||||
case bot.Message:
|
case bot.Message:
|
||||||
return d.sendMessage(args[0].(string), args[1].(string), false, args...)
|
return d.sendMessage(args[0].(string), args[1].(string), false, args...)
|
||||||
case bot.Action:
|
case bot.Action:
|
||||||
|
|
|
@ -234,6 +234,9 @@ func (s *SlackApp) Send(kind bot.Kind, args ...interface{}) (string, error) {
|
||||||
switch kind {
|
switch kind {
|
||||||
case bot.Message:
|
case bot.Message:
|
||||||
return s.sendMessage(args[0].(string), args[1].(string), false, args...)
|
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:
|
case bot.Action:
|
||||||
return s.sendMessage(args[0].(string), args[1].(string), true, args...)
|
return s.sendMessage(args[0].(string), args[1].(string), true, args...)
|
||||||
case bot.Edit:
|
case bot.Edit:
|
||||||
|
@ -271,6 +274,8 @@ func (s *SlackApp) sendMessage(channel, message string, meMessage bool, args ...
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
switch a := a.(type) {
|
switch a := a.(type) {
|
||||||
|
case bot.EphemeralID:
|
||||||
|
options = append(options, slack.MsgOptionPostEphemeral(string(a)))
|
||||||
case bot.ImageAttachment:
|
case bot.ImageAttachment:
|
||||||
attachments = append(attachments, slack.Attachment{
|
attachments = append(attachments, slack.Attachment{
|
||||||
ImageURL: a.URL,
|
ImageURL: a.URL,
|
||||||
|
|
|
@ -196,7 +196,7 @@ func (p *MemePlugin) sendMeme(c bot.Connector, channel, channelName, msgID strin
|
||||||
id, w, h, err := p.genMeme(format, bullyImg, config)
|
id, w, h, err := p.genMeme(format, bullyImg, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("Hey %v, I couldn't download that image you asked for.", from.Name)
|
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
|
return
|
||||||
}
|
}
|
||||||
baseURL := p.c.Get("BaseURL", ``)
|
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"))
|
log.Debug().Msgf("Meme:\n%+v", r.PostForm.Get("text"))
|
||||||
channel := r.PostForm.Get("channel_id")
|
channel := r.PostForm.Get("channel_id")
|
||||||
channelName := r.PostForm.Get("channel_name")
|
channelName := r.PostForm.Get("channel_name")
|
||||||
|
userID := r.PostForm.Get("user_id")
|
||||||
from := r.PostForm.Get("user_name")
|
from := r.PostForm.Get("user_name")
|
||||||
text := r.PostForm.Get("text")
|
text := r.PostForm.Get("text")
|
||||||
log.Debug().Msgf("channel: %s", channel)
|
log.Debug().Msgf("channel: %s", channel)
|
||||||
|
|
||||||
user := &user.User{
|
user := &user.User{
|
||||||
ID: from, // HACK but should work fine
|
ID: userID, // HACK but should work fine
|
||||||
Name: from,
|
Name: from,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue