findserver

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	Cooldown:             2,
	CmdCategory:          commands.CategoryDebug,
	HideFromCommandsPage: true,
	Name:                 "findserver",
	Aliases:              []string{"findservers"},
	Description:          "Looks for a server by server name or the servers a user was on",
	HideFromHelp:         true,
	ArgSwitches: []*dcmd.ArgDef{
		&dcmd.ArgDef{Switch: "name", Name: "name", Type: dcmd.String, Default: ""},
		&dcmd.ArgDef{Switch: "user", Name: "user", Type: dcmd.UserID, Default: 0},
	},
	RunFunc: util.RequireBotAdmin(func(data *dcmd.Data) (interface{}, error) {
		nameToMatch := strings.ToLower(data.Switch("name").Str())
		userIDToMatch := data.Switch("user").Int64()

		if userIDToMatch == 0 && nameToMatch == "" {
			return "-name or -user not provided", nil
		}

		candidates := make([]*Candidate, 0, 0)

		bot.State.RLock()
		for _, v := range bot.State.Guilds {
			bot.State.RUnlock()

			v.RLock()
			if candidate := CheckGuild(v, nameToMatch, userIDToMatch); candidate != nil {
				candidates = append(candidates, candidate)
			}
			v.RUnlock()

			bot.State.RLock()

			if len(candidates) > 1000 {
				break
			}
		}
		bot.State.RUnlock()

		if len(candidates) < 1 {
			return "No matches", nil
		}

		resp := ""
		for _, candidate := range candidates {
			resp += fmt.Sprintf("`%d`: **%s**", candidate.ID, candidate.Name)
			if candidate.UserMatch {
				resp += fmt.Sprintf(" (owner: `%t`, admin: `%t`, mod: `%t`)", candidate.Owner, candidate.Admin, candidate.Mod)
			}

			resp += "\n"
		}

		return resp, nil
	}),
}

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	ID   int64
	Name string

	UserMatch bool
	Owner     bool
	Admin     bool
	Mod       bool
}

func CheckGuild

func CheckGuild(gs *dstate.GuildState, nameToMatch string, userToMatch int64) *Candidate

Jump to

Keyboard shortcuts

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