mirror of
https://github.com/idanoo/GoDiscMoji
synced 2025-07-01 18:32:15 +00:00
Add more context
This commit is contained in:
parent
a8b2007f05
commit
464fa00efa
2 changed files with 125 additions and 38 deletions
|
@ -1,6 +1,7 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
|
@ -20,34 +21,8 @@ var (
|
|||
}
|
||||
|
||||
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
"show-top-emojis": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
top, err := b.Db.GetTopEmojisForGuild(i.GuildID, 5)
|
||||
if err != nil {
|
||||
slog.Error("Error getting top emojis", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Top Emojis:\n" + strings.Join(top, "\n"),
|
||||
},
|
||||
})
|
||||
},
|
||||
"show-top-users": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
top, err := b.Db.GetTopUsersForGuild(i.GuildID, 5)
|
||||
if err != nil {
|
||||
slog.Error("Error getting top users", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Top Users:\n" + strings.Join(top, "\n"),
|
||||
},
|
||||
})
|
||||
},
|
||||
"show-top-emojis": showTopEmojis,
|
||||
"show-top-users": showTopUsers,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -73,3 +48,67 @@ func (bot *Bot) DeregisterCommands() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// showTopEmojis - Show top emojis with users
|
||||
func showTopEmojis(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
top, err := b.Db.GetTopEmojisForGuild(i.GuildID, 5)
|
||||
if err != nil {
|
||||
slog.Error("Error getting top emojis", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
msg := "Most used emojis:\n"
|
||||
for k, v := range top {
|
||||
topUsers, err := b.Db.GetTopUsersForGuildEmoji(i.GuildID, k, 3)
|
||||
if err != nil {
|
||||
slog.Error("Error getting top users for guild emoji", "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
users := []string{}
|
||||
msg += fmt.Sprintf("%s: %d", k, v)
|
||||
for sk, sv := range topUsers {
|
||||
users = append(users, fmt.Sprintf("<@%s>: %d", sk, sv))
|
||||
}
|
||||
msg += " (" + strings.Join(users, ", ") + ")\n"
|
||||
}
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: msg,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// showTopUsers - Show top users with emojis
|
||||
func showTopUsers(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
top, err := b.Db.GetTopUsersForGuild(i.GuildID, 5)
|
||||
if err != nil {
|
||||
slog.Error("Error getting top users", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
msg := "Users who use the most emojis:\n"
|
||||
for k, v := range top {
|
||||
topUsers, err := b.Db.GetTopEmojisForGuildUser(i.GuildID, k, 3)
|
||||
if err != nil {
|
||||
slog.Error("Error getting top emojis for guild user", "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
users := []string{}
|
||||
msg += fmt.Sprintf("<@%s>: %d", k, v)
|
||||
for sk, sv := range topUsers {
|
||||
users = append(users, fmt.Sprintf("%s: %d", sk, sv))
|
||||
}
|
||||
msg += " (" + strings.Join(users, ", ") + ")\n"
|
||||
}
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: msg,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue