commands package - github.com/McCune1224/oomdroid/internal/commands - Go Packages

commands

package
v0.0.0-...-5f4cf3e Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Ping = SlashCommand{
	Feature: dg.ApplicationCommand{
		Name:        "ping",
		Description: "Responds with 'Pong!'",
	},
	Handler: func(s *dg.Session, i *dg.InteractionCreate) {
		s.InteractionRespond(i.Interaction, &dg.InteractionResponse{
			Type: dg.InteractionResponseChannelMessageWithSource,
			Data: &dg.InteractionResponseData{
				Content: "Pong!",
			},
		})
	},
}
View Source
var Rps = SlashCommand{
	Feature: dg.ApplicationCommand{
		Name:        "rps",
		Description: "Play Rock Paper Scissors!",
		Options: []*dg.ApplicationCommandOption{
			{
				Type:        dg.ApplicationCommandOptionString,
				Name:        "selection",
				Description: "Input either Rock, Paper, or Scissors",
				Required:    true,
			},
		},
	},

	Handler: func(s *dg.Session, i *dg.InteractionCreate) {

		playeSelected := i.ApplicationCommandData().Options[0].StringValue()

		rand.Seed(time.Now().UnixNano())
		Options := []string{"rock", "paper", "scissors"}
		botSelected := Options[rand.Intn(3)]

		var winner string
		botResponse := fmt.Sprintf("You Selected *%s*, I selected *%s*\n", playeSelected, botSelected)
		switch isPlayerWinner(botSelected, playeSelected) {
		case 1:
			winner = "**You Win!**"
		case 0:
			winner = "**You Lose!**"
		case -1:
			winner = "**Draw!**"
		case -2:
			winner = fmt.Sprintf("**No One Wins. Invalid option '%s'.**", playeSelected)
			botResponse = ""
		}

		botResponse += fmt.Sprintf(winner)
		s.InteractionRespond(i.Interaction, &dg.InteractionResponse{
			Type: dg.InteractionResponseChannelMessageWithSource,
			Data: &dg.InteractionResponseData{
				Content: botResponse,
			},
		})

	},
}

Functions

func Foobar

func Foobar(s *dg.Session, i *dg.InteractionCreate)

Types

type SCM

type SCM struct {
	SlashCommands map[string]SlashCommand
}

Slash Command Manager, binds all commands to a map, the command name now is used to reference a SlashCommand

func NewSCM

func NewSCM() *SCM

Create New Instance of a Slash Command manager

func (SCM) AddCommand

func (scm SCM) AddCommand(sc SlashCommand)

func (SCM) RegisterCommands

func (scm SCM) RegisterCommands(session *dg.Session) int

Returns a tally of successful applications created for the session

type SlashCommand

type SlashCommand struct {
	//to avoid naming stuttering (SlashCommand.Command....) discordgo.ApplicationCommand is aliased to "Feature"
	Feature dg.ApplicationCommand

	//Slash Command Handler aka how the command should operate
	Handler func(s *dg.Session, i *dg.InteractionCreate)
}

Wrapper Structure to couple A ApplicationCommand with a dedicated Handler

Jump to

Keyboard shortcuts

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