package
0.0.0-20240613153357-3ea8a2466821
Repository: https://github.com/5ht2/taro-bot.git
Documentation: pkg.go.dev

# README

plugins

This README describes how to use plugins. See the README in the root of the repo for a description of what plugins can do.

  1. Default plugins
  2. Compiling a plugin
  3. Hot-reloading plugins
  4. Creating a plugin
  5. Docker

Default plugins

Various plugins are loaded by default when using the bot, stored in the DefaultPlugins variable in bot/config.go.

You can configure the plugins that are loaded by modifying the config/plugins.json file, as described in the main README.

You are also able to change the directory that the bot looks for plugins in, which is -pluginDir="bin" by default. Changing this flag will not compile your plugins for you, the Makefile will check plugins/ for compiling, and output them to bin/.

Compiling a plugin

Running make on its own will compile the bot along with the plugins, by default. This is the code that make calls for compiling all plugins:

for d in ./plugins/*/; do
  echo "building $$d"
  go build -o "bin/" -buildmode=plugin "$$d"
done

You can compile a single plugin on your own using

go build -o "bin/" -buildmode=plugin "plugins/my-plugin/"

If you want your plugin to be loaded, you must add it to the DefaultPlugins list in bot/config.go, or the config/plugins.json file.

Hot-reloading plugins

Currently, hot-reloading is technically possible but there are no commands to do so from the user-end. This README will be updated as issue #8 is updated.

Creating a plugin

All a plugin has to do is

  • Have a plugin-name.go with a package main which declares a func InitPlugin(_ *plugins.PluginInit) *plugins.Plugin.
  • Be inside the plugins/ (or other) directory in a directory under its own name, for example, plugins/base/base.go or plugins/base-extra/base-extra.go

The actual plugins.go code is heavily documented and explains the technical process of how plugins are loaded and work.

An example plugin's example.go can be found in the plugins folder.

Docker

You can modify the plugins to be loaded via Docker with the config/plugins.json file, as described in the main README.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

ClearHandlers will go through bot.Handlers and handle the de-registration of them.
ClearJobs will clear all registered jobs.
Load will load all the plugins.
RegisterAll will register all bot features, and then load plugins.
RegisterHandlers will go through bot.Handlers and handle the re-registration of them.
RegisterJob registers a job for use with gocron.
RegisterJobConcurrent registers a job with RegisterJob concurrently, and optionally adds the job to bot.Jobs to be tracked.
RegisterJobs will go through bot.Jobs and handle the re-registration of them.
SaveConfig will save all plugin configs.
SetupConfigSaving will run each plugin's SaveConfig every 5 minutes with a ticker.
Shutdown will run the shutdown function for all plugins.
Startup will run the startup function for all plugins.

# Structs

No description provided by the author
No description provided by the author