mirror of
https://github.com/idanoo/GoDiscMoji
synced 2025-07-02 02:42:15 +00:00
Allow custom counts
This commit is contained in:
parent
37a843825f
commit
1da9d79d70
2 changed files with 51 additions and 4 deletions
|
@ -9,14 +9,37 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
integerOptionMinValue = 5.0
|
||||||
|
amountKey = "amount"
|
||||||
|
|
||||||
commands = []*discordgo.ApplicationCommand{
|
commands = []*discordgo.ApplicationCommand{
|
||||||
{
|
{
|
||||||
Name: "show-top-emojis",
|
Name: "show-top-emojis",
|
||||||
Description: "Show top emojis",
|
Description: "Show top emojis",
|
||||||
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionInteger,
|
||||||
|
Name: amountKey,
|
||||||
|
Description: "Amount to show",
|
||||||
|
MinValue: &integerOptionMinValue,
|
||||||
|
MaxValue: 20,
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "show-top-users",
|
Name: "show-top-users",
|
||||||
Description: "Show top users",
|
Description: "Show top users",
|
||||||
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionInteger,
|
||||||
|
Name: amountKey,
|
||||||
|
Description: "Amount to show",
|
||||||
|
MinValue: &integerOptionMinValue,
|
||||||
|
MaxValue: 20,
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +74,19 @@ func (bot *Bot) DeregisterCommands() {
|
||||||
|
|
||||||
// showTopEmojis - Show top emojis with users
|
// showTopEmojis - Show top emojis with users
|
||||||
func showTopEmojis(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func showTopEmojis(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
top, err := b.Db.GetTopEmojisForGuild(i.GuildID, 5)
|
// Access options in the order provided by the user.
|
||||||
|
options := i.ApplicationCommandData().Options
|
||||||
|
optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options))
|
||||||
|
for _, opt := range options {
|
||||||
|
optionMap[opt.Name] = opt
|
||||||
|
}
|
||||||
|
|
||||||
|
amount := int64(5)
|
||||||
|
if opt, ok := optionMap[amountKey]; ok {
|
||||||
|
amount = opt.IntValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
top, err := b.Db.GetTopEmojisForGuild(i.GuildID, amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Error getting top emojis", "err", err)
|
slog.Error("Error getting top emojis", "err", err)
|
||||||
return
|
return
|
||||||
|
@ -84,7 +119,19 @@ func showTopEmojis(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
|
||||||
// showTopUsers - Show top users with emojis
|
// showTopUsers - Show top users with emojis
|
||||||
func showTopUsers(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func showTopUsers(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
top, err := b.Db.GetTopUsersForGuild(i.GuildID, 5)
|
// Access options in the order provided by the user.
|
||||||
|
options := i.ApplicationCommandData().Options
|
||||||
|
optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options))
|
||||||
|
for _, opt := range options {
|
||||||
|
optionMap[opt.Name] = opt
|
||||||
|
}
|
||||||
|
|
||||||
|
amount := int64(5)
|
||||||
|
if opt, ok := optionMap[amountKey]; ok {
|
||||||
|
amount = opt.IntValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
top, err := b.Db.GetTopUsersForGuild(i.GuildID, amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Error getting top users", "err", err)
|
slog.Error("Error getting top users", "err", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -11,7 +11,7 @@ func (db *Database) LogEmojiUsage(guildID, channelID, userID, emojiID string) er
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTopUsersForGuild - Report usage
|
// GetTopUsersForGuild - Report usage
|
||||||
func (db *Database) GetTopUsersForGuild(guildID string, num int) (map[string]int64, error) {
|
func (db *Database) GetTopUsersForGuild(guildID string, num int64) (map[string]int64, error) {
|
||||||
data := make(map[string]int64)
|
data := make(map[string]int64)
|
||||||
row, err := db.db.Query(
|
row, err := db.db.Query(
|
||||||
"SELECT user_id, count(*) FROM `emoji_usage` WHERE `guild_id` = ? GROUP BY user_id ORDER BY count(*) DESC LIMIT ?",
|
"SELECT user_id, count(*) FROM `emoji_usage` WHERE `guild_id` = ? GROUP BY user_id ORDER BY count(*) DESC LIMIT ?",
|
||||||
|
@ -60,7 +60,7 @@ func (db *Database) GetTopUsersForGuildEmoji(guildID string, emojiID string, num
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTopEmojisForGuild - Report usage
|
// GetTopEmojisForGuild - Report usage
|
||||||
func (db *Database) GetTopEmojisForGuild(guildID string, num int) (map[string]int64, error) {
|
func (db *Database) GetTopEmojisForGuild(guildID string, num int64) (map[string]int64, error) {
|
||||||
data := make(map[string]int64)
|
data := make(map[string]int64)
|
||||||
row, err := db.db.Query(
|
row, err := db.db.Query(
|
||||||
"SELECT emoji_id, count(*) FROM `emoji_usage` WHERE `guild_id` = ? GROUP BY emoji_id ORDER BY count(*) DESC LIMIT ?",
|
"SELECT emoji_id, count(*) FROM `emoji_usage` WHERE `guild_id` = ? GROUP BY emoji_id ORDER BY count(*) DESC LIMIT ?",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue