2023-07-06 22:21:11 +00:00
|
|
|
package events
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-09 20:00:49 +00:00
|
|
|
"unicode/utf8"
|
2023-07-06 22:21:11 +00:00
|
|
|
|
2023-07-11 04:35:15 +00:00
|
|
|
"github.com/Cynosphere/comcord/commands"
|
2023-07-09 01:17:47 +00:00
|
|
|
"github.com/Cynosphere/comcord/state"
|
2023-07-27 02:27:04 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v3/gateway"
|
2023-07-09 01:17:47 +00:00
|
|
|
"github.com/mgutz/ansi"
|
2023-07-06 22:21:11 +00:00
|
|
|
)
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
func Ready(event *gateway.ReadyEvent) {
|
|
|
|
client := state.GetClient()
|
|
|
|
self, err := client.Me()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print("\r% Failed to get self: ", err.Error(), "\n\r")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("\rLogged in as: %s\n\r", ansi.Color(fmt.Sprintf("%s (%s)", self.Username, self.ID), "yellow"))
|
2023-07-09 01:17:47 +00:00
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
state.SetNameLength(utf8.RuneCountInString(self.Username) + 2)
|
2023-07-09 01:17:47 +00:00
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
commands.ListGuildsCommand()
|
2023-07-11 04:35:15 +00:00
|
|
|
|
2023-07-09 01:17:47 +00:00
|
|
|
defaultGuild := state.GetConfigValue("defaultGuild")
|
|
|
|
defaultChannel := state.GetConfigValue("defaultChannel")
|
|
|
|
if defaultGuild != "" {
|
2023-07-27 02:27:04 +00:00
|
|
|
parsedGuildId, err := discord.ParseSnowflake(defaultGuild)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print("\r% Failed to parse guild ID: ", err.Error(), "\n\r")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guild, err := client.Guild(discord.GuildID(parsedGuildId))
|
2023-07-09 04:42:58 +00:00
|
|
|
if err == nil {
|
2023-07-09 01:17:47 +00:00
|
|
|
if defaultChannel != "" {
|
|
|
|
state.SetCurrentChannel(defaultChannel)
|
|
|
|
state.SetLastChannel(defaultGuild, defaultChannel)
|
|
|
|
}
|
2023-07-27 02:27:04 +00:00
|
|
|
commands.SwitchGuild(guild.Name)
|
2023-07-09 01:17:47 +00:00
|
|
|
} else {
|
|
|
|
fmt.Println("\r% This account is not in the defined default guild.")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if defaultChannel != "" {
|
|
|
|
fmt.Println("\r% Default channel defined without defining default guild.")
|
|
|
|
}
|
|
|
|
}
|
2023-07-06 22:21:11 +00:00
|
|
|
}
|