foundation

package module
v5.0.1-alpha+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

README

discord

SkilStak's discord bot.

About

skilbot® is a golang moderation and integration bot for SkilStak®'s Discord server. It helps to register users and link them with their IRL name, posts updates from github repos and Mr. Rob's blog to appropriate channels and logs deleted messages.

Files

Along with the go files that... well are the bot, the bot needs a json file to tell it what it likes and who it is. An example one is provided (titled preferences.json) but note that the authentication fields are empty (so our bot doesn't get hijacked)

Changing the SkilBot used on the server

Although this repo isn't exactly the source code for the real SkilBot, we would be happy to take in any suggestions for the bot. Simply fork this and put in a pull request. If its accepted it will be put onto the real skilbot.

EOF

Documentation

Index

Constants

This section is empty.

Variables

A discordgo session global variable as .Session is needed for a lot. This is written to in the main.go file.

Functions

func Contains

func Contains(list []string, item string) bool
# Check if item is in array

* This function checks if a value is in a slice (string only) * * Parameters: * - list ([]string) | the slice to be checking against * - item (string) | the item looked for in the slice * * Returns: * - bool | If the item was found or not * * NOTE: If another Contains() funciton is needed for a different type, rename * this function to ContainsSliceString() and the other function to * ContainsSlice<T>() where <T> is the generic type.

func GetGuild

func GetGuild(s *dsg.Session, m *dsg.Message) (st *dsg.Guild, err error)
# Get the guild a message was sent in.

* What a pain in the arse. * * Parameters: * - s (type *discordgo.Session) | The current running discord session, * (discordgo needs that always apparently) * - message (type *discordgo.Message) | the author's id is extracted from this. * * Returns: * - st (type *discordgo.Guild) | The guild the message was found in * - err (type error) | If an error was encountered during the process * This error is an SEP (someone else's problem).

func HasPermissions

func HasPermissions(s *dsg.Session, m *dsg.Message, userID string, perm int) (bool, error)
Checks if user has permission to run a command

* This function is a wrapper to check if a user has the permission needed to * run a given command. This checks for both specific permissions the user has * in the server (see below) and for "bot staff" roles defined in the config. * Permissions are integer constants defined by discordgo: * https://godoc.org/github.com/bwmarrin/discordgo#pkg-constants * Note that the check is non-hierarchichal.

func RoleFromID

func RoleFromID(s *dsg.Session, m *dsg.Message, id string) (*dsg.Role, error)

a stupid, inefficent function to get a role from its id

Types

type Action

type Action func(session *dsg.Session, message *dsg.MessageCreate)
Defines the actual action the bot takes

* This is a key component of the Command struct, it is the actual *thing* that * the command does when it is run. This can be as simple as printing a string * or embed to discord or even be a wrapper for a massive series of functions * for your discord-based RPG. * * Parameters: * - session (*discordgo.Session) The bot session, in case you need to pull data * from about discord itself to complete your task * - session (*discordgo.Message) The entire message that triggered the command * this includes the prefix and command itself. You will have to parse out * flags and clean the input. * * NOTE: THIS DOES NOT RETURN ERRORS. YOU MUST HANDLE ERRORS.

type BotType

type BotType struct {
	Auth struct {
		ClientID string `json:"clientID"`
		Secret   string `json:"secret"`
		Token    string `json:"token"`
		Port     string `json:"port"`
	} `json:"auth"`
	Prefs struct {
		Prefix  string `json:"prefix"`
		Playing string `json:"playing"`
		Version string `json:"version"`
	} `json:"prefs"`
	Perms struct {
		WhitelistChannels   bool     `json:"whitelistChannels"`
		WhitelistedChannels []string `json:"whitelistedChannels"`
		BlacklistedChannels []string `json:"blacklistedChannels"`
	} `json:"perms"`
	Users struct {
		RoleWhitelist    bool     `json:"roleWhitelist"`
		ReportPermFails  bool     `json:"reportPermissionFailures"`
		BlacklistedRoles []string `json:"blacklistedRoles"`
		AdminRoles       []string `json:"adminRoles"`
		StaffRoles       []string `json:"staffRoles"`
		StandardRoles    []string `json:"standardUser"`
	} `json:"users"`
}
# Big Bot Boye

* This struct is all about who the bot is: its prefrences, authentication, etc. * * The fields are self explanitory so I'm not going to detail them. * * TODO: I think the auth section needs to be either a different json file or * passed in as parameters because the rest isn't nearly as important. *

var MyBot BotType

An initialized instance of the BotType for use everywhere in this project.

type Command

type Command struct {
	Name    string `json:"name"`
	Help    string `json:"help"`
	Perms   int    `json:"perms"`
	Version string `json:"version"`
	Action  Action `json:"-"`
}
Defines static data about commands the bot runs.

* This is a very large structure that defines all the needed bits for a bot * command. All bot modules MUST have one of these along with a few other key * components so that the bot works. * * Parameters: * - Name (string) | The name of the command, used in the help page * - Help (string) | A description of the command and how it is used. * - Action (Action) | The function the command runs * - Perms (Int) | Oh boy this is a doozie: * This is the integer value of the permissions needed to run the command. If * you don't know what value to use, use a calculator tool such as * https://discordapi.com/permissions.html or discordgo's predefined constants * available at https://godoc.org/github.com/bwmarrin/discordgo#pkg-constants * If you want your command available to all users who can trigger the bot, set * this value to -1.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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