Documentation
¶
Index ¶
- Variables
- func AutoCompleteHandler(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func CommandEventsHandler(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func GetCommandHandler(lcm *common.LifeCycleManager, db *database.Database, l *log.Logger) func(s *discordgo.Session, i *discordgo.InteractionCreate)
- func GetEmojiID(emoji string) string
- func HandleEventCreate(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func HandleEventDelete(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func HandleEventDetails(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func HandleEventListing(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func HandleEventPurge(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func HandleEventUpdate(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func HelpHandler(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func InternalError(s *discordgo.Session, i *discordgo.InteractionCreate, log *log.Logger) *discordgo.Message
- func RegisterGlobalCommands(s *discordgo.Session, cfg common.ConfigDiscord) error
- func RoleReactCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func TryGetUsername(i *discordgo.InteractionCreate) string
- func TryRespond(s *discordgo.Session, i *discordgo.InteractionCreate, response string, ...) *discordgo.Message
- type Command
- type Handler
Constants ¶
This section is empty.
Variables ¶
View Source
var CommandChainRoles = Command{ Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger) { data := i.ApplicationCommandData() baseRoleID := "" newRoles := make([]*discordgo.Role, 0) for _, v := range data.Options { if v == nil { continue } if v.Name == baseRoleName { baseRoleID = v.RoleValue(s, i.GuildID).ID continue } newRoles = append(newRoles, v.RoleValue(s, i.GuildID)) } roleSetFailure := false var highestID big.Int for { members, err := s.GuildMembers(i.GuildID, highestID.String(), 1000) if err != nil { log.Printf("%s: failed to list guild members: %s", i.ID, err) InternalError(s, i, log) return } log.Printf("Found %d users... processing...", len(members)) for _, v := range members { if v == nil { log.Printf("%s: nil guild member in query") continue } var id big.Int id.SetString(v.User.ID, 10) if id.Cmp(&highestID) == 1 { highestID = id } foundRole := false for _, v := range v.Roles { if v == baseRoleID { foundRole = true break } } if foundRole { log.Printf("%s: Assigning new roles to user %s", i.ID, v.User.String()) for _, newRole := range newRoles { err = s.GuildMemberRoleAdd(i.GuildID, v.User.ID, newRole.ID) if err != nil { roleSetFailure = true log.Printf("%s: role addition failed (user: %s role: %s): %err", i.ID, v.User.String(), newRole.Name, err) } } } } if len(members) < 1000 { break } } if !roleSetFailure { log.Printf("%s: Assigned all new roles to users.", i.ID) TryRespond(s, i, "All new roles were assigned.", log) } else { log.Printf("%s: Some roles failed to assign.", i.ID) TryRespond(s, i, fmt.Sprintf("Some roles failed to assign. Contact bot owner with %s.", i.ID), log) } }, DgCommand: &discordgo.ApplicationCommand{ Name: "chainroles", Description: "Assign multiple roles to members with existing roles", DefaultMemberPermissions: common.Pointer(int64(discordgo.PermissionManageRoles)), DMPermission: common.Pointer(false), Options: func() []*discordgo.ApplicationCommandOption { out := make([]*discordgo.ApplicationCommandOption, 24) for k := range out { out[k] = &discordgo.ApplicationCommandOption{ Type: discordgo.ApplicationCommandOptionRole, Name: fmt.Sprintf("new_role%d", k), Description: "The initial required role to receive additional roles.", Required: false, } } required := []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionRole, Name: baseRoleName, Description: "The initial required role to receive additional roles.", Required: true, }, } return append(required, out...) }(), }, HelpText: chainRolesHelptext, }
View Source
var CommandEvents = Command{ Handler: CommandEventsHandler, AutoCompleteHandlers: map[string]interface{}{ "create": map[string]interface{}{ "frequency": autocomplete.CreateEventFrequency, "initial_event": autocomplete.CreateEventInitialEvent, }, "details": map[string]interface{}{ "series": autocomplete.EventGetAvailableSeries, }, "delete": map[string]interface{}{ "series": autocomplete.EventGetAvailableSeries, }, "update": map[string]interface{}{ "series": autocomplete.EventGetAvailableSeries, "frequency": autocomplete.CreateEventFrequency, }, }, DgCommand: &discordgo.ApplicationCommand{ Type: discordgo.ChatApplicationCommand, Name: "events", Description: "Wrangle auto-scheduled events.", DefaultMemberPermissions: common.Pointer(int64(discordgo.PermissionManageEvents)), Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "create", Description: "Create a new auto-scheduled event. Can clone existing events.", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "initial_event", Description: "Initial event. Autocorrect presents the 25 soonest non-series events.", Required: true, Autocomplete: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "frequency", Description: "How frequently the event should exist", Required: true, Autocomplete: true, }, }, }, { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "details", Description: "Check frequency of auto-scheduled events.", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "series", Description: "Target series. Autocorrect prevents the 25 series with the soonest events.", Required: true, Autocomplete: true, }, }, }, { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "list", Description: "List auto-scheduled events.", }, { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "delete", Description: "Delete auto-scheduled events.", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "series", Description: "Target series. Autocorrect prevents the 25 series with the soonest events.", Required: true, Autocomplete: true, }, { Type: discordgo.ApplicationCommandOptionBoolean, Name: "delete_finale", Description: "Delete the final event? (default: true)", Required: false, }, }, }, { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "update", Description: "Adjust the frequency of an event.", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "series", Description: "Target series. Autocorrect prevents the 25 series with the soonest events.", Required: true, Autocomplete: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "frequency", Description: "How frequently the event should exist", Required: true, Autocomplete: true, }, }, }, { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "purge", Description: "Purge the database of events that do not match", }, }, }, HelpText: EventsHelptext, }
View Source
var CommandSource = Command{ Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger) { TryRespond(s, i, "My source code is available at: https://github.com/Riven-Spell/hydaelyn", log) }, DgCommand: &discordgo.ApplicationCommand{ Name: "source", Description: "Links to the source code.", Type: discordgo.ChatApplicationCommand, }, HelpText: "Links to the source code.", }
View Source
var EventsHelptext string
View Source
var GlobalCommands = map[string]Command{ RoleReactCommand.DgCommand.Name: RoleReactCommand, CommandChainRoles.DgCommand.Name: CommandChainRoles, CommandSource.DgCommand.Name: CommandSource, CommandEvents.DgCommand.Name: CommandEvents, }
View Source
var HelpCommand = Command{ Handler: HelpHandler, DgCommand: &discordgo.ApplicationCommand{ Version: "1.0", Type: discordgo.ChatApplicationCommand, Name: "help", DMPermission: common.Pointer(true), Description: "List commands & information", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "command", Description: "Target command to view", Required: false, }, }, }, HelpText: helpHelptext, }
View Source
var RoleReactCommand = Command{ Handler: RoleReactCommandHandler, DgCommand: &discordgo.ApplicationCommand{ Type: discordgo.ChatApplicationCommand, Name: "rolereact", DMPermission: common.Pointer(false), Description: "Creates a role react message for unprivileged users. /setup required.", DefaultMemberPermissions: common.Pointer(int64(discordgo.PermissionManageRoles)), Options: func() []*discordgo.ApplicationCommandOption { out := make([]*discordgo.ApplicationCommandOption, 24) for k, _ := range out { out[k] = &discordgo.ApplicationCommandOption{ Type: discordgo.ApplicationCommandOptionString, Name: fmt.Sprintf("rolereact%d", k), Description: "Role react format: `emoji:roleid,roleid...`", Required: false, } } textOption := &discordgo.ApplicationCommandOption{ Type: discordgo.ApplicationCommandOptionString, Name: "description", Description: "Describe this role react message!", Required: true, } out = append([]*discordgo.ApplicationCommandOption{textOption}, out...) return out }(), }, HelpText: roleReactHelptext, }
Functions ¶
func AutoCompleteHandler ¶
func AutoCompleteHandler(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, l *log.Logger)
func CommandEventsHandler ¶
func CommandEventsHandler(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func GetCommandHandler ¶
func GetCommandHandler(lcm *common.LifeCycleManager, db *database.Database, l *log.Logger) func(s *discordgo.Session, i *discordgo.InteractionCreate)
func GetEmojiID ¶
func HandleEventCreate ¶
func HandleEventCreate(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func HandleEventDelete ¶
func HandleEventDelete(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func HandleEventDetails ¶
func HandleEventDetails(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func HandleEventListing ¶
func HandleEventListing(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func HandleEventPurge ¶
func HandleEventPurge(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func HandleEventUpdate ¶
func HandleEventUpdate(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func HelpHandler ¶
func HelpHandler(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func InternalError ¶
func RegisterGlobalCommands ¶
func RegisterGlobalCommands(s *discordgo.Session, cfg common.ConfigDiscord) error
func RoleReactCommandHandler ¶
func RoleReactCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate, lcm *common.LifeCycleManager, db *database.Database, log *log.Logger)
func TryGetUsername ¶
func TryGetUsername(i *discordgo.InteractionCreate) string
Types ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.