topservers

package
v1.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	Cooldown:    5,
	CmdCategory: commands.CategoryFun,
	Name:        "TopServers",
	Description: "Responds with the top 15 servers I'm on",
	Arguments: []*dcmd.ArgDef{
		&dcmd.ArgDef{Name: "Skip", Help: "Entries to skip", Type: dcmd.Int, Default: 0},
	},
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		skip := data.Args[0].Int()

		state := bot.State
		state.RLock()

		guilds := make([]*discordgo.Guild, len(state.Guilds))
		i := 0
		for _, v := range state.Guilds {
			state.RUnlock()
			guilds[i] = v.LightCopy(true)
			state.RLock()
			i++
		}
		state.RUnlock()

		sortable := GuildsSortUsers(guilds)
		sort.Sort(sortable)

		entriesIncluded := 0
		out := "```"
		for k, v := range sortable {
			if entriesIncluded > 14 {
				break
			}

			if k < skip {
				continue
			}

			entriesIncluded++
			out += fmt.Sprintf("\n#%-2d: %-25s (%d members)", k+1, v.Name, v.MemberCount)
		}
		return "Top servers the bot is on (by membercount):\n" + out + "\n```", nil
	},
}

Functions

This section is empty.

Types

type GuildsSortUsers

type GuildsSortUsers []*discordgo.Guild

func (GuildsSortUsers) Len

func (g GuildsSortUsers) Len() int

func (GuildsSortUsers) Less

func (g GuildsSortUsers) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (GuildsSortUsers) Swap

func (g GuildsSortUsers) Swap(i, j int)

Swap swaps the elements with indexes i and j.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL