Skip to content

Making Plugins

Zach | xDest edited this page Apr 12, 2018 · 5 revisions

How to create a Plugin

Note:

This is a guide on how to create a plugin using this interface. It isn't a tutorial on how to write a bot. You should already be familiar with (or learning about) JDA. This bot is more like an extension of the JDA wrapper.

With that out of the way, let's start.

Starting out

Acquire ComBot

First, you'll need to download some version of ComBot. As ComBot is compiled with the JDA included, this file is all you'll need.

ComBot versions (or check the meme dist co website repo)

Add ComBot as a lib / dependency

You'll need to add ComBot to your project in some way, similar to how you need to add JDA to your project to make bots.

Create your main class

You'll need a main class. It doesn't follow any naming convention, but it must implement com.mdc.combot.plugin.BotPlugin. The two methods included are simply enable() and disable(). This is where you will set up anything you need and get your plugin ready to go, and where you'll do any final saving and other things when it shuts down.

Important

Make sure to include a plugin.txt at the root of your project, and include it when you export your project to a jar.

The line ComBot 100% needs is main:path.to.main.PluginClass. There are other optional lines you can include, such as author:<your name, however you want it>, version:<your plugin version>, and info:<line of info>.

Your final plugin.txt might look something like this:

main:com.xdest.pltest.MyFirstPlugin

author:xDest#abcd

version:v1.0.0

info: This is my first plugin! I can include info about the plugin here, but only on this line.

Using the bot

The bot has a few features built in, like a permissions system and command interface. As permissions are also used by users, I'll include information about them on a different page.

Important: To get the bot instance, call ComBot.getBot();

Commands

The Command interface allows you to register commands with the Bot. It's simple right now, but I plan to make it easier to use in the future. The Command interface contains two methods, called(ComBot b, MessageReceivedEvent e) and getLabel(). The getLabel() method should simply return what you want your command to be called. For instance, a ban command's label would be "ban". The called(Bot, Evt) method is called when a user types a command that matches your provided label and functions the same as a message received event normally would. Again, in the future, I plan to add a built in command parser and change the command interface to something which is easier to use.

Util

ComBot includes a Util class com.mdc.combot.util.Util which provides some conversions and a few other small things, reducing the amount of code you have to write. It'll expand as time goes on.

PermissionsInstance

ComBot also includes a permission manager, should plugins decide to use it. The built in permission system uses json to assign permissions to users and roles. However, the bot's permission manager can be overwritten by another plugin with bot.setPermissionManager(PermissionsInstance s). If you choose, you can write a plugin which allows the user to assign permissions in an easier way, and override the default system. However, you should not change how the permissions themselves work. Permissions should function in a hierarchical fashion always.

Docs

I try to keep the docs as updated as possible, and you can view them here