TwasiDocs

TwasiDocs

  • Developers
  • Users
  • Changelogs
  • Blog
  • Languages iconEnglish
    • Deutsch

›Core concepts

Welcome

  • Home

Core concepts

  • The Twasi-Plugin
  • The Twasi-Command
  • The Twasi-Variable

Getting started

  • Local Twasi setup
  • Plugin Base
  • Plugin commands
  • Plugin translations
  • Plugin variables
  • Plugin permissions

The Twasi-Plugin

Twasi itself does not provide many features to use in the Twitch chat. Instead it loads plugins that contain these features bundled in a .jar file.

The Twasi-plugin-framework

Twasi-Core contains the Twasi-plugin-framework. This is a Java framework for building Twasi-features as easy as possible. You can include it using the Java dependency injection system "Maven", since Twasi Core is deployed on our public Maven Artifactory.

What does a Twasi-plugin consist of?

The TwasiPlugin class

Every Twasi-plugin has a main class that is loaded by the Twasi Core. This class needs to extend the "TwasiPlugin" class of Twasi Core. It is the main interface for interacting with the core.

It consists of the following methods and functions that can be overridden:

NameReturn typeMust be overriddenDescription
getUserPluginClass()Class<? extends TwasiUserPlugin>YesReturns the class that will be instantiated for each user that has the plugin installed.
onActivate()voidNoAn event handler that will be called when the plugin is activated.
onDeactivate()voidNoAn event handler that will be called when the plugin is deactivated.
onReady()voidNoAn event handler that will be called when the plugin is ready.
getGraphQLResolver()GraphQLQueryResolverNoIf your plugin provides API endpoints for the public GraphQL-API, you need to return your GraphQL-Resolver here.

The TwasiUserPlugin class

The TwasiPlugin class is instantiated once the plugin is loaded. It has a function that must be overridden called getUserPluginClass() that returns a class extending the TwasiUserPlugin class. This class will now be instantiated for each Twasi-user who has the plugin installed. The idea behind this is simplicity for the developers. You can temporarily store information and context that belongs to a channel in class variables of your UserPlugin-class and don't have to put these information in maps or something similar.

It consists of the following methods and functions that can be overridden:

NameReturn typeDescription
onEnable(TwasiEnableEvent)voidAn event handler that will be called when the UserPlugin is enabled (After restarting the core).
onDisable(TwasiDisableEvent)voidAn event handler that will be called when the UserPlugin is disabled (When stopping the core).
onInstall(TwasiInstallEvent)voidAn event handler that will be called when the UserPlugin is installed.
onUninstall(TwasiInstallEvent)voidAn event handler that will be called when the UserPlugin is uninstalled.
onCommand(TwasiCommandEvent)voidAn event handler that will be called when a command is executed.
onMessage(TwasiMessageEvent)voidAn event handler that will be called when a message is sent to the user's chat (ignoring the bot's messages).

None of them must be overridden

Overriding the onCommand method will disable the command registration system which is highly recommended to use due to its flexibility.

If you want to use the onMessage method, you need to set "messageHandler" to true in your plugin.yml file.

The plugin.yml file

To make Twasi understand your plugin, you need to put a plugin.yml file into your resource folder (or directly into your jar-file). This file contains basic information about the plugin and tells the core which commands, permissions and API-endpoints are available. But we will come to these things later.

Example plugin.yml

This is an example of how a simple plugin.yml file could look like:

name: "My cool plugin"
author: "DieserMerlin"
main: net.twasiplugin.example.ExamplePlugin
version: "1.0"
description: "An example plugin"
commands:
    - test
permissions:
    - exampleplugin.test

plugin.yml properties

The following properties are available:

nametypedescriptionrequired
namestringThe unique name of the plugin. Should not be changed later.yes
descriptionstringA short description of the plugin.no
authorstringThe author's name.yes
versionstringThe current version of the plugin.yes
mainstringThe full path to your TwasiPlugin class including the package.yes
helpTextstringAn explaination how your plugin works.no
apistringGraphQL API definitions.no
messageHandlerbooleanWhether the plugin should receive all messages.no
dynamicCommandNamesbooleanWhether the plugin should listen to all commands.no
dependencybooleanWhether the plugin is a TwasiDependency.no
hiddenbooleanWhether the plugin should be hidden from the plugin store.no
autoInstallbooleanWhether the plugin should automatically install.no
commandsstring[]A list of all command names.no
permissionsstring[]A list of all permission keys the plugin uses.no
dependenciesstring[]Other Twasi-Plugins that the plugin depends on.no

While the name of the plugin is required (because it's the "id" of the plugin), the description and the helptext are not. The reason is that you can provide these localized in the translation files of the plugin later.

Behaviour of hidden and autoInstall:

The properties hidden and autoInstall should not be used in most cases. They were implemented to create plugins that are always installed like the debug-plugin or the StreamTracker.

hiddenautoInstallbehaviour
truefalseThe plugin won't show up in the plugin store and will not be installed in any channel unless it is added to a user's plugin list manually using the database.
falsetrueNew user's will see the plugin on the setup page of Twasi as recommended.
truetrueThe plugin won't show up in the plugin store but will be automatically loaded for every user when Twasi starts up.

Plugin configurations

If your plugin needs a configuration file, you can create a template class with all of the settings that should be available. Twasi will automatically create the file for you based on the template you specify. Afterwards you can load this file in the code with one single line of code.

Possible use case: Your plugin integrates with a third party API and needs API credentials. Instead of hardcoding them, you can create a configuration file where the instance hoster can put them in.

Translations

Twasi is not restricted to one language. At the moment we support the German and the English language. To support multiple languages, Twasi uses translation files (country-code.lang) stored in the plugin's resource folder under /translations.

Currently supported languages:

codecountry
DE_DEGermany/Deutschland
EN_GBGreat Britain

They are structured like this:

translation.key=This is an example text.
command.output=Hey {sender.displayName}!

You will learn about parameter binding like {sender.displayName} here.

Translations keys can be chosen by the plugin developer but should be separated by dots.

There are default translation keys that should always be set:

keydescription
plugin.nameThe localized name of the plugin.
plugin.descriptionThe localized description of the plugin.
plugin.helptextThe localized helptext of the plugin.
← HomeThe Twasi-Command →
  • The Twasi-plugin-framework
  • What does a Twasi-plugin consist of?
    • The TwasiPlugin class
    • The TwasiUserPlugin class
    • The plugin.yml file
    • Plugin configurations
    • Translations
TwasiDocs
Docs
User DocumentationDeveloper DocumentationAPI Reference
Community
DiscordTwitter
More
BlogGitHub
Legals
PrivacyTerms of UseImprint
Copyright © 2019 Twasi | Twasi.NET | Docs.Twasi.NET