handler

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: GPL-3.0 Imports: 7 Imported by: 2

Documentation

Overview

Copyright (C) 2022-2023  sabafly

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutocompleteHandler

type AutocompleteHandler func(event *events.AutocompleteInteractionCreate) error

type Check

type Check[T any] func(ctx T) bool

func CheckAllOf

func CheckAllOf[T any](checks ...Check[T]) Check[T]

func CheckAnyOf

func CheckAnyOf[T any](checks ...Check[T]) Check[T]

func (Check[T]) And

func (c Check[T]) And(check Check[T]) Check[T]

func (Check[T]) Or

func (c Check[T]) Or(check Check[T]) Check[T]

type Command

type Command struct {
	Create               discord.ApplicationCommandCreate
	Check                Check[*events.ApplicationCommandInteractionCreate]
	AutocompleteCheck    Check[*events.AutocompleteInteractionCreate]
	CommandHandlers      map[string]CommandHandler
	AutocompleteHandlers map[string]AutocompleteHandler

	DevOnly bool
}

type CommandHandler

type CommandHandler func(event *events.ApplicationCommandInteractionCreate) error

type Component

type Component struct {
	Name    string
	Check   Check[*events.ComponentInteractionCreate]
	Handler map[string]ComponentHandler
}

type ComponentHandler

type ComponentHandler func(event *events.ComponentInteractionCreate) error

type GuildMemberJoinHandler

type GuildMemberJoinHandler func(event *events.GuildMemberJoin) error

type GuildMemberLeaveHandler

type GuildMemberLeaveHandler func(event *events.GuildMemberLeave) error

type Handler

type Handler struct {
	Logger log.Logger

	Commands    map[string]Command
	Components  map[string]Component
	Modals      map[string]Modal
	Message     map[uuid.UUID]Message
	Ready       []func(*events.Ready)
	MemberJoin  map[uuid.UUID]MemberJoin
	MemberLeave map[uuid.UUID]MemberLeave

	ExcludeID  map[snowflake.ID]struct{}
	DevGuildID []snowflake.ID
	IsDebug    bool
}

func New

func New(logger log.Logger) *Handler

func (*Handler) AddCommands

func (h *Handler) AddCommands(commands ...Command)

func (*Handler) AddComponent

func (h *Handler) AddComponent(component Component) func()

func (*Handler) AddComponents

func (h *Handler) AddComponents(components ...Component)

func (*Handler) AddExclude

func (h *Handler) AddExclude(ids ...snowflake.ID)

func (*Handler) AddMemberJoin

func (h *Handler) AddMemberJoin(memberJoin MemberJoin) func()

func (*Handler) AddMemberJoins

func (h *Handler) AddMemberJoins(memberJoins ...MemberJoin)

func (*Handler) AddMemberLeave

func (h *Handler) AddMemberLeave(memberLeave MemberLeave) func()

func (*Handler) AddMemberLeaves

func (h *Handler) AddMemberLeaves(memberLeaves ...MemberLeave)

func (*Handler) AddMessage

func (h *Handler) AddMessage(message Message) func()

func (*Handler) AddModals

func (h *Handler) AddModals(modals ...Modal)

func (*Handler) AddReady

func (h *Handler) AddReady(ready func(*events.Ready))

func (*Handler) OnEvent

func (h *Handler) OnEvent(event bot.Event)

func (*Handler) SyncCommands

func (h *Handler) SyncCommands(client bot.Client, guildIDs ...snowflake.ID)

type MemberJoin

type MemberJoin struct {
	UUID    uuid.UUID
	Check   Check[*events.GuildMemberJoin]
	Handler GuildMemberJoinHandler
}

type MemberLeave

type MemberLeave struct {
	UUID    uuid.UUID
	Check   Check[*events.GuildMemberLeave]
	Handler GuildMemberLeaveHandler
}

type Message

type Message struct {
	UUID      uuid.UUID
	ChannelID snowflake.ID
	AuthorID  *snowflake.ID
	Check     Check[*events.MessageCreate]
	Handler   MessageHandler
}

type MessageHandler

type MessageHandler func(event *events.MessageCreate) error
type Modal struct {
	Name    string
	Check   Check[*events.ModalSubmitInteractionCreate]
	Handler map[string]ModalHandler
}

type ModalHandler

type ModalHandler func(event *events.ModalSubmitInteractionCreate) error

Jump to

Keyboard shortcuts

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