botReactions

package
v0.0.0-...-fab16b2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: MIT Imports: 21 Imported by: 0

README

Bot Reactions

Hi! It's easy to implement simple bot reactions! We have a lovely dispatcher to take care of the gory details as long as your code conforms to the following example:

package botReactions

import (
	"github.com/bwmarrin/discordgo"
)

/* // A bot reaction implements the following interface
type BotReaction interface {
	Help() string
	HelpDetail(*discordgo.Message) string
	Reaction(message *discordgo.Message, author *discordgo.Member) Reaction
}
*/

type ping struct {  
	Trigger string
}

// This should be a single line without \n breaks, it appears in !help
func (p *ping) Help() string {
	return "Pong!"
}

// This is detailed help and it's supposed to be invoked when people do !help <trigger>
func (p *ping) HelpDetail() string {
	return "Ima ping pong ball!"
}

// The actual reaction, the full message content is available in m.Content
// The returned reaction is sent to the channel where the trigger was seen
func (p *ping) Reaction(m *discordgo.Message, a *discordgo.Member, mType string) Reaction {
	// mType can be CREATE, UPDATE, or DELETE (of messages on Discord) at the moment
	// see botReactions.go for the full struct definition of Reaction
	return Reaction{Text: "Pong!"}
}

// Here's where you add your 'trigger' and register your reaction with the dispatcher
func init() {
	_ping := &ping{
		Trigger: "ping", // Yes, it's "ping" and NOT "!ping".
	}
	addReaction(_ping.Trigger, "CREATE", _ping) // the second argument is mType
}

Oh, there's a special wildcard trigger * for which reactions are ignored on channels (they still work on direct messages). Those are intended for things that like to log and process all incoming messages (e.g. - logger.go).

Have a look at the other reactions for more complex examples!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsDirectory = map[string]string{
	"Africa":    "Johannesburg",
	"America":   "Chicago",
	"Asia":      "Shanghai",
	"Australia": "Sydney",
	"Europe":    "Zurich",
}

Functions

func GenHelp

func GenHelp(helpDetail string) string

GenHelp generates help text for all defined bot reactions

func GetReactions

func GetReactions(message *discordgo.Message, author *discordgo.Member, mType string, gTrigger string, gTIndex int) []taggedReaction

GetReactions gets all bot reactions for the supplied message

Types

type BotReaction

type BotReaction interface {
	Help() string
	HelpDetail() string
	Reaction(message *discordgo.Message, author *discordgo.Member, mType string) Reaction
}

BotReaction interface is expected by the dispatcher to process message triggers

type Reaction

type Reaction struct {
	Timer *time.Duration
	Text  string
}

Reaction represents the bot's reaction on a given trigger string, a non-nil Timer can be used for delayed (re)execution

Jump to

Keyboard shortcuts

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