mirror of
https://github.com/idanoo/GoDiscMoji
synced 2025-07-02 02:42:15 +00:00
Compare commits
6 commits
d4244e0f4a
...
75fc7b9bb4
Author | SHA1 | Date | |
---|---|---|---|
75fc7b9bb4 | |||
e2b21beec6 | |||
d132cfe4cc | |||
e553aca772 | |||
200a08ecbc | |||
ca38e5bb85 |
6 changed files with 12 additions and 20 deletions
|
@ -63,7 +63,6 @@ func runScrubber() {
|
|||
err := b.DiscordSession.MessageReactionRemove(e.ChannelID, e.MessageID, e.EmojiID, e.UserID)
|
||||
if err != nil {
|
||||
slog.Error("Error removing emoji reaction", "err", err, "emoji", e.EmojiID, "user", e.UserID)
|
||||
continue
|
||||
}
|
||||
|
||||
// We care if we can't delete from our DB..
|
||||
|
|
|
@ -154,7 +154,7 @@ func showTopEmojis(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
users := []string{}
|
||||
if top[v].EmojiID == top[v].EmojiName {
|
||||
// Handle bad data with stock emojis
|
||||
msg += fmt.Sprintf(":%s: %d", top[v].EmojiName, top[v].Count)
|
||||
msg += fmt.Sprintf("%s %d", top[v].EmojiName, top[v].Count)
|
||||
} else {
|
||||
msg += fmt.Sprintf("<:%s:%s> %d", top[v].EmojiName, top[v].EmojiID, top[v].Count)
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func showTopUsers(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
for _, sv := range subkeys {
|
||||
if topUsers[sv].EmojiID == topUsers[sv].EmojiName {
|
||||
// Handle bad data with stock emojis
|
||||
users = append(users, fmt.Sprintf(":%s: %d", topUsers[sv].EmojiName, topUsers[sv].Count))
|
||||
users = append(users, fmt.Sprintf("%s %d", topUsers[sv].EmojiName, topUsers[sv].Count))
|
||||
} else {
|
||||
users = append(users, fmt.Sprintf("<:%s:%s> %d", topUsers[sv].EmojiName, topUsers[sv].EmojiID, topUsers[sv].Count))
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func addAutoScrubber(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: fmt.Sprintf("Error auto scrubbing user %s", user.Username),
|
||||
Content: fmt.Sprintf("Error auto scrubbing user %s: %+v", user.Username, err.Error()),
|
||||
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
||||
},
|
||||
})
|
||||
|
@ -293,7 +293,7 @@ func addAutoScrubber(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: fmt.Sprintf("Will remove %s's emojis every %d minutes", user.Username, minutes),
|
||||
Content: fmt.Sprintf("Will remove %s's emojis after %d minutes", user.Username, minutes),
|
||||
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
||||
},
|
||||
})
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package bot
|
||||
|
||||
func orderMap(m map[string]int64) []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
|
@ -69,6 +69,9 @@ func (bot *Bot) Start() error {
|
|||
bot.RegisterCommands()
|
||||
b = bot
|
||||
|
||||
// Add scrubber
|
||||
initScrubber()
|
||||
|
||||
// Keep running untill there is NO os interruption (ctrl + C)
|
||||
slog.Info("Bot is now running. Press CTRL-C to exit.")
|
||||
c := make(chan os.Signal, 1)
|
||||
|
|
|
@ -13,7 +13,7 @@ type AutoScrubber struct {
|
|||
// AddAutoScrubber - Add an auto scrubber for a guild/user
|
||||
func (db *Database) AddAutoScrubber(guildID, userID string, duration time.Duration) error {
|
||||
_, err := db.db.Exec(
|
||||
"INSERT IGNORE INTO `auto_scrubber` (`guild_id`, `user_id`, `duration`) VALUES (?,?,?)",
|
||||
"INSERT INTO `auto_scrubber` (`guild_id`, `user_id`, `duration`) VALUES (?,?,?)",
|
||||
guildID, userID, duration,
|
||||
)
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ func (db *Database) GetTopEmojisForGuildUser(guildID string, userID string, num
|
|||
func (db *Database) GetRecentEmojisForUser(guildID string, userID string, hours int64) ([]EmojiUsage, error) {
|
||||
var data []EmojiUsage
|
||||
row, err := db.db.Query(
|
||||
"SELECT guild_id, channel_id, message_id, user_id, emoji_id, emoji_name, timestamp "+
|
||||
"SELECT id, guild_id, channel_id, message_id, user_id, emoji_id, emoji_name, timestamp "+
|
||||
"FROM `emoji_usage` WHERE `guild_id` = ? AND `user_id` = ? AND timestamp >= datetime('now', '-"+fmt.Sprintf("%d", hours)+" hours') "+
|
||||
"ORDER BY timestamp DESC",
|
||||
guildID,
|
||||
|
@ -187,7 +187,7 @@ func (db *Database) GetRecentEmojisForUser(guildID string, userID string, hours
|
|||
defer row.Close()
|
||||
for row.Next() {
|
||||
usage := EmojiUsage{}
|
||||
row.Scan(&usage.GuildID, &usage.ChannelID, &usage.MessageID, &usage.UserID, &usage.EmojiID, &usage.EmojiName, &usage.Timestamp)
|
||||
row.Scan(&usage.ID, &usage.GuildID, &usage.ChannelID, &usage.MessageID, &usage.UserID, &usage.EmojiID, &usage.EmojiName, &usage.Timestamp)
|
||||
data = append(data, usage)
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ func (db *Database) GetRecentEmojisForUser(guildID string, userID string, hours
|
|||
func (db *Database) GetAllEmojisForUser(guildID string, userID string) ([]EmojiUsage, error) {
|
||||
var data []EmojiUsage
|
||||
row, err := db.db.Query(
|
||||
"SELECT guild_id, channel_id, message_id, user_id, emoji_id, emoji_name, timestamp "+
|
||||
"SELECT id, guild_id, channel_id, message_id, user_id, emoji_id, emoji_name, timestamp "+
|
||||
"FROM `emoji_usage` WHERE `guild_id` = ? AND `user_id` = ?",
|
||||
guildID,
|
||||
userID,
|
||||
|
@ -211,7 +211,7 @@ func (db *Database) GetAllEmojisForUser(guildID string, userID string) ([]EmojiU
|
|||
defer row.Close()
|
||||
for row.Next() {
|
||||
usage := EmojiUsage{}
|
||||
row.Scan(&usage.GuildID, &usage.ChannelID, &usage.MessageID, &usage.UserID, &usage.EmojiID, &usage.EmojiName, &usage.Timestamp)
|
||||
row.Scan(&usage.ID, &usage.GuildID, &usage.ChannelID, &usage.MessageID, &usage.UserID, &usage.EmojiID, &usage.EmojiName, &usage.Timestamp)
|
||||
data = append(data, usage)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue