diff --git a/commands/guild.go b/commands/guild.go index 97c182c..549460b 100644 --- a/commands/guild.go +++ b/commands/guild.go @@ -43,6 +43,10 @@ func ListGuildsCommand(session *discordgo.Session) { return } + if guild.Name == "" && guildWithCounts.Name != "" { + guild.Name = guildWithCounts.Name + } + guilds = append(guilds, GuildListing{ Name: guild.Name, Members: guildWithCounts.ApproximateMemberCount, @@ -66,11 +70,19 @@ func GetSortedChannels(session *discordgo.Session, guildId string, withCategorie if err != nil { return channels } + guildChannels := guild.Channels + if len(guildChannels) == 0 { + c, err := session.GuildChannels(guildId) + if err != nil { + return channels + } + guildChannels = c + } if withCategories { categories := make(map[string][]*discordgo.Channel) - for _, channel := range guild.Channels { + for _, channel := range guildChannels { if channel.Type != discordgo.ChannelTypeGuildText && channel.Type != discordgo.ChannelTypeGuildNews { continue } @@ -117,7 +129,7 @@ func GetSortedChannels(session *discordgo.Session, guildId string, withCategorie categories[id] = categoryChannels } - keys := make([]string, 0, len(categories) - 1) + keys := make([]string, 0) for id := range categories { if id == "0" { continue @@ -143,7 +155,7 @@ func GetSortedChannels(session *discordgo.Session, guildId string, withCategorie } } } else { - for _, channel := range guild.Channels { + for _, channel := range guildChannels { if channel.Type != discordgo.ChannelTypeGuildText && channel.Type != discordgo.ChannelTypeGuildNews { continue } @@ -239,7 +251,7 @@ func ListChannelsCommand(session *discordgo.Session) { created := "??-???-??" timestamp, err := discordgo.SnowflakeTimestamp(channel.ID) if err == nil { - created = timestamp.Format("02-Jan-06") + created = timestamp.UTC().Format("02-Jan-06") } fmt.Printf(" %*s %s %s\n\r", longest, name, created, topic) @@ -359,6 +371,9 @@ func ListUsersCommand(session *discordgo.Session) { index := 0 for _, position := range positions { members := membersByPosition[position] + if len(members) > 150 { + continue + } for _, member := range members { statusColor := "reset" @@ -431,10 +446,13 @@ func SwitchGuild(session *discordgo.Session, input string) { last := state.GetLastChannel(target) if last == "" { channels := GetSortedChannels(session, target, false, false) - topChannel := channels[0] + // NB: ???????????????? + if len(channels) > 0 { + topChannel := channels[0] - state.SetCurrentChannel(topChannel.ID) - state.SetLastChannel(target, topChannel.ID) + state.SetCurrentChannel(topChannel.ID) + state.SetLastChannel(target, topChannel.ID) + } } else { state.SetCurrentChannel(last) } diff --git a/commands/main.go b/commands/main.go index e9f4a1f..74d549c 100644 --- a/commands/main.go +++ b/commands/main.go @@ -76,6 +76,11 @@ func Setup() { Run: CrossPeekCommand, Description: "cross-guild peek", } + + commandMap["+"] = Command{ + Run: TimeCommand, + Description: "current time", + } } func GetCommand(key string) (Command, bool) { diff --git a/commands/time.go b/commands/time.go new file mode 100644 index 0000000..dc67a8b --- /dev/null +++ b/commands/time.go @@ -0,0 +1,14 @@ +package commands + +import ( + "fmt" + "time" + + "github.com/bwmarrin/discordgo" +) + +func TimeCommand(session *discordgo.Session) { + now := time.Now().UTC() + + fmt.Printf("%s\n\r", now.Format("[Mon 02-Jan-06 15:04:05]")) +} diff --git a/lib/messages.go b/lib/messages.go index e817546..aebe979 100644 --- a/lib/messages.go +++ b/lib/messages.go @@ -38,7 +38,7 @@ type MessageOptions struct { func FormatMessage(session *discordgo.Session, options MessageOptions) []string { lines := make([]string, 0) - timestamp := options.Timestamp.Format("[15:04:05]") + timestamp := options.Timestamp.UTC().Format("[15:04:05]") nameLength := utf8.RuneCountInString(options.Name) + 2 stateNameLength := state.GetNameLength() diff --git a/main.go b/main.go index 8a98643..3b4e4d3 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,8 @@ func main() { return } - //client.LogLevel = discordgo.LogDebug + //client.LogLevel = -1 + client.LogLevel = discordgo.LogDebug client.Identify.Intents = discordgo.IntentsAll