topservers

package
v2.49.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	Cooldown:    5,
	CmdCategory: commands.CategoryDebug,
	Name:        "TopServers",
	Description: "Responds with the top 20 servers I'm on. *Bot admin only.",
	Arguments: []*dcmd.ArgDef{
		{Name: "Skip", Help: "Entries to skip", Type: dcmd.Int, Default: 0},
	},
	ArgSwitches: []*dcmd.ArgDef{
		{Name: "id", Type: dcmd.BigInt},
		{Name: "shard", Help: "Shard to get top servers from", Type: dcmd.Int},
	},
	RunFunc: util.RequireBotAdmin(func(data *dcmd.Data) (interface{}, error) {
		skip := data.Args[0].Int()

		if data.Switches["id"].Value != nil {
			type serverIDQuery struct {
				MemberCount int64
				Name        string
				Place       int64
			}
			var serverID int64
			var position serverIDQuery
			serverID = data.Switch("id").Int64()
			const q = `` /* 214-byte string literal not displayed */
			err := common.PQ.QueryRow(q, serverID).Scan(&position.MemberCount, &position.Name, &position.Place)
			return fmt.Sprintf("```Server with ID %d is placed:\n#%-2d: %-25s (%d members)\n```", serverID, position.Place, position.Name, position.MemberCount), err
		}
		query := []qm.QueryMod{}
		totalShards := common.ConfTotalShards.GetInt()
		shard := -1
		if data.Switches["shard"].Value != nil {
			shard = data.Switch("shard").Int()
		}
		if totalShards > 0 && shard >= 0 && shard < totalShards {
			query = append(query, qm.Where("(id >> 22) % ? = ?", totalShards, shard))
		}
		query = append(query, qm.Where("left_at is null"), qm.OrderBy("member_count desc"), qm.Limit(10), qm.Offset(skip))
		results, err := models.JoinedGuilds(query...).AllG(data.Context())
		if err != nil {
			return nil, err
		}
		out := "```"
		for k, v := range results {
			out += fmt.Sprintf("\n#%-2d: %-12d %-25s (%d members)", k+skip+1, v.ID, v.Name, v.MemberCount)
		}
		return "Top servers the bot is on:\n" + out + "\n```", nil
	}),
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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