gophbot

package module
v0.0.0-...-518a455 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2018 License: MIT Imports: 16 Imported by: 0

README

GophBot Build Status Go Report Card

This is a powerful moderation bot for use in Discord. You can invite me using this link: Invite me!

Building

All steps provided here assume you have your GOPATH configured correctly, see this page.

The two commands below will download all dependencies and then install the gophbot binary to $GOPATH/bin

go get github.com/ikkerens/gophbot/cmd/gophbot
go install github.com/ikkerens/gophbot/cmd/gophbot

Running

Windows:

SET TOKEN="PASTEYOURTOKENHERE"
SET SQL_DSN="dbuser:dbpass@localhost/dbname"
%GOPATH%\bin\gophbot.exe

Linux/Mac/Unix:

export TOKEN=PASTEYOURTOKENHERE
export SQL_DSN=dbuser:dbpass@localhost/dbname
$GOPATH/bin/gophbot

Documentation

Index

Constants

View Source
const (
	// OkHand is the 👌 emoji in Discord.
	OkHand = "\U0001f44c"
	// Error is the ❗ emoji in Discord
	Error = "\U00002757"
	// LoadingReaction is the loading gif often used in Discord, but as emoji
	LoadingReaction = "a:loading:428921925377458187"
)

Variables

View Source
var (
	// DB is the database connection pool that we use for obtaining guild/channel-specific settings.
	DB *gorm.DB

	// Self is the bot user itself
	Self *discordgo.User
)

Log is the bots main logging utility

View Source
var State = struct {
	sync.RWMutex
	Guilds map[string]*Guild
}{
	Guilds: make(map[string]*Guild),
}

State keeps commonly use settings for the bot in memory for quick access

Functions

func AddHandler

func AddHandler(handler interface{})

AddHandler adds an event handler to all shards

func ComputeBasePermissions

func ComputeBasePermissions(member *discordgo.Member, guild *discordgo.Guild) (int, error)

ComputeBasePermissions calculates the permissions a guild member has, outside the scope of a channel

func ComputeOverwrites

func ComputeOverwrites(basePermissions int, member *discordgo.Member, channel *discordgo.Channel) (int, error)

ComputeOverwrites calculates the permissions a channel member has, given the guilds base permissions

func ComputePermissions

func ComputePermissions(member *discordgo.Member, channel *discordgo.Channel) (int, error)

ComputePermissions calculates the permissions a channel member has, using the guilds base permissions

func GetChannel

func GetChannel(discord *discordgo.Session, channelID Snowflake) (*discordgo.Channel, error)

GetChannel attempts to get a channel instance from the shard state cache, and if none exists, attempts to obtain it from the Discord API. Will err if the channel does not exist or the bot is not in the guild it belongs to.

func GetGuild

func GetGuild(guildID Snowflake) (*discordgo.Guild, error)

GetGuild attempts to get a guild instance from the shard state cache, and if none exists, attempts to obtain it from the Discord API. Will err if the guild does not exist or if this guild is unreachable for the bot.

func GetGuildMember

func GetGuildMember(guildID, userID Snowflake) (*discordgo.Member, error)

GetGuildMember will attempt to obtain a member instance for this guild member. Will err if this user is not a member of this guild

func GetOverwrite

func GetOverwrite(channel *discordgo.Channel, target interface{}) *discordgo.PermissionOverwrite

GetOverwrite will attempt to obtain the PermissionOverwrite instance for the target (Role, Member or User) Will return nil if no such overwrite exists

func GetOverwriteByID

func GetOverwriteByID(channel *discordgo.Channel, id Snowflake, typ string) *discordgo.PermissionOverwrite

GetOverwriteByID will attempt to obtain the PermissionOverwrite instance for the given ID and type ("role" or "user") Will return nil if no such overwrite exists

func GetRole

func GetRole(guildID, roleID Snowflake) (*discordgo.Role, error)

GetRole will attempt to obtain a role instance for this role Will err if the given ID is not a role in the guild.

func Start

func Start()

Start is the main entry point for the bot, outside of the main package to allow external packages to call back

Types

type Guild

type Guild struct {
	ID     Snowflake `gorm:"size:20;primary;not null"`
	Prefix string    `gorm:"size:10;not null;default:\"!\""`
}

Guild is the metadata of this guild in the database, for guild-specific settings.

type Snowflake

type Snowflake = string

Snowflake is a convenience typealias depicting the format used to store snowflakes

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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