Skip to content

Commit

Permalink
fix: remove guild on leave
Browse files Browse the repository at this point in the history
  • Loading branch information
SushiWaUmai committed Jun 27, 2023
1 parent fb172a3 commit 66428ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,11 @@ func handleInteraction(s *discordgo.Session, i *discordgo.InteractionCreate) {
c.Execute(s, i)
}
}

func handleGuildLeave(s *discordgo.Session, g *discordgo.GuildDelete) {
err := db.DeleteGuild(g.ID)

if err != nil {
log.Printf("Error deleting guild channels for guild %s: %v\n", g.ID, err)
}
}
4 changes: 4 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func DeleteGuildChannels(guildID string, channelID string) error {
return db.Where("guild_id = ? AND channel_id = ?", guildID, channelID).Delete(&GuildChannel{}).Error
}

func DeleteGuild(guildID string) error {
return db.Where("guild_id = ?", guildID).Delete(&GuildChannel{}).Error
}

func GetGuildChannel(guildID string, channelID string, category string) (*GuildChannel, error) {
var guildChannel GuildChannel
err := db.Where("guild_id = ? AND channel_id = ? AND category = ?", guildID, channelID, category).First(&guildChannel).Error
Expand Down

0 comments on commit 66428ef

Please sign in to comment.