commands

command module
v0.0.0-...-70f5dd5 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: MIT Imports: 6 Imported by: 0

README

Slightly more advanced example

A slightly more advanced example that reads a TOML config file (with very basic validation), and has a command system where you can add commands to a list and avoids us having to repeat ourselves with triggers.

!help will return all commands added, and tell the user the prefix for them (for example "!"). !help will return the help text provided when you add the command, like this

Example command to add
	cmdList.AddCommand(command.Command{
		Name:        "cve", // Trigger word
		Description: "Fetches information about the CVE number from http://cve.circl.lu/", // Description
		Usage:       "!cve CVE-2017-7494", // Usage example
		Run:         core.GetCVE, // Function or method to run when it triggers (gets passed everything after the command word as a slice)
	})

The function signature for the "Run" function for commands
// Func represents the Go function that will be executed when a command triggers
type Func func(m *hbot.Message, args []string)

It's very basic, but it works pretty well. It could easily be expanded to do more validation (for example require N arguments) that we could check in the "Process"-method, but I just do that in the individual commands and it has worked just fine.

Run this example with go run main.go -config dev.toml

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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