Go-interactions - Easy slash commands for Arikawa

go-interactions

A library that aims to make dealing with discord's slash commands easy. It is designed for diamondburned/arikawa, and based on the command system from df-mc/dragonfly.

Note

This library is currently not quite ready for production use. There might be bugs, and while I do try to test everything there could always be some edge cases. The library is also not feature complete yet. Currently, there is no way to reliably use this across multiple nodes. Other currently missing features include command parameter options and autocompleted params.

Usage

To use this library you will need to have at least Go 1.18 installed. To use this in your project, simply run the following command:

go get github.com/AndreasHGK/go-interactions

The following code is an example command made using this library, which will greet the user provided as a parameter.

import (
    "fmt"
    "github.com/andreashgk/go-interactions/cmd"
    "time"
)

// Greet is an example command executor. It will greet a user after the delay specified, otherwise send it in one
// second. Parameters can be specified using the fields in the struct.
type Greet struct {
    // The discord api allows you to add up to 25 parameters per executor. These parameters can be any int, float,
    // string or bool type and can also be of type cmd.User, cmd.Channel, cmd.Mentionable, cmd.Role. The description
    // should be included for every parameter like shown here.
    Target cmd.User `description:"The person to greet"`
    
    // Optional parameters can be added like shown for this. A cmd.Optional[] needs to be wrapped around the parameter
    // type. It has a few methods to get the underlying value and to return whether the value was provided. All optional
    // parameters have to be provided after all required parameters.
    Delay cmd.Optional[int] `description:"Whether or not to show the response publicly"`
}

// Run will be called when the command is executed by the player. All parameter values will be set inside the struct,
// and a *cmd.Interaction is passed to allow for getting values such as the sender and has methods to send responses.
func (u Greet) Run(interaction *cmd.Interaction) {
    // Sends a "DeferredMessageInteractionWithSource" response. This indicates that the bot has received the command and
    // a message response will follow within the next 15 minutes.
    followup, err := interaction.DeferResponse()
    if err != nil {
        fmt.Printf("Error sending command response: %s", err.Error())
        return
    }
    
    go func() {
        time.Sleep(time.Duration(u.Delay.GetOrFallback(1)) * time.Second)
        
        // The followup can be used to send followup responses. Currently, these can only be messages. They will show
        // as responses to the original response.
        _, err := followup.Create(cmd.MessageResponse{
            Content: fmt.Sprintf("Hello, <@%v>", u.Target),
        })
        if err != nil {
            fmt.Printf("Error sending followup message: %s", err.Error())
        }
    }()
}

The command will then have to be registered to a command handler. This can be done as follows:

func RegisterCommands(botState *state.State) {
	// Create a new command handler.
	h := cmd.NewHandler(nil).WithCommands(
		cmd.New("greet", "Greet another user.").WithExecutor(Greet{}),
	)
	// Will register the commands to a specific guild. This clears the list of commands that are pending to be
	// registered.
	h.RegisterAllGuild(botState, discord.GuildID(12345))
	// Adds the interaction event handler to the bot.
	h.Listen(botState)
}

This is all that is needed to add your commands!

Owner
Similar Resources

Database testing made easy in Go.

dbtest Database testing made easy in Go. Features Declarative Define the minimum test specification in a YAML-based DSL, then all tests can be generat

Oct 31, 2022

gomonkey is a library to make monkey patching in unit tests easy

gomonkey is a library to make monkey patching in unit tests easy, and the core idea of monkey patching comes from Bouke, you can read this blogpost for an explanation on how it works.

Jan 4, 2023

Discordgo-scm - Slash commands manager for discordgo

discordgo-scm Slash commands manager for discordgo Install go get github.com/eth

Jun 17, 2022

Slack remote terminal - execute commands on remote host using slack slash command

slackRT Slack remote terminal - execute commands on remote host using slack slash command Installation Go to api.slack.com/apps and sign in and create

Jul 12, 2022

Go package exposing a simple interface for executing commands, enabling easy mocking and wrapping of executed commands.

go-runner Go package exposing a simple interface for executing commands, enabling easy mocking and wrapping of executed commands. The Runner interface

Oct 18, 2022

turn a directory into a GUI, slash example of VNC-based GUI

dirgui @rsnous on Jan 11, 2021: "idea: filesystem-GUI adapter, where a directory turns into a form, executable files inside that directory turn into

May 3, 2022

A cutting edge (haha), prototype, object-oriented and highly modular slash command handler for Discordgo.

A cutting edge (haha), prototype, object-oriented and highly modular slash command handler for Discordgo.

ken ⚠️ Disclaimer This package is still in a very early state of development and future updates might include breaking changes to the API until the fi

Dec 12, 2022

Slash command for Slack/Mattermost to post punch lines

Slash command for Slack/Mattermost to post punch lines

Slash command pro milujipraci.cz This project is by its nature dedicated to czech or slovak speaking users, so I suggest you to either learn Czech or

Jan 18, 2022

A Commander for modern Go CLI interactions

A Commander for modern Go CLI interactions

Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files. Cobra is used i

Jan 3, 2023

Record and replay your HTTP interactions for fast, deterministic and accurate tests

go-vcr go-vcr simplifies testing by recording your HTTP interactions and replaying them in future runs in order to provide fast, deterministic and acc

Dec 25, 2022

Sql mock driver for golang to test database interactions

Sql driver mock for Golang sqlmock is a mock library implementing sql/driver. Which has one and only purpose - to simulate any sql driver behavior in

Dec 31, 2022

HTTP mock for Golang: record and replay HTTP/HTTPS interactions for offline testing

govcr A Word Of Warning I'm in the process of partly rewriting govcr to offer better support for cassette mutations. This is necessary because when I

Dec 28, 2022

A Go implementation of Servirtium, a library that helps test interactions with APIs.

Servirtium is a server that serves as a man-in-the-middle: it processes incoming requests, forwards them to a destination API and writes the response into a Markdown file with a special format that is common across all of the implementations of the library.

Jun 16, 2022

A Commander for modern Go CLI interactions

A Commander for modern Go CLI interactions

Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files. Cobra is used i

Dec 6, 2021

An high level discord interactions wrapper, simple, clean, extensible. Based on outgoing webhooks.

corde corde is a discord webhook callback API wrapper. It's nowhere near prod-ready, but it's honestly usable, and it's open to contributions. Be awar

Oct 13, 2022

📡 http interactions server written in golang

📡 http interactions server written in golang

📡 mixtape-bot/kantoku http interactions server written in go publishes all interactions to rabbitmq probably bad because im very new to go ⛓️ usage t

Jan 7, 2023

painless task queue manager for shell commands with an intuitive cli interface (execute shell commands in distributed cloud-native queue manager).

EXEQ DOCS STILL IN PROGRESS. Execute shell commands in queues via cli or http interface. Features Simple intuitive tiny cli app. Modular queue backend

Dec 14, 2022

easy way to distribute commands over ssh.

grapes grapes is lightweight tool designed to distribute commands over ssh with ease. Update (25/04/2019) Handshake validation is now in place in orde

Dec 20, 2022

A golang library about socks5, supports all socks5 commands. That Provides server and client and easy to use. Compatible with socks4 and socks4a.

socks5 This is a Golang implementation of the Socks5 protocol library. To see in this SOCKS Protocol Version 5. This library is also compatible with S

Nov 22, 2022
Comments
  • interaction: Incorrectly checking for a valid guild

    interaction: Incorrectly checking for a valid guild

    https://github.com/AndreasHGK/go-interactions/blob/2600d1cdb7fe709d6fb90a300f5103771b650ea1/cmd/interaction.go#L129

    (Assuming this was intended to be used as DM/Guild differentiation)

    Arikawa internally differentiates DMs and Guilds with the isValid() method on the Snowflake GuildIDs from DMs are set as GuildId(0) even tho NullSnowflake exists (which is the exact opposite: ^GuildId(0)) Example: https://github.com/diamondburned/arikawa/blob/16a408bf3024bb4baa2a8c06fb84a65f0b5736af/state/state.go#L186

Sql mock driver for golang to test database interactions

Sql driver mock for Golang sqlmock is a mock library implementing sql/driver. Which has one and only purpose - to simulate any sql driver behavior in

Dec 31, 2022
HTTP mock for Golang: record and replay HTTP/HTTPS interactions for offline testing

govcr A Word Of Warning I'm in the process of partly rewriting govcr to offer better support for cassette mutations. This is necessary because when I

Dec 28, 2022
A Go implementation of Servirtium, a library that helps test interactions with APIs.

Servirtium is a server that serves as a man-in-the-middle: it processes incoming requests, forwards them to a destination API and writes the response into a Markdown file with a special format that is common across all of the implementations of the library.

Jun 16, 2022
Small program that takes in commands and moves one or more robots around the surface of Mars!

Mars Rover Build and Run the Image Build image from current directory: docker build -t marsrover . Run image interactively: docker run -i marsrover

Jan 2, 2022
Wise-mars-rover - Write a program that takes in commands and moves one or more robots around the surface of Mars

wise-mars-rover Write a program that takes in commands and moves one or more rob

Feb 9, 2022
Expressive end-to-end HTTP API testing made easy in Go

baloo Expressive and versatile end-to-end HTTP API testing made easy in Go (golang), built on top of gentleman HTTP client toolkit. Take a look to the

Dec 13, 2022
Quick and easy expression matching for JSON schemas used in requests and responses

schema schema makes it easier to check if map/array structures match a certain schema. Great for testing JSON API's or validating the format of incomi

Dec 24, 2022
HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

gock Versatile HTTP mocking made easy in Go that works with any net/http based stdlib implementation. Heavily inspired by nock. There is also its Pyth

Jan 4, 2023
Quick and Easy server testing/validation
Quick and Easy server testing/validation

Goss - Quick and Easy server validation Goss in 45 seconds Note: For an even faster way of doing this, see: autoadd Note: For testing docker container

Oct 7, 2022
gostub is a library to make stubbing in unit tests easy

gostub gostub is a library to make stubbing in unit tests easy. Getting started Import the following package: github.com/prashantv/gostub Click here t

Dec 28, 2022