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
}
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)
}

View File

@ -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) {

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 {
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()

View File

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