beluga

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

README

Beluga

A fun little chat bot for Discord, inspired from the Narwhal IRC bot. View all available commands in Discord using !help.

Report License

Building

Beluga is a regular Go program using Go modules, so build it how you would any normal Go application.

Installation

Create a Discord bot here. Next, add the bot to your Discord server using this link, replacing the Client ID with your bot's ID:

https://discordapp.com/oauth2/authorize?client_id=<CLIENT_ID>&scope=bot

CLI Usage

./beluga [OPTIONS]

Options:

-c, --configDir - Specify the directory to use for configuration files
-h, --help   - Print the help message

License

Copyright © 2020 Evan Maddock (EbonJaeger)

Beluga is available under the terms of the Apache-2.0 license

Documentation

Index

Constants

View Source
const (
	// PluginsPath is the path where Beluga plugins should
	// be placed
	PluginsPath = "/usr/share/beluga/plugins"
)

Variables

View Source
var ConfigDir string

ConfigDir is the path to all Beluga-related configs

View Source
var Help helpPlugin

Help is our help responder

Log is our WaterLog instance

Session is our Discord session

Functions

func ArrayContains

func ArrayContains(arr []string, element string) bool

ArrayContains checks if a given element is in a string array

func CreateFileIfNotExists

func CreateFileIfNotExists(path string) error

CreateFileIfNotExists creates a new empty file at the given path it the file does not yet exist

func GetUserFromName

func GetUserFromName(s *discordgo.Session, g *discordgo.Guild, t string) *discordgo.User

GetUserFromName gets the Discord user from a mention or username. The username can be only a partial username

func MemberHasPermission

func MemberHasPermission(s *discordgo.Session, guildID string, userID string, perm int) bool

MemberHasPermission checks if a member of a guild has the desired permission

func NewBeluga

func NewBeluga(cliFlags Flags)

NewBeluga creates a new Beluga instance, and connects to Discord

func OnGuildCreate

func OnGuildCreate(s *discordgo.Session, e *discordgo.GuildCreate)

OnGuildCreate handles when we join a Discord guild

func OnMessageCreate

func OnMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate)

OnMessageCreate handles when a regular message is sent in a channel that we have access to

func OnReady

func OnReady(s *discordgo.Session, e *discordgo.Ready)

OnReady handles the "ready" event from Discord

func RemoveFromStringArray

func RemoveFromStringArray(arr []string, item string) []string

RemoveFromStringArray removes a single item from a string array

func RemoveMultipleFromArray

func RemoveMultipleFromArray(arr, toRemove []string) []string

RemoveMultipleFromArray removes anything that's in the second array from the first array

func SaveConfigToFile

func SaveConfigToFile(name string, data interface{}) error

SaveConfigToFile saves the given data to the given file name in the local config directory

func SetGuildDefaults

func SetGuildDefaults(guildID string)

SetGuildDefaults creates a new guild configuration with defaults, adds it to the existing configuration, and saves it to the disk

Types

type AdminPlugin

type AdminPlugin struct {
	// contains filtered or unexported fields
}

AdminPlugin is our admin plugin struct

var BelugaAdmin AdminPlugin

BelugaAdmin is our admin plugin instance

func (*AdminPlugin) Handle

func (p *AdminPlugin) Handle(s *discordgo.Session, c Command)

Handle handles all admin-related commands

type Command

type Command struct {
	ChannelID    string
	Command      string
	GuildID      string
	Message      string
	MessageNoCmd string
	Sender       *discordgo.User
}

Command represents a chat command for a Beluga plugin to handle

type CommandPlugin

type CommandPlugin interface {
	Handle(s *discordgo.Session, c Command)
}

CommandPlugin is the interface that plugins can implement to handle commands from a Discord channel

type CustomCommandsPlugin

type CustomCommandsPlugin struct{}

CustomCommandsPlugin is our custom command creater and responder plugin

var Commands CustomCommandsPlugin

Commands is our ResponderPlugin instance

func (*CustomCommandsPlugin) Handle

func (p *CustomCommandsPlugin) Handle(s *discordgo.Session, c Command)

Handle handles the commands for the responder plugin

type Flags

type Flags struct {
	ConfigDir string `short:"c" long:"configDir" description:"Specify the directory to use for configuration files"`
}

Flags holds the global command-line flags

type GuildConfig

type GuildConfig struct {
	EnabledPlugins  []string
	CustomResponses map[string]string
	SlapConfig      SlapPluginConfig
}

GuildConfig is a guild-specific configuration

type HunterPlugin

type HunterPlugin struct{}

HunterPlugin is our hunter2 plugin

var Hunter HunterPlugin

Hunter is our hunter2 plugin instance

func (*HunterPlugin) Handle

func (p *HunterPlugin) Handle(s *discordgo.Session, c Command)

Handle handles the "!hunter2" command

type PluginManager

type PluginManager struct {
	Plugins map[string]plugin.Symbol
}

PluginManager is the Beluga plugin manager

var Manager *PluginManager

Manager is our plugin manager for third-party plugins

func (*PluginManager) IsEnabled

func (pm *PluginManager) IsEnabled(guild string, name string) bool

IsEnabled will check if the given plugin is enabled in the Beluga config

func (*PluginManager) IsLoaded

func (pm *PluginManager) IsLoaded(name string) bool

IsLoaded will check if the given plugin name has an entry in our plugins map.

func (*PluginManager) LoadPlugins

func (pm *PluginManager) LoadPlugins() error

LoadPlugins attempts to load all found plugins

func (*PluginManager) SendCommand

func (pm *PluginManager) SendCommand(cmd Command)

SendCommand sends a chat command to all registered handlers

type RootConfig

type RootConfig struct {
	// Token is the Discord bot token to use to connect to Discord
	Token string `toml:"discord_bot_token"`
	// Guilds contains the guild-specific configurations for each guild
	Guilds map[string]*GuildConfig
}

RootConfig is our root configuration structure

var Config RootConfig

Config is our global Config object

func LoadConfig

func LoadConfig() (conf RootConfig, err error)

LoadConfig will load the config and return it

func SetDefaults

func SetDefaults() RootConfig

SetDefaults sets any sane default configuration options

type SlapPlugin

type SlapPlugin struct{}

SlapPlugin is our slapping plugin

var Slapper SlapPlugin

Slapper is our slap plugin instance

func (*SlapPlugin) Handle

func (p *SlapPlugin) Handle(s *discordgo.Session, c Command)

Handle implements the '!slap' command

type SlapPluginConfig

type SlapPluginConfig struct {
	SelfSlap     string   `toml:"self-slap"`
	SlapMessages []string `toml:"slap-messages,omitempty"`
}

SlapPluginConfig holds the configuration options for the slap plugin. These options are guild-specific

type UserBlacklist

type UserBlacklist struct {
	Guilds map[string][]string
}

UserBlacklist contains the user ID's that are blacklisted from using commands

var Blacklist UserBlacklist

Blacklist is the list of users who are blacklisted from using commands

func LoadBlacklist

func LoadBlacklist() (blacklist UserBlacklist, err error)

LoadBlacklist reads the blacklist file

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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