listroles

package
v1.31.14 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	CmdCategory: commands.CategoryTool,
	Name:        "ListRoles",
	Aliases:     []string{"lr", "ur"},
	Description: "List roles, their id's, color hex code, and 'mention everyone' perms (useful if you wanna double check to make sure you didn't give anyone mention everyone perms that shouldn't have it)",
	Arguments: []*dcmd.ArgDef{
		{Name: "User", Type: &commands.MemberArg{}},
	},

	ArgSwitches: []*dcmd.ArgDef{
		{Name: "nomanaged", Help: "Don't list managed/bot roles"},
		{Name: "managed", Help: "List managed/bot roles"},
		{Name: "raw", Help: "Raw, legacy output"},
	},

	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		var out, outFinal string
		var noMana, yesMana, raw bool
		var member *dstate.MemberState
		maxLength := 24

		if data.Args[0].Value != nil {
			member = data.Args[0].Value.(*dstate.MemberState)
		}

		if data.Switches["nomanaged"].Value != nil && data.Switches["nomanaged"].Value.(bool) && member == nil {
			noMana = true
		}

		if data.Switches["managed"].Value != nil && data.Switches["managed"].Value.(bool) && member == nil {
			yesMana = true
		}

		if data.Switches["raw"].Value != nil && data.Switches["raw"].Value.(bool) {
			raw = true
		}

		counter := 0
		if member != nil {
			if len(member.Member.Roles) > 0 {
				for _, roleID := range member.Member.Roles {
					for _, r := range data.GuildData.GS.Roles {
						if roleID == r.ID {
							counter++
							toOut(&r, raw, &out)
						}
					}
				}
			} else {
				return "User has no roles", nil
			}
		} else {
			for _, r := range data.GuildData.GS.Roles {
				if noMana && r.Managed {
					continue
				} else if yesMana && !r.Managed {
					continue
				} else {
					counter++
					toOut(&r, raw, &out)
				}
			}
		}

		if raw {
			outFinal = fmt.Sprintf("Total role count: %d\n", counter)
			outFinal += fmt.Sprintf("%s", "(ME = mention everyone perms)\n")
			outFinal += out

			return outFinal, nil

		}

		outSlice := strings.Split(out, "\n")
		_, err := paginatedmessages.CreatePaginatedMessage(
			data.GuildData.GS.ID, data.ChannelID, 1, int(math.Ceil(float64(len(outSlice))/float64(maxLength))), func(p *paginatedmessages.PaginatedMessage, page int) (*discordgo.MessageEmbed, error) {
				i := page - 1
				paginatedEmbed := embedCreator(outSlice, i, maxLength, counter)
				return paginatedEmbed, nil
			})
		if err != nil {
			return fmt.Sprintf("Something went wrong: %s", err), nil
		}
		return nil, 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