Skip to content
This repository has been archived by the owner on Dec 25, 2019. It is now read-only.

NyanKiyoshi/disgord-plugin-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

disgord-plugin-router

Build Status Code coverage Maintainability

Godoc

A plugin management and routing mechanism for Disgord.

WARNING: this repository is still in active development and is not yet ready for the proper expected user experience. See the roadmap for more details.

Design Approach

The approach of this library is that the bot developer will create a plugin for each command, each plugin can have a set of sub-commands.

Example Design

- Roles -> lists the roles when invoked (e.g.: /roles)
    - add {role-name}               -> appends a given role
    - remove {role-name}            -> pops a given role

- Colors [color-name] -> lists the roles or set the user's color when invoked 
                         (e.g.: /colors or /colors blue)
    - add {color-hex} {color-name}  -> registers a new color
    - remove {color-name}           -> removes a given color

Features

  • Can define or not a command to be executed on root commands (read or example)
  • Can define sub-commands (one level max by design, see above section) (read or example)
  • Can define Disgord events handlers per plugin (read or example)
  • Can define typed arguments with auto parsing and error management (read or example)
  • Can blacklist/ disable pluging using patterns or matchers (read or example)
  • Can define plugin setUp and tearDown handlers (read or example)
  • Command handlers/ callbacks are context based (read or example)
  • Plugins can have separate or the same command prefix everywhere (read or example)
  • Errors can be returned by handlers and directly reported to the user (read or example)
  • Modular, modules can be imported from anywhere using go modules (read or example)
  • ...It's open source, fully tested and made with love! 🚀

Usage

package main

import (
	"github.com/NyanKiyoshi/disgord-plugin-router"
	"github.com/andersfylling/disgord"
)

type _internal struct {}

func main() {
	client := disgord.New(&disgord.Config{BotToken: "YOUR BOT TOKEN"})
	
	drouter.Router.Plugin(_internal{}, "ping").
		Handler(func(ctx *drouter.Context) error {
			return ctx.Say("pong!")
		}).
		Command("miss").Handler(func(ctx *drouter.Context) error {
			return ctx.Say("I missed.")
		})
	
	// Setup the client from the router
	drouter.Router.Configure(client)

	// Connect to the discord gateway to receive events
	if err := client.Connect(); err != nil {
		panic(err)
	}

	// Wait for ever for interrupt. Then, disconnect.
	if err := client.DisconnectOnInterrupt(); err != nil {
		panic(err)
	}
}

Roadmap

  • Implement arguments parsing with dynamic typing (instead of strings).
  • Context arguments should not contain the dispatched root command or sub command.
  • Drop plugins pointer array in the router.
  • Implement SetUp(...) and TearDown(...) functions on the plugins.
  • Add final documentation and complete examples for each feature.

About

A plugin management and routing mechanism for disgord.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages