findserver

package
v1.19.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: MIT Imports: 9 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 owns",
	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
		}

		var whereQM qm.QueryMod
		if userIDToMatch != 0 {
			whereQM = qm.Where("owner_id = ?", userIDToMatch)
		} else {
			whereQM = qm.Where("name ILIKE ?", "%"+nameToMatch+"%")
		}

		results, err := models.JoinedGuilds(qm.Where("left_at is null"), whereQM, qm.OrderBy("id desc"), qm.Limit(250)).AllG(data.Context())
		if err != nil {
			return nil, err
		}

		resp := ""
		for _, v := range results {
			resp += fmt.Sprintf("`%d`: **%s**\n", v.ID, v.Name)
		}

		resp += fmt.Sprintf("%d results", len(results))

		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