list guilds
This commit is contained in:
parent
4aa208ee69
commit
80a343e4ee
4 changed files with 62 additions and 2 deletions
|
@ -18,7 +18,7 @@ Go is more portable than Node.js
|
||||||
- [ ] Switch guilds (G)
|
- [ ] Switch guilds (G)
|
||||||
- [ ] Switch channels (g)
|
- [ ] Switch channels (g)
|
||||||
- [ ] List online users in guild (w)
|
- [ ] List online users in guild (w)
|
||||||
- [ ] Emote (e)
|
- [x] Emote (e)
|
||||||
- Just sends message surrounded in `*`'s
|
- Just sends message surrounded in `*`'s
|
||||||
- [ ] Finger (f)
|
- [ ] Finger (f)
|
||||||
- Shows presence data if available
|
- Shows presence data if available
|
||||||
|
@ -28,7 +28,7 @@ Go is more portable than Node.js
|
||||||
- [ ] Peek (p)
|
- [ ] Peek (p)
|
||||||
- [ ] Cross-guild peek (P)
|
- [ ] Cross-guild peek (P)
|
||||||
- [ ] List channels (l)
|
- [ ] List channels (l)
|
||||||
- [ ] List guilds (L)
|
- [x] List guilds (L)
|
||||||
- [x] Clear (c)
|
- [x] Clear (c)
|
||||||
- [ ] Surf channels forwards (>)
|
- [ ] Surf channels forwards (>)
|
||||||
- [ ] Surf channels backwards (<)
|
- [ ] Surf channels backwards (<)
|
||||||
|
|
52
commands/guild.go
Normal file
52
commands/guild.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GuildListing struct {
|
||||||
|
Name string
|
||||||
|
Members int
|
||||||
|
Online int
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListGuildsCommand(session *discordgo.Session) {
|
||||||
|
longest := 0
|
||||||
|
guilds := make([]GuildListing, 0)
|
||||||
|
|
||||||
|
for _, guild := range session.State.Guilds {
|
||||||
|
length := utf8.RuneCountInString(guild.Name)
|
||||||
|
if length > longest {
|
||||||
|
longest = length
|
||||||
|
}
|
||||||
|
|
||||||
|
guildWithCounts, err := session.GuildWithCounts(guild.ID)
|
||||||
|
if err != nil {
|
||||||
|
guilds = append(guilds, GuildListing{
|
||||||
|
Name: guild.Name,
|
||||||
|
Members: guild.MemberCount,
|
||||||
|
Online: 0,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guilds = append(guilds, GuildListing{
|
||||||
|
Name: guild.Name,
|
||||||
|
Members: guildWithCounts.ApproximateMemberCount,
|
||||||
|
Online: guildWithCounts.ApproximatePresenceCount,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print("\n\r")
|
||||||
|
fmt.Printf(" %*s online total\n\r", longest, "guild-name")
|
||||||
|
fmt.Print(strings.Repeat("-", 80) + "\n\r")
|
||||||
|
for _, guild := range guilds {
|
||||||
|
fmt.Printf(" %*s %6d %5d\n\r", longest, guild.Name, guild.Online, guild.Members)
|
||||||
|
}
|
||||||
|
fmt.Print(strings.Repeat("-", 80) + "\n\r")
|
||||||
|
fmt.Print("\n\r")
|
||||||
|
}
|
|
@ -31,6 +31,11 @@ func Setup() {
|
||||||
Run: EmoteCommand,
|
Run: EmoteCommand,
|
||||||
Description: "emote",
|
Description: "emote",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commandMap["L"] = Command{
|
||||||
|
Run: ListGuildsCommand,
|
||||||
|
Description: "list guilds",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCommand(key string) (Command, bool) {
|
func GetCommand(key string) (Command, bool) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/Cynosphere/comcord/commands"
|
||||||
"github.com/Cynosphere/comcord/state"
|
"github.com/Cynosphere/comcord/state"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/mgutz/ansi"
|
"github.com/mgutz/ansi"
|
||||||
|
@ -14,6 +15,8 @@ func Ready(session *discordgo.Session, event *discordgo.Ready) {
|
||||||
|
|
||||||
state.SetNameLength(utf8.RuneCountInString(session.State.User.Username) + 2)
|
state.SetNameLength(utf8.RuneCountInString(session.State.User.Username) + 2)
|
||||||
|
|
||||||
|
commands.ListGuildsCommand(session)
|
||||||
|
|
||||||
defaultGuild := state.GetConfigValue("defaultGuild")
|
defaultGuild := state.GetConfigValue("defaultGuild")
|
||||||
defaultChannel := state.GetConfigValue("defaultChannel")
|
defaultChannel := state.GetConfigValue("defaultChannel")
|
||||||
if defaultGuild != "" {
|
if defaultGuild != "" {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue