gosdbot

package module
v0.0.0-...-7b0d920 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2018 License: MIT Imports: 12 Imported by: 0

README

GoDoc Go Report Card Build Status

SDBot

SDBot is a package with a few utilities and the code to spin up fairly simple Discord bot written in the Go. Simply stripping the current main.go file out and running it as-is with a responses.json file customized as per the template or example file can get you up and running in no time!

Getting Started

Installing

This assumes you already have a working Go environment, if not please see this page first.

go get github.com/mjhehn/sdbot

Usage

Import the package into your project.

import "github.com/mjhehn/sdbot"

See Documentation(in-progress, AKA nonexistent right now) and the Examples folder for more detailed information.

License

This project is licensed under the MIT License - see the LICENSE file for details

Documentation

Overview

Package gosdbot acts as an extension of the discord api by implementing some helper methods and additional functions potentially useful for a go discord bot.

Index

Constants

View Source
const (
	Textresponse     = 0
	Embedresponse    = 1
	Reactionresponse = 2
)

help improve readability of the 'general' response checker method.

View Source
const (
	EmbedLimitTitle       = 256
	EmbedLimitDescription = 2048
	EmbedLimitFieldValue  = 1024
	EmbedLimitFieldName   = 256
	EmbedLimitField       = 25
	EmbedLimitFooter      = 2048
	EmbedLimit            = 4000
)

Constants for message embed character limits

Variables

This section is empty.

Functions

func Check

func Check(err error)

Check prints the results of an error if it exists

func CheckWebHooks

func CheckWebHooks(session *discordgo.Session, message *discordgo.MessageCreate, target string) bool

CheckWebHooks parses through a list of webhooks given the channel to see if the target is present

func Cleanup

func Cleanup(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

Cleanup removes messages from bots within a range. defaults to 100 messages back to clean

func CleverResponse

func CleverResponse(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool, clvrbot *cleverbot.Session)

CleverResponse parses requests from channels tagged with the cleverbot webhook and mentioning this bot, and then asks them to cleverbot.

func Compliment

func Compliment(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

Compliment pulls a 'compliment' from a json list found online from emergencycompliment.com and displays it

func Delete

func Delete(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

Delete a number of messages. same basically as cleanup

func DiceRoller

func DiceRoller(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

DiceRoller rolls a variable number and type of dice. same format of parameters as other responders.

func GetEmoji

func GetEmoji(session *discordgo.Session, msg *discordgo.MessageCreate, name string) *discordgo.Emoji

GetEmoji retrieves server emoji by name if it exists.

func GetGuild

func GetGuild(session *discordgo.Session, msg *discordgo.MessageCreate) *discordgo.Guild

GetGuild retrieve the actual server/guild object

func GetJSON

func GetJSON(url string, target interface{}) error

GetJSON ...

func GetRoles

func GetRoles(session *discordgo.Session, msg *discordgo.MessageCreate) []string

GetRoles retrieves the roles of a user based on the message the sent+the current session

func GetServer

func GetServer(session *discordgo.Session, msg *discordgo.MessageCreate) string

GetServer retrieve the guild/server by name from the current message and session

func In

func In(s string, list []string) bool

In checks if s is in the list

func NotJustTheMen

func NotJustTheMen(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

NotJustTheMen is a prequel meme

func RunIt

func RunIt(chance int) bool

RunIt takes in a chance (1:chance) and rolls to see if the number generator for that range hits 0

Types

type AutoResponse

type AutoResponse struct {
	Trigger        string              //regex needed to invoke the response as a string
	Regex          *regexp.Regexp      //the regex compiled. handled by NewAutoResponse
	Responses      []*TextResponse     //list of textresposne objects possible to reply with
	Embeds         []*EmbedResponse    //list of embeds possible to reply with
	Reactions      []*ReactionResponse //list of reactions possible to reply with
	Mentions       []string            //list of mentions. currently only works with self-mentions
	Cleanup        bool                //whether the bot should delete the message that invoked the responses
	UserSpecific   []string            //list of users the autoresponse should run for
	ServerSpecific []string            //list of servers the autoresponse can run on
}

AutoResponse stores all elements needed for an Autoresponse

func NewAutoResponse

func NewAutoResponse(Trigger string, Responses []*TextResponse, Embeds []*EmbedResponse, Reactions []*ReactionResponse, Mentions []string, Cleanup bool, UserSpecific []string, ServerSpecific []string) *AutoResponse

NewAutoResponse build an AutoResponse object, takes arguments for everything and then creates a compiled regex from the Trigger

func ReadFromJSON

func ReadFromJSON() []*AutoResponse

ReadFromJSON builds a list of autoresponses based on a json file

func (*AutoResponse) CheckResponses

func (a *AutoResponse) CheckResponses(session *discordgo.Session, message *discordgo.MessageCreate, checkType int, responded chan bool)

CheckResponses acts as a generic checker and applier of responses possible from the autoresponse it is called upon. takes: pointer to the current session pointer to the message created by messagecreate event an integer telling the check whether it's checking through text responses, embedded resposnes, or (emoji) reaction responses (0, 1, 2 respectively) a bool channel to note when a goroutine has made an answer.

type Config

type Config struct {
	Ars          []*AutoResponse
	MutedServers []string
	Token        string
	Status       string
	OwnerID      string
	CleverUser   string
	CleverID     string
}

Config is a wrapper for the autoresposnses and mutedServers objects needed by the bot

func ConfigFromJSON

func ConfigFromJSON() *Config

ConfigFromJSON builds a list of autoresponses based on a json file

func NewConfig

func NewConfig() *Config

NewConfig is a server cstor

func NewConfigByToken

func NewConfigByToken(token string) *Config

NewConfigByToken is a server cstor

func (*Config) Botstatus

func (c *Config) Botstatus(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

Botstatus updates the bot's "playing" status notifier

func (*Config) LeaveServer

func (c *Config) LeaveServer(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

LeaveServer removes the bot from the guildID given to it if the user making the request is an admin

func (*Config) Mute

func (c *Config) Mute(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

Mute adds current sever to the muted list, which allows only mute commands to be received or sent.

func (*Config) Mutestatus

func (c *Config) Mutestatus(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

Mutestatus as it says, returns the current message channel's server mute state

func (*Config) Unmute

func (c *Config) Unmute(session *discordgo.Session, message *discordgo.MessageCreate, responded chan bool)

Unmute removes the current server from the muted list

type ConfigJSON

type ConfigJSON struct {
	Token      string
	Status     string
	OwnerID    string
	CleverUser string
	CleverID   string
}

ConfigJSON is a JSON serializeable struct to use to set Config via json parsing

type Embed

type Embed struct {
	*discordgo.MessageEmbed
}

Embed ...

func NewEmbed

func NewEmbed() *Embed

NewEmbed returns a new embed object

func (*Embed) AddField

func (e *Embed) AddField(name, value string) *Embed

AddField [name] [value]

func (*Embed) InlineAllFields

func (e *Embed) InlineAllFields() *Embed

InlineAllFields sets all fields in the embed to be inline

func (*Embed) SetAuthor

func (e *Embed) SetAuthor(args ...string) *Embed

SetAuthor ...

func (*Embed) SetColor

func (e *Embed) SetColor(clr int) *Embed

SetColor ...

func (*Embed) SetDescription

func (e *Embed) SetDescription(description string) *Embed

SetDescription [desc]

func (*Embed) SetFooter

func (e *Embed) SetFooter(args ...string) *Embed

SetFooter [Text] [iconURL]

func (*Embed) SetImage

func (e *Embed) SetImage(args ...string) *Embed

SetImage ...

func (*Embed) SetThumbnail

func (e *Embed) SetThumbnail(args ...string) *Embed

SetThumbnail ...

func (*Embed) SetTitle

func (e *Embed) SetTitle(name string) *Embed

SetTitle ...

func (*Embed) SetURL

func (e *Embed) SetURL(URL string) *Embed

SetURL ...

func (*Embed) Truncate

func (e *Embed) Truncate() *Embed

Truncate truncates any embed value over the character limit.

func (*Embed) TruncateDescription

func (e *Embed) TruncateDescription() *Embed

TruncateDescription ...

func (*Embed) TruncateFields

func (e *Embed) TruncateFields() *Embed

TruncateFields truncates fields that are too long

func (*Embed) TruncateFooter

func (e *Embed) TruncateFooter() *Embed

TruncateFooter ...

func (*Embed) TruncateTitle

func (e *Embed) TruncateTitle() *Embed

TruncateTitle ...

type EmbedResponse

type EmbedResponse struct {
	Chance int
	URL    string
}

EmbedResponse ...

func NewEmbedResponse

func NewEmbedResponse(setChance int, setURL string) *EmbedResponse

NewEmbedResponse cstor

type ReactionResponse

type ReactionResponse struct {
	Chance int
	Emojis []string
}

ReactionResponse stores the chance a text response will be made and the text itself

func NewReactionResponse

func NewReactionResponse(setChance int, setText []string) *ReactionResponse

NewReactionResponse ...

type TextResponse

type TextResponse struct {
	Chance int
	Text   string
}

TextResponse stores the chance a text response will be made and the text itself

func NewTextResponse

func NewTextResponse(setChance int, setText string) *TextResponse

NewTextResponse ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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