Skip to content

Commit

Permalink
change mention emojis to randomer (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
h3mmy authored May 8, 2024
2 parents 0139656 + be70040 commit 23b849b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bot/discord/commands/user_mentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,31 @@ func DirectedMessageReceive(s *discordgo.Session, m *discordgo.MessageCreate) {
nsfwContext = channel.NSFW
}

guildEmojis, err := s.GuildEmojis(m.GuildID)
if err != nil {
logger.Warn("could not get emoji for guild", zap.String("guildID", m.GuildID))
}

botMentioned := false
// Filter only commands we care about
if len(m.Mentions) > 0 {
// Just react to some mentions mysteriously
if rand.Float32()<0.5 {
if rand.Float32() < 0.5 {
var err error
if nsfwContext {
err = s.MessageReactionAdd(m.ChannelID, m.ID, "imwetrn:1236826185783316552")
} else {
if guildEmojis != nil {
emj := selectGuildEmojiForReaction(guildEmojis)
if emj.Available {
err = s.MessageReactionAdd(m.ChannelID, m.ID, emj.APIName())
} else {
err = s.MessageReactionAdd(m.ChannelID, m.ID, "👁‍🗨")
}
} else{
err = s.MessageReactionAdd(m.ChannelID, m.ID, "👁‍🗨")
}
}
if err != nil {
logger.Warn(fmt.Sprintf("Error adding reaction to message %s from user %s", m.ID, m.Author.Username))
}
Expand All @@ -60,7 +74,7 @@ func DirectedMessageReceive(s *discordgo.Session, m *discordgo.MessageCreate) {

if !directMessage && botMentioned {
logger.Sugar().Debug(fmt.Sprintf("Detected Channel Mention in message from %s with UserID %s and Content: ", m.Author.Username, m.Author.ID), m.Content)
err := s.MessageReactionAdd(m.ChannelID, m.ID,emojiZoop)
err := s.MessageReactionAdd(m.ChannelID, m.ID, emojiZoop)
if err != nil {
logger.Sugar().Error(err)
return
Expand Down
5 changes: 5 additions & 0 deletions bot/discord/commands/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"math/rand"
"time"

"github.com/bwmarrin/discordgo"
Expand Down Expand Up @@ -37,3 +38,7 @@ func typeInChannel(channel chan bool, s *discordgo.Session, channelID string) {
}
}
}

func selectGuildEmojiForReaction(emojiPool []*discordgo.Emoji) *discordgo.Emoji {
return emojiPool[rand.Intn(len(emojiPool))]
}
4 changes: 4 additions & 0 deletions bot/internal/models/discord_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ type DiscordAppCommand interface {
GetGuildID() string
GetAllowedRoles() []int64
}

type EmojiProvider interface {
GetEmoji() string
}

0 comments on commit 23b849b

Please sign in to comment.