Skip to content

Commit

Permalink
chore: more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ADRFranklin committed Mar 31, 2024
1 parent 36e0f69 commit 4417274
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bot/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ func Start(config *types.Config) {
zap.Any("config", config))

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
<-signals
}
6 changes: 3 additions & 3 deletions bot/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (app *App) onMessage(s *discordgo.Session, event *discordgo.MessageCreate)
}
}

if event.Message.Author.Bot == true {
if event.Message.Author.Bot {
return
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func (app *App) onReactionAdd(s *discordgo.Session, event *discordgo.MessageReac
}

emoji := event.Emoji.APIName()
if strings.Index(emoji, ":") != -1 {
if strings.Contains(emoji, ":") {
emoji = fmt.Sprintf("<:%s>", emoji)
}
err = app.storage.AddEmojiReactionToUser(message.DiscordUserID, emoji)
Expand All @@ -147,7 +147,7 @@ func (app *App) onReactionRemove(s *discordgo.Session, event *discordgo.MessageR
}

emoji := event.Emoji.APIName()
if strings.Index(emoji, ":") != -1 {
if strings.Contains(emoji, ":") {
emoji = fmt.Sprintf("<:%s>", emoji)
}
err = app.storage.RemoveEmojiReactionFromUser(message.DiscordUserID, emoji)
Expand Down
12 changes: 6 additions & 6 deletions storage/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (m *MongoStorer) AddEmojiReactionToUser(discordUserID string, emoji string)
user.ReceivedReactions[i].Counter++
}
}
if found == false {
if !found {
entry := ReactionCounter{
Counter: 1,
Reaction: emoji,
Expand All @@ -77,27 +77,27 @@ type TopReactionEntry struct {
// GetTopReactions gets the top <top> amount of people who received reaction <reaction>
func (m *MongoStorer) GetTopReactions(top int, reaction string) (result []TopReactionEntry, err error) {
pipeline := []bson.M{
bson.M{
{
"$unwind": "$received_reactions",
},
bson.M{
{
"$match": bson.M{
"received_reactions.reaction": reaction,
},
},
bson.M{
{
"$project": bson.M{
"discord_user_id": "$discord_user_id",
"counter": "$received_reactions.counter",
"reaction": "$received_reactions.reaction",
},
},
bson.M{
{
"$sort": bson.M{
"counter": -1,
},
},
bson.M{
{
"$limit": top,
},
}
Expand Down

0 comments on commit 4417274

Please sign in to comment.