large guild fixes

This commit is contained in:
Cynthia Foxwell 2023-07-26 16:51:25 -06:00
parent 2d2ba1fd60
commit 7af5462d54
5 changed files with 47 additions and 9 deletions

View File

@ -43,6 +43,10 @@ func ListGuildsCommand(session *discordgo.Session) {
return return
} }
if guild.Name == "" && guildWithCounts.Name != "" {
guild.Name = guildWithCounts.Name
}
guilds = append(guilds, GuildListing{ guilds = append(guilds, GuildListing{
Name: guild.Name, Name: guild.Name,
Members: guildWithCounts.ApproximateMemberCount, Members: guildWithCounts.ApproximateMemberCount,
@ -66,11 +70,19 @@ func GetSortedChannels(session *discordgo.Session, guildId string, withCategorie
if err != nil { if err != nil {
return channels return channels
} }
guildChannels := guild.Channels
if len(guildChannels) == 0 {
c, err := session.GuildChannels(guildId)
if err != nil {
return channels
}
guildChannels = c
}
if withCategories { if withCategories {
categories := make(map[string][]*discordgo.Channel) categories := make(map[string][]*discordgo.Channel)
for _, channel := range guild.Channels { for _, channel := range guildChannels {
if channel.Type != discordgo.ChannelTypeGuildText && channel.Type != discordgo.ChannelTypeGuildNews { if channel.Type != discordgo.ChannelTypeGuildText && channel.Type != discordgo.ChannelTypeGuildNews {
continue continue
} }
@ -117,7 +129,7 @@ func GetSortedChannels(session *discordgo.Session, guildId string, withCategorie
categories[id] = categoryChannels categories[id] = categoryChannels
} }
keys := make([]string, 0, len(categories) - 1) keys := make([]string, 0)
for id := range categories { for id := range categories {
if id == "0" { if id == "0" {
continue continue
@ -143,7 +155,7 @@ func GetSortedChannels(session *discordgo.Session, guildId string, withCategorie
} }
} }
} else { } else {
for _, channel := range guild.Channels { for _, channel := range guildChannels {
if channel.Type != discordgo.ChannelTypeGuildText && channel.Type != discordgo.ChannelTypeGuildNews { if channel.Type != discordgo.ChannelTypeGuildText && channel.Type != discordgo.ChannelTypeGuildNews {
continue continue
} }
@ -239,7 +251,7 @@ func ListChannelsCommand(session *discordgo.Session) {
created := "??-???-??" created := "??-???-??"
timestamp, err := discordgo.SnowflakeTimestamp(channel.ID) timestamp, err := discordgo.SnowflakeTimestamp(channel.ID)
if err == nil { 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) fmt.Printf(" %*s %s %s\n\r", longest, name, created, topic)
@ -359,6 +371,9 @@ func ListUsersCommand(session *discordgo.Session) {
index := 0 index := 0
for _, position := range positions { for _, position := range positions {
members := membersByPosition[position] members := membersByPosition[position]
if len(members) > 150 {
continue
}
for _, member := range members { for _, member := range members {
statusColor := "reset" statusColor := "reset"
@ -431,10 +446,13 @@ func SwitchGuild(session *discordgo.Session, input string) {
last := state.GetLastChannel(target) last := state.GetLastChannel(target)
if last == "" { if last == "" {
channels := GetSortedChannels(session, target, false, false) channels := GetSortedChannels(session, target, false, false)
topChannel := channels[0] // NB: ????????????????
if len(channels) > 0 {
topChannel := channels[0]
state.SetCurrentChannel(topChannel.ID) state.SetCurrentChannel(topChannel.ID)
state.SetLastChannel(target, topChannel.ID) state.SetLastChannel(target, topChannel.ID)
}
} else { } else {
state.SetCurrentChannel(last) state.SetCurrentChannel(last)
} }

View File

@ -76,6 +76,11 @@ func Setup() {
Run: CrossPeekCommand, Run: CrossPeekCommand,
Description: "cross-guild peek", Description: "cross-guild peek",
} }
commandMap["+"] = Command{
Run: TimeCommand,
Description: "current time",
}
} }
func GetCommand(key string) (Command, bool) { func GetCommand(key string) (Command, bool) {

14
commands/time.go Normal file
View File

@ -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]"))
}

View File

@ -38,7 +38,7 @@ type MessageOptions struct {
func FormatMessage(session *discordgo.Session, options MessageOptions) []string { func FormatMessage(session *discordgo.Session, options MessageOptions) []string {
lines := make([]string, 0) 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 nameLength := utf8.RuneCountInString(options.Name) + 2
stateNameLength := state.GetNameLength() stateNameLength := state.GetNameLength()

View File

@ -79,7 +79,8 @@ func main() {
return return
} }
//client.LogLevel = discordgo.LogDebug //client.LogLevel = -1
client.LogLevel = discordgo.LogDebug
client.Identify.Intents = discordgo.IntentsAll client.Identify.Intents = discordgo.IntentsAll