rolecommands

package
v1.20.5 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2019 License: MIT Imports: 31 Imported by: 0

README

Plugin that allows users to assign roles to themsleves

  • role options

    • names
    • group
    • require-roles
    • ignore-roles
    • allow-take-off-role
  • group options

    • name
    • require-roles
    • ignore-roles
    • mode
      • single
        • auto-take-away
        • require-one
      • multi
        • max-amount
        • min-amount
      • none

Documentation

Overview

rolecommands is a plugin which allows users to assign roles to themselves

Index

Constants

View Source
const (
	GroupModeNone = iota
	GroupModeSingle
	GroupModeMultiple
)
View Source
const (
	RoleMenuStateSettingUp              = 0
	RoleMenuStateDone                   = 1
	RoleMenuStateEditingOptionSelecting = 2
	RoleMenuStateEditingOptionReplacing = 3
)

Variables

View Source
var DBSchemas = []string{`
CREATE TABLE IF NOT EXISTS role_groups (
	id bigserial NOT NULL PRIMARY KEY,
	guild_id bigint NOT NULL,
	name text NOT NULL,
	require_roles bigint[],
	ignore_roles bigint[],
	mode bigint NOT NULL,
	multiple_max bigint NOT NULL,
	multiple_min bigint NOT NULL,
	single_auto_toggle_off boolean NOT NULL,
	single_require_one boolean NOT NULL
);

`, `
CREATE INDEX IF NOT EXISTS role_groups_guild_idx ON role_groups(guild_id);

`, `
CREATE TABLE IF NOT EXISTS role_commands (
	id bigserial NOT NULL PRIMARY KEY,
	created_at timestamptz NOT NULL,
	updated_at timestamptz NOT NULL,
	guild_id bigint NOT NULL,
	name text NOT NULL,
	role_group_id bigint REFERENCES role_groups(id) ON DELETE SET NULL,
	role bigint NOT NULL,
	require_roles bigint[],
	ignore_roles bigint[],
	position bigint NOT NULL
);

`, `
CREATE INDEX IF NOT EXISTS role_commands_guild_idx ON role_commands(guild_id);
`, `
CREATE INDEX IF NOT EXISTS role_commands_role_group_idx ON role_commands(role_group_id);
`, `
CREATE TABLE IF NOT EXISTS role_menus (
 	message_id bigint NOT NULL PRIMARY KEY,
	guild_id bigint NOT NULL,
	channel_id bigint NOT NULL,
	owner_id bigint NOT NULL,
	own_message boolean NOT NULL,
	state bigint NOT NULL,
	next_role_command_id bigint REFERENCES role_commands(id) ON DELETE SET NULL,
	role_group_id bigint REFERENCES role_groups(id) ON DELETE CASCADE
);

`, `
ALTER TABLE role_menus ADD COLUMN IF NOT EXISTS disable_send_dm BOOLEAN NOT NULL DEFAULT false;
`, `
ALTER TABLE role_menus ADD COLUMN IF NOT EXISTS remove_role_on_reaction_remove BOOLEAN NOT NULL DEFAULT false;
`, `
ALTER TABLE role_menus ADD COLUMN IF NOT EXISTS fixed_amount BOOLEAN NOT NULL DEFAULT false;
`, `
ALTER TABLE role_menus ADD COLUMN IF NOT EXISTS skip_amount INT NOT NULL DEFAULT 0;
`, `
ALTER TABLE role_menus ADD COLUMN IF NOT EXISTS setup_msg_id BIGINT NOT NULL DEFAULT 0;
`, `
CREATE INDEX IF NOT EXISTS role_menus_setup_msg_idx ON role_menus(setup_msg_id);
`, `
CREATE TABLE IF NOT EXISTS role_menu_options (
	id bigserial NOT NULL PRIMARY KEY,
	role_command_id bigint REFERENCES role_commands(id) ON DELETE CASCADE,
	emoji_id bigint NOT NULL,
	unicode_emoji text NOT NULL,
	role_menu_id bigint NOT NULL REFERENCES role_menus(message_id) ON DELETE CASCADE
);
`, `
ALTER TABLE role_menus ADD COLUMN IF NOT EXISTS editing_option_id BIGINT;
`, `
DO $$
BEGIN

  BEGIN
    ALTER TABLE role_menus ADD CONSTRAINT role_menus_editing_option_id_fkey FOREIGN KEY (editing_option_id) REFERENCES role_menu_options(id) ON DELETE SET NULL;
  EXCEPTION
    WHEN duplicate_object THEN RAISE NOTICE 'Table constraint role_menus.role_menus_editing_option_id_fkey already exists';
  END;

END $$;
`, `
ALTER TABLE role_menu_options ADD COLUMN IF NOT EXISTS emoji_animated BOOLEAN NOT NULL DEFAULT false;
`, `
CREATE INDEX IF NOT EXISTS role_menu_options_role_command_idx ON role_menu_options(role_command_id);
`, `
CREATE INDEX IF NOT EXISTS role_menu_options_role_menu_id_idx ON role_menu_options(role_menu_id);
`, `
ALTER TABLE role_groups ADD COLUMN IF NOT EXISTS temporary_role_duration INT NOT NULL DEFAULT 0;
`}

Functions

func AssignRole

func AssignRole(ctx context.Context, ms *dstate.MemberState, cmd *models.RoleCommand) (gaveRole bool, err error)

func CanAssignRoleCmdTo

func CanAssignRoleCmdTo(r *models.RoleCommand, memberRoles []int64) error

func CanRole added in v1.7.0

func CanRole(ctx context.Context, ms *dstate.MemberState, cmd *models.RoleCommand) (can bool, err error)

func CheckIgnoredRoles

func CheckIgnoredRoles(ignore []int64, has []int64) error

func CheckRequiredRoles

func CheckRequiredRoles(requireOneOf []int64, has []int64) bool

func CheckToggleRole added in v1.7.0

func CheckToggleRole(ctx context.Context, ms *dstate.MemberState, cmd *models.RoleCommand) (gaveRole bool, err error)

AssignRole attempts to assign the given role command, returns an error if the role does not exists or is unable to receie said role

func CmdFuncListCommands

func CmdFuncListCommands(parsed *dcmd.Data) (interface{}, error)

func CmdFuncRole

func CmdFuncRole(parsed *dcmd.Data) (interface{}, error)

func ContinueRoleMenuSetup

func ContinueRoleMenuSetup(ctx context.Context, rm *models.RoleMenu, emoji *discordgo.Emoji, userID int64) (resp string, err error)

func FindRolemenuFull added in v1.8.0

func FindRolemenuFull(ctx context.Context, mID int64, guildID int64) (*models.RoleMenu, error)

func FindToggleRole added in v1.7.0

func FindToggleRole(ctx context.Context, ms *dstate.MemberState, name string) (gaveRole bool, err error)

func GetAllRoleCommandsSorted

func GetAllRoleCommandsSorted(ctx context.Context, guildID int64) (groups []*models.RoleGroup, grouped map[*models.RoleGroup][]*models.RoleCommand, unGrouped []*models.RoleCommand, err error)

func GroupCanRole added in v1.7.0

func GroupCanRole(ctx context.Context, ms *dstate.MemberState, targetRole *models.RoleCommand) (can bool, err error)

func GroupMaybeScheduleRoleRemoval added in v1.13.1

func GroupMaybeScheduleRoleRemoval(ctx context.Context, ms *dstate.MemberState, targetRole *models.RoleCommand) error

func GroupToggleRole added in v1.7.0

func GroupToggleRole(ctx context.Context, ms *dstate.MemberState, targetRole *models.RoleCommand) (gaveRole bool, err error)

AssignRoleToMember attempts to assign the given role command, part of this group to the member

func HandleGetGroup added in v1.4.1

func HandleGetGroup(groupID int64, w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)

func HandleGetIndex added in v1.4.1

func HandleGetIndex(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)

func HandleMoveCommand

func HandleMoveCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleNewCommand

func HandleNewCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleNewGroup

func HandleNewGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleRemoveCommand

func HandleRemoveCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleRemoveGroup

func HandleRemoveGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleUpdateCommand

func HandleUpdateCommand(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)

func HandleUpdateGroup

func HandleUpdateGroup(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)

func HumanizeAssignError

func HumanizeAssignError(guild *dstate.GuildState, err error) (string, error)

func IsRoleCommandError

func IsRoleCommandError(err error) bool

func MemberChooseOption

func MemberChooseOption(ctx context.Context, rm *models.RoleMenu, gs *dstate.GuildState, option *models.RoleMenuOption, userID int64, emoji *discordgo.Emoji, raAdd bool) (resp string, err error)
func MenuReactedNotDone(ctx context.Context, rm *models.RoleMenu, emoji *discordgo.Emoji, userID int64) (resp string, err error)

func NewGroupError

func NewGroupError(msg string, group *models.RoleGroup) error

func NewLmitError

func NewLmitError(msg string, limit int) error

func NewRoleError

func NewRoleError(msg string, role int64) error

func NewSimpleError

func NewSimpleError(format string, args ...interface{}) error

func NextRoleMenuSetupStep

func NextRoleMenuSetupStep(ctx context.Context, rm *models.RoleMenu, first bool) (resp string, err error)

func OptionsLessFunc added in v1.8.0

func OptionsLessFunc(slice []*models.RoleMenuOption) func(int, int) bool

func RegisterPlugin

func RegisterPlugin()

func RemoveRole added in v1.7.0

func RemoveRole(ctx context.Context, ms *dstate.MemberState, cmd *models.RoleCommand) (removedRole bool, err error)

func RoleCommandsLessFunc

func RoleCommandsLessFunc(slice []*models.RoleCommand) func(int, int) bool

func StrFlags added in v1.8.0

func StrFlags(rm *models.RoleMenu) string

func StringCommands

func StringCommands(cmds []*models.RoleCommand) string

StringCommands pretty formats a bunch of commands into a string

func ToggleRole

func ToggleRole(ms *dstate.MemberState, role int64) (gaveRole bool, err error)

ToggleRole toggles the role of a guildmember, adding it if the member does not have the role and removing it if they do

func UpdateMenu

func UpdateMenu(parsed *dcmd.Data, menu *models.RoleMenu) (interface{}, error)

func UpdateRoleMenuMessage

func UpdateRoleMenuMessage(ctx context.Context, rm *models.RoleMenu) error

Types

type FormCommand

type FormCommand struct {
	ID           int64
	Name         string `valid:",1,100,trimspace"`
	Role         int64  `valid:"role,false"`
	Group        int64
	RequireRoles []int64 `valid:"role,true"`
	IgnoreRoles  []int64 `valid:"role,true"`
}

type FormGroup

type FormGroup struct {
	ID           int64
	Name         string  `valid:",1,100,trimspace"`
	RequireRoles []int64 `valid:"role,true"`
	IgnoreRoles  []int64 `valid:"role,true"`

	Mode int

	MultipleMax int
	MultipleMin int

	SingleAutoToggleOff   bool
	SingleRequireOne      bool
	TemporaryRoleDuration int `valid:"0,1440"`
}

type GroupError

type GroupError struct {
	Group   *models.RoleGroup
	Message string
}

func (*GroupError) Error

func (r *GroupError) Error() string

type LmitError

type LmitError struct {
	Limit   int
	Message string
}

func (*LmitError) Error

func (r *LmitError) Error() string

type Plugin

type Plugin struct{}

func (*Plugin) AddCommands added in v1.4.1

func (p *Plugin) AddCommands()

func (*Plugin) BotInit added in v1.4.1

func (p *Plugin) BotInit()

func (*Plugin) InitWeb

func (p *Plugin) InitWeb()

func (*Plugin) LoadServerHomeWidget added in v1.17.0

func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func (*Plugin) PluginInfo added in v1.17.0

func (p *Plugin) PluginInfo() *common.PluginInfo

type RoleError

type RoleError struct {
	Role    int64
	Message string
}

func (*RoleError) Error

func (r *RoleError) Error() string

func (*RoleError) PrettyError

func (r *RoleError) PrettyError(roles []*discordgo.Role) string

Uses the role name from one of the passed roles with matching id instead of the id

type ScheduledMemberRoleRemoveData added in v1.13.1

type ScheduledMemberRoleRemoveData struct {
	GuildID int64 `json:"guild_id"`
	GroupID int64 `json:"group_id"`
	UserID  int64 `json:"user_id"`
	RoleID  int64 `json:"role_id"`
}

type SimpleError

type SimpleError string

Just a simple type but distinguishable from errors.Error

func (SimpleError) Error

func (s SimpleError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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