minidis

package module
v0.0.0-...-9dbe755 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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/World-of-Cryptopups/minidis

Usage

package main

import (
    "fmt"
    "log"
    "os"

    "github.com/World-of-Cryptopups/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 | World of Cryptopups

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 EditProps

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

type FollowupContext

type FollowupContext struct {
	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 Minidis

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

func New

func New(token string) *Minidis

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) NewComponentContext

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

func (*Minidis) NewSlashContext

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

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

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) 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 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 {
	Command     string
	Description string
	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 {
	AppID  string
	Author *discordgo.User
	Member *discordgo.Member // only filled when called in a guild
	IsDM   bool

	// NOTE: this is empty if component is called
	Options map[string]*discordgo.ApplicationCommandInteractionDataOption
	// contains filtered or unexported fields
}

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) ReplyString

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

SendText sends a string text as interaction response.

type SlashSubcommandGroupProps

type SlashSubcommandGroupProps struct {
	Command     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 {
	Command     string
	Description string
	Options     []*discordgo.ApplicationCommandOption
	Execute     func(c *SlashContext) error
}

Directories

Path Synopsis
example
components command
options command
simple command
subcommands command

Jump to

Keyboard shortcuts

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