minidis

package module
v0.0.0-...-ed58325 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 6 Imported by: 0

README

minidis

Simple slash commands handler for discordgo

This just wraps functions and is based from the examples provided by discordgo and this is made in order to make its api more readable and easier to maintain.

Install

This is usable for simple and basic commands but is still missing some of other features.

go get -u github.com/TheBoringDude/minidis

CLI

You can also use a simple boilerplate generator to kickstart a new discord bot project

go install github.com/TheBoringDude/minidis/cli/minidis@latest

Usage

package main

import (
    "fmt"
    "log"
    "os"

    "github.com/TheBoringDude/minidis"
    "github.com/bwmarrin/discordgo"
)

func main() {
    bot := minidis.New(os.Getenv("TOKEN"))

    // set intents
    bot.SetIntents(discordgo.IntentsGuilds | discordgo.IntentsGuildMessages)

    bot.OnReady(func(s *discordgo.Session, i *discordgo.Ready) {
        log.Println("Bot is ready!")
    })

    // simple command
    bot.AddCommand(minidis.SlashCommandProps{
        Command:     "ping",
        Description: "Simple ping command.",
        Execute: func(c *minidis.SlashContext) error {
            return c.ReplyString(fmt.Sprintf("Hello **%s**, pong?", c.Author.Username))
        },
    })

    bot.Run()
}

More examples...

© 2022 | TheBoringDude

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(bot *Minidis) error

Execute the bot. It is similar to `Run()` function of `Minidis` struct.

Types

type ComponentContext

type ComponentContext struct {
	Data discordgo.MessageComponentInteractionData
}

type ComponentInteractionProps

type ComponentInteractionProps struct {
	ID      string
	Execute func(s *SlashContext, c *ComponentContext) error
}

type CustomHandlers

type CustomHandlers struct {
	// contains filtered or unexported fields
}

type EditProps

type EditProps struct {
	Content         string
	Embeds          []*discordgo.MessageEmbed
	Components      []discordgo.MessageComponent
	Attachments     []*discordgo.File
	AllowedMentions *discordgo.MessageAllowedMentions
}

type FollowupContext

type FollowupContext struct {
	Interaction *discordgo.Interaction
	Session     *discordgo.Session
	AppID       string
	// contains filtered or unexported fields
}

func (*FollowupContext) Delete

func (f *FollowupContext) Delete() error

Delete deletes the followup message.

func (*FollowupContext) Edit

func (f *FollowupContext) Edit(content string) error

Edit edits the followup message.

func (*FollowupContext) EditC

func (f *FollowupContext) EditC(reply EditProps) error

EditC is the full edit interaction component structure.

type FollowupProps

type FollowupProps ReplyProps

type MessageCommandContext

type MessageCommandContext struct {
	Interaction *discordgo.Interaction
	Session     *discordgo.Session
	Message     *discordgo.Message
}

func (*MessageCommandContext) ReplyC

func (m *MessageCommandContext) ReplyC(reply ReplyProps) error

type MessageCommandProps

type MessageCommandProps struct {
	Name    string
	Execute func(c *MessageCommandContext) error
}

type Minidis

type Minidis struct {
	Token string
	AppID string
	// contains filtered or unexported fields
}

func New

func New(token string) *Minidis

Create a new Minidis instance.

func (*Minidis) AddCommand

func (m *Minidis) AddCommand(cmd *SlashCommandProps) *SlashCommandProps

AddCommand adds a new slash command.

func (*Minidis) AddComponentHandler

func (m *Minidis) AddComponentHandler(cpi *ComponentInteractionProps)

AddComponentHandler adds a function handler once the `id` is called.

func (*Minidis) AddCustomComponentHandler

func (m *Minidis) AddCustomComponentHandler(handler func(s *SlashContext, c *ComponentContext) error)

AddCustomComponentHandler is a fallback handler for the AddComponentHandler. This is usefull if you have custom component ids that are changing or unique. This is called if the component's id has no handler set.

func (*Minidis) AddCustomModalSubmitHandler

func (m *Minidis) AddCustomModalSubmitHandler(handler func(s *SlashContext, c *ModalSubmitContext) error)

AddCustomModalSubmitHandler is a fallback handler for AddModalSubmitHandler. This is useful if you have custom mod ids that are changing or unique. This is called if the component's id has no handler set.

func (*Minidis) AddMessageCommand

func (m *Minidis) AddMessageCommand(cmd *MessageCommandProps)

AddMessageCommand adds a new message command.

func (*Minidis) AddModalSubmitHandler

func (m *Minidis) AddModalSubmitHandler(mi *ModalInteractionProps)

AddModalSubmitHandler adds a new modal submit interaction handler for a specific custom id.

func (*Minidis) AddUserCommand

func (m *Minidis) AddUserCommand(cmd *UserCommandProps)

AddUserCommand adds a new user command.

func (*Minidis) ClearCommands

func (m *Minidis) ClearCommands() error

ClearCommands removes the application commands from the guild. If there are no guilds specified using `SyncToGuilds()`, global commands will be removed.

func (*Minidis) NewComponentContext

func (m *Minidis) NewComponentContext(event *discordgo.Interaction) *ComponentContext

func (*Minidis) NewModalContext

func (*Minidis) NewSlashContext

func (m *Minidis) NewSlashContext(session *discordgo.Session, inter *discordgo.Interaction, isSlash bool) *SlashContext

Creates a new slash context for slash command interaction. This is called internally.

func (*Minidis) OnBeforeStart

func (m *Minidis) OnBeforeStart(v func(s *discordgo.Session))

OnBeforeStart adds a custom function that will be called before syncing the application commands and running the bot.

func (*Minidis) OnClose

func (m *Minidis) OnClose(v func(s *discordgo.Session))

OnClose adds a custom function that will be called when exit is called.

func (*Minidis) OnReady

func (m *Minidis) OnReady(v func(s *discordgo.Session, i *discordgo.Ready))

OnReady adds a wrapper handler that executes once the bot is ready.

func (*Minidis) RegisterCommands

func (m *Minidis) RegisterCommands(cmds ...*SlashCommandProps)

RegisterCommands is used for adding multiple already defined commands. It does not return anything. It just wrap the `AddCommand` function.

func (*Minidis) Run

func (m *Minidis) Run() error

Run executes the command handler.

func (*Minidis) SetIntents

func (m *Minidis) SetIntents(intents discordgo.Intent)

SetIntents sets the required or used intents by the bot.

func (*Minidis) SyncToGuilds

func (m *Minidis) SyncToGuilds(guildIDs ...string)

Sync the commands to these guilds.

type ModalInteractionProps

type ModalInteractionProps struct {
	ID      string
	Execute func(s *SlashContext, c *ModalSubmitContext) error
}

type ModalSubmitContext

type ModalSubmitContext struct {
	Data discordgo.ModalSubmitInteractionData
}

type ReplyModalProps

type ReplyModalProps struct {
	Title      string
	CustomID   string
	Components []discordgo.MessageComponent
}

type ReplyProps

type ReplyProps struct {
	Content         string
	Embeds          []*discordgo.MessageEmbed
	Components      []discordgo.MessageComponent
	IsEphemeral     bool
	Attachments     []*discordgo.File
	AllowedMentions *discordgo.MessageAllowedMentions
}

type SlashCommandProps

type SlashCommandProps struct {
	Name        string // Name of the command
	Description string // Description of the command

	NameLocalizations        *map[discordgo.Locale]string
	DescriptionLocalizations *map[discordgo.Locale]string

	DefaultMemberPermissions int64
	DmPermission             bool

	Options []*discordgo.ApplicationCommandOption
	Execute func(c *SlashContext) error
	// contains filtered or unexported fields
}

func (*SlashCommandProps) AddSubcommand

func (s *SlashCommandProps) AddSubcommand(cmd *SlashSubcommandProps)

AddSubcommand adds a new sub command for the parent command. Note: this will make your parent command not execute.

func (*SlashCommandProps) AddSubcommandGroup

AddSubcommand adds a new group for sub commands for the parent command. Note: this will make your parent command not execute.

type SlashContext

type SlashContext struct {
	Interaction *discordgo.Interaction
	Session     *discordgo.Session

	AppID  string
	Author *discordgo.User
	Member *discordgo.Member // only filled when called in a guild
	IsDM   bool
	Bot    *discordgo.User // this is the bot user

	Id          string
	GuildId     string
	GuildLocale *discordgo.Locale
	Local       discordgo.Locale
	ChannelId   string

	// NOTE: this is empty if component is called
	Options map[string]*discordgo.ApplicationCommandInteractionDataOption
}

func (*SlashContext) DeferReply

func (s *SlashContext) DeferReply(ephemeral bool) error

DeferReply sends an interaction response where the user sees a loading state. After sending, 15 minutes is given to complete your command's tasks. This is considered as an interaction response, so you should not use the `Reply*` functions after. - `ephemeral` -> only the user sees the loading state

func (*SlashContext) Delete

func (s *SlashContext) Delete() error

Delete deletes the interaction response.

func (*SlashContext) Edit

func (s *SlashContext) Edit(content string) error

Edit edis the interaction response.

func (*SlashContext) EditC

func (s *SlashContext) EditC(reply EditProps) error

EditC is the full edit interaction component structure.

func (*SlashContext) Followup

func (s *SlashContext) Followup(content string) (*FollowupContext, error)

Followup creates a followup message to the interaction response.

func (*SlashContext) FollowupC

func (s *SlashContext) FollowupC(reply FollowupProps) (*FollowupContext, error)

FollowupC is the full followup component structure.

func (*SlashContext) Reply

func (s *SlashContext) Reply(content string, embeds ...*discordgo.MessageEmbed) error

Reply sends a string content with embeds if there is.

func (*SlashContext) ReplyC

func (s *SlashContext) ReplyC(reply ReplyProps) error

ReplyC is the full reply component structure.

func (*SlashContext) ReplyEphemeral

func (s *SlashContext) ReplyEphemeral(content string, embeds ...*discordgo.MessageEmbed) error

Reply sends a string content with embeds if there is. `Ephemeral` - the response message will only be seen by the user who called it.

func (*SlashContext) ReplyModal

func (s *SlashContext) ReplyModal(reply ReplyModalProps) error

ReplyModal returns a modal component as InteractionResponse

func (*SlashContext) ReplyString

func (s *SlashContext) ReplyString(content string) error

SendText sends a string text as interaction response.

type SlashSubcommandGroupProps

type SlashSubcommandGroupProps struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

func (*SlashSubcommandGroupProps) AddSubcommand

func (s *SlashSubcommandGroupProps) AddSubcommand(cmd *SlashSubcommandProps)

AddSubcommand adds a new sub command for the subcommmand group. Note: this will make your parent command not execute.

type SlashSubcommandProps

type SlashSubcommandProps struct {
	Name        string
	Description string
	Options     []*discordgo.ApplicationCommandOption
	Execute     func(c *SlashContext) error
}

type UserCommandContext

type UserCommandContext struct {
	Interaction *discordgo.Interaction
	Session     *discordgo.Session
	Member      *discordgo.Member
	User        *discordgo.User
}

func (*UserCommandContext) ReplyC

func (m *UserCommandContext) ReplyC(reply ReplyProps) error

type UserCommandProps

type UserCommandProps struct {
	Command string
	Execute func(c *UserCommandContext) error
}

Directories

Path Synopsis
cli
example

Jump to

Keyboard shortcuts

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