Skip to content

Commit

Permalink
add: number of servers to ready message
Browse files Browse the repository at this point in the history
updating the status didn't seem to work but i also dont really care
*that* much, will look at later
  • Loading branch information
fvckgrimm committed Aug 15, 2024
1 parent 8dbf3d6 commit fac7ca5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,29 @@ func main() {
defer discord.Close()

go monitorUsers(discord)
go updateStatusPeriodically(discord)

log.Println("Bot is now running. Press CTRL-C to exit.")
select {}
}

func updateStatusPeriodically(s *discordgo.Session) {
ticker := time.NewTicker(180 * time.Minute)
defer ticker.Stop()

for range ticker.C {
updateBotStatus(s)
}
}

func ready(s *discordgo.Session, event *discordgo.Ready) {
log.Println("Bot is ready")
serverCount := len(s.State.Guilds)
log.Printf("Currently active and monitoring in %d servers", serverCount)
manageServerPerm := int64(discordgo.PermissionManageServer)

updateBotStatus(s)

_, err := s.ApplicationCommandBulkOverwrite(s.State.User.ID, "", []*discordgo.ApplicationCommand{
{
Name: "add",
Expand Down Expand Up @@ -151,6 +165,22 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
}
}

func updateBotStatus(s *discordgo.Session) {
serverCount := len(s.State.Guilds)
status := fmt.Sprintf("Watching %d servers", serverCount)
err := s.UpdateStatusComplex(discordgo.UpdateStatusData{
Activities: []*discordgo.Activity{
{
Name: status,
Type: discordgo.ActivityTypeWatching,
},
},
})
if err != nil {
log.Printf("Error updating status: %v", err)
}
}

func hasAdminOrModPermissions(s *discordgo.Session, i *discordgo.InteractionCreate) bool {
// Check if the user is the server owner
guild, err := s.Guild(i.GuildID)
Expand Down

0 comments on commit fac7ca5

Please sign in to comment.