snorlax

package module
v0.0.0-...-4014866 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: MIT Imports: 17 Imported by: 0

README

Snorlax - See bear for a better bot. (Rework)

GitHub tag Report Card Documentation Powered By License

Snorlax is yet another modular Discord bot, with loads of premade modules and other features.

This is still in early development, therefore it is subject to frequent breaking changes and rewrites.

Menu

Premade Modules

  • Administration
  • Eval
  • Gambling (WIP)
  • Moderation
  • Music
  • Role Manager
  • More to come!

Getting Started

To get the public bot, you can just click here (invalid link, not public yet).

To run it yourself, grab one of the releases. (Still in early development, see running from source).
Once downloaded go to the location of the downloaded binary, create a config.

This a sample config:

{
    "autoDelete": true,
    "dbPath": "./snorlax.db",
    "debug": false,
    "displayAuthor": false,
    "token": "bot-token",
    "owners": [
        "140254342170148864"
    ]
}

When you've created a config, run the program:

$ ./snorlax

Commands

Visit the website (not finished, see help command) for a full list of commands.

Running From Source

To run the bot from source, you need to have Go installed.
You also need to define a GOPATH.

Follow these instructions to compile and run Snorlax form source.

$ go get github.com/omarhachach/snorlax
$ go install github.com/omarhachach/snorlax/cmd/snorlax

It will install it in the bin folder in your GOPATH ($GOPATH/bin).
If you have $GOPATH/bin in your PATH variable, you will be able to run it like so:

$ snorlax

Remember to create a config before running the bot.

Contributing

If you've found a bug, or have a suggestion feel free to open an issue.

You can contact me (the author) on Discord: Omar H.#6299 or via email.

License

Snorlax is licensed under the MIT License.

Documentation

Index

Constants

View Source
const (
	SuccessColor int = 5025616
	ErrorColor   int = 16007990
	InfoColor    int = 2201331
)

This is a collection of the standard colors used for messages.

View Source
const Version = "0.1.0"

Version is the bot version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Command    string
	Alias      string
	Desc       string
	Usage      string
	ModuleName string
	Handler    func(*Context)
}

Command holds the data and handler for a command.

type Config

type Config struct {
	// AutoDelete determines whether or not to automatically delete command
	// messages.
	AutoDelete    bool     `json:"autoDelete"`
	DBPath        string   `json:"dbPath"`
	Debug         bool     `json:"debug"`
	DisplayAuthor bool     `json:"displayAuthor"`
	Token         string   `json:"token"`
	Owners        []string `json:"owners"`
}

Config is the configuration struct for the Snorlax bot.

func ParseConfig

func ParseConfig(path string) (*Config, error)

ParseConfig parses a config file, and returns a new Config.

func (*Config) UpdateFile

func (c *Config) UpdateFile() error

UpdateFile will update the config.json file.

type Context

type Context struct {
	Log       *logrus.Logger
	Session   *discordgo.Session
	Message   *discordgo.MessageCreate
	Snorlax   *Snorlax
	State     *discordgo.State
	ChannelID string
}

Context is the context for command handlers. It serves as a way to unify styles and ease development.

func (Context) SendEmbed

func (ctx Context) SendEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)

SendEmbed sends a custom embed message.

func (Context) SendErrorMessage

func (ctx Context) SendErrorMessage(format string, a ...interface{}) (*discordgo.Message, error)

SendErrorMessage is a quick way to send an error. -scrapped- It will suffix the message with a mention to the message creator.

func (Context) SendInfoMessage

func (ctx Context) SendInfoMessage(format string, a ...interface{}) (*discordgo.Message, error)

SendInfoMessage is a shortcut for sending a message with the info colors.

func (Context) SendMessage

func (ctx Context) SendMessage(color int, title, format string, a ...interface{}) (*discordgo.Message, error)

SendMessage sends an embed message with a message and color.

func (Context) SendSuccessMessage

func (ctx Context) SendSuccessMessage(format string, a ...interface{}) (*discordgo.Message, error)

SendSuccessMessage is a shortcut for sending a message with the success colors.

type Module

type Module struct {
	Name     string
	Desc     string
	Commands map[string]*Command
	Init     func(*Snorlax)
}

Module is used to import a modular package into the bot. This serves to make the bot modular and expandable.

type Snorlax

type Snorlax struct {
	Commands map[string]*Command
	Modules  map[string]*Module
	Session  *discordgo.Session
	Log      *logrus.Logger
	Mutex    *sync.Mutex
	DB       *sql.DB
	Config   *Config
}

Snorlax is the bot type.

func New

func New(config *Config) *Snorlax

New returns a new bot type.

func (*Snorlax) Close

func (s *Snorlax) Close()

Close closes the Discord session, and exits the app.

func (*Snorlax) ConnDB

func (s *Snorlax) ConnDB()

ConnDB intializes the connection to the SQLite database.

func (*Snorlax) InitDB

func (s *Snorlax) InitDB()

InitDB will create the initial tables and rows of the database.

func (*Snorlax) IsOwner

func (s *Snorlax) IsOwner(id string) bool

IsOwner returns whether or not a given ID is in the owners list.

func (*Snorlax) RegisterModule

func (s *Snorlax) RegisterModule(module *Module)

RegisterModule allows you to register a module to expand the bot.

func (*Snorlax) RegisterModules

func (s *Snorlax) RegisterModules(modules ...*Module)

RegisterModules registers a list of modules.

func (*Snorlax) Start

func (s *Snorlax) Start()

Start opens a connection to Discord, and initiliazes the bot.

Jump to

Keyboard shortcuts

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