godiscordutil

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 6 Imported by: 0

README

godiscordutil

Package MaxwellBanks/godiscordutil provides a set of utility functions that may be helpful for Discord bots.

Datatypes

Argparser
type BotFunc func(*sql.DB, []string) string

Abstract type for custom bot functions mapped to in CommandToFunc.

Tablegen
type RawTable [][]string

Two dimensional list containing raw data to be loaded into ASCII table.

Exposed Functions

Argparser
IsCommand(message string, flag string) bool

Checks for the activation flag in front of the message.

IsOwnMessage(s *discordgo.Session, m *discordgo.MessageCreate) bool

Prevents recursion by blacklisting self-responses.

ParseMessage(message string, flag string) (command string, args []string)

Scrubs flag from message and splits the message into a command and a list of arguments.

CommandToFunc(command string, arguments[string], cmdMap map[string]BotFunc, db *sql.DB) string

Takes in command and arguments and returns the value of the function mapped to the command.

Tablegen
GenTable(data RawTable) string

Converts two dimensional list of strings to ASCII table suitable for Discord chat displays.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandToFunc

func CommandToFunc(
	command string,
	arguments []string,
	cmdMap map[string]BotFunc,
	db *sql.DB,
) string

CommandToFunc passes command and argument parameters through Map parameter, returning the resulting function from the map

func GenTable

func GenTable(data RawTable) string

GenTable generates simple ascii table as string

func IsCommand

func IsCommand(message string, flag string) bool

IsCommand verifies that a given message is meant for this bot

func IsOwnMessage

func IsOwnMessage(
	s *discordgo.Session,
	m *discordgo.MessageCreate,
) bool

IsOwnMessage verifies that a given message is not from this bot

func ParseMessage

func ParseMessage(
	message string,
	flag string,
) (command string, args []string)

ParseMessage splits message into command (scrubbed of bot flag) And list of arguments

Types

type BotFunc

type BotFunc func(*sql.DB, []string) string

BotFunc is an abstract type for functions that serve a Discord bot

type RawTable

type RawTable [][]string

RawTable contains the data to be inserted into ascii table

Jump to

Keyboard shortcuts

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