large guild fixes
This commit is contained in:
parent
2d2ba1fd60
commit
7af5462d54
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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]"))
|
||||||
|
}
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue