commandframework_discordgo

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

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

Go to latest
Published: Oct 2, 2018 License: MIT Imports: 2 Imported by: 0

README

Discord.go - Command Framework

What is it?

Well, it's simply a command framework for Golang using Discord.go.

It's quite simple to set up and shouldn't take anyone a long time to make a bot.

How do I use it?

Fetching

First of all, you'll need to get it:

go get -t https://github.com/Proximyst/CommandFramework-D.GO

Secondly, you'll need to simply import it:

import (
    "github.com/Proximyst/CommandFramework-D.GO"
)

Take note an alias would be a good choice, as commandframework is quite long.

To now make a manager, you'll need to something along these lines:

var (
    Token string // Set it with init or however you'd like.
    Manager *commandframework.CommandManager // The frameworks manager.
)
 // ....
func main() {
    // .... - bot is assumed to be the result from discordgo.New
    Manager := commandframework.NewManager()
    Manager.Prefix = "b!" // set the prefix to something else. it allows any length
    Manager.AddCommand(Command{
        Handler: PingCommand,
        Names: []string{
            "ping",
            "pong",
        },
        Predicates: []func(context *CommandContext) bool{},
    }) // This can take any number of arguments. Just add a comma and another one, or a hundred

    // Done?
    bot.AddHandler(Manager.ChatListener)
}

And in that example, this may be the PingCommand:

func PingCommand(context *commandframework.CommandContext) {
    context.Session.ChannelMessageSend(context.Event.ChannelID, "hemlo!!")
}

This will all be done automatically for you afterwards.

More features are to come, though, so we'll see how far this goes..

License

MIT License

Copyright (c) 2018 Mariell Hoversholm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BehaviourSettings

type BehaviourSettings struct {
	// DeleteMessageSuccess represents whether the bot should delete commands
	// upon success of finding and/or executing it.
	DeleteMessageSuccess bool

	// DeleteMessageUnknown represents whether the bot should delete any commands with
	// the correct prefix, even when it doesn't know what command it is.
	DeleteMessageUnknown bool

	// ReactMessageUnknown represents whether the bot should react to commands it does not recognise.
	ReactMessageUnknown string

	// HandleTts represents whether or not it should respond to TTS.
	HandleTts bool
}

BehaviourSettings represent settings related to how the bot should behave.

type Command

type Command struct {
	// Handler represents the function that will handle the command.
	Handler func(context *CommandContext)

	// Names represent the name and aliases this command can be used with.
	//
	// Names[0] is the main name, while the rest are counted as aliases.
	// If there is no name upon registration, this will produce an error.
	Names []string

	// Predicates represent the different conditions that are required the be fullfilled
	// before the command will be executed as usual.
	Predicates []func(context *CommandContext) bool
}

Command represents a command used within Discord.

If the prefix is "!", then "!h" and "!help" would require: ```go

Command {
	Handler: func(context *CommandContext) { context.DoStuff() },
	Names: []string{"h", "help"},
}

```

type CommandContext

type CommandContext struct {
	// Implementation represents the implementation of the command.
	//
	// This can be used to get the inner instance of the command, should it be needed.
	Implementation *Command

	// Event represents the event of the message itself.
	Event *discordgo.MessageCreate

	// Session represents the session instance of the bot.
	Session *discordgo.Session

	// Label represents the label used to execute the command, of the registered names.
	Label string
}

CommandContext represents the context of the command execution.

This is handed to the command's handler.

type CommandManager

type CommandManager struct {
	Prefix    string
	Commands  []Command
	Behaviour BehaviourSettings
}

func CreateManager

func CreateManager() CommandManager

func (*CommandManager) AddCommand

func (manager *CommandManager) AddCommand(commands ...Command)

func (*CommandManager) ChatListener

func (manager *CommandManager) ChatListener(session *discordgo.Session, event *discordgo.MessageCreate)

Jump to

Keyboard shortcuts

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