-
Notifications
You must be signed in to change notification settings - Fork 8
Create a new plugins
//For v0.3.0
A plugin contains a plugin.json
file, a javascript executable file, and other files that plugin uses. It's a ZIP file with extensions changed to .z3p
.
plugin.json
is a file that contain information about the plugin, command list, authors, etc...
Example:
{
"plugin_name": "Ping",
"plugin_scope": "ping",
"plugin_exec": "ping.js",
"command_map": {
"ping": {
"hargs": "",
"hdesc": "Ping",
"fscope": "fping",
"compatibly": 0
}
},
"author": "",
"version": "1",
"node_depends": {
"http": "*"
},
"complied_for": "0.3.0"
}
That plugin.json
content above will define this plugin is named "Ping", version 1, built for bot version 0.3.0, requires a node modules named http
and contains a command /ping
with compatibly 0 (more on this later).
plugin_name
, plugin_scope
, plugin_exec
and complied_for
is required, but author
and version
is not. Also command_map
and node_depends
is required but doesn't need to contain any items.
Also, there's some properties that is not required but some plugin might contains it like:
-
file_map
: To map file inside plugin file for the code to use. -
dependents
: An array. If your plugin need to access other plugins, bot will read this property and check if plugin defined (by plugin names) in here is installed. If not, your plugin will not load until that plugin is installed. -
file_map
: An object which structures isname (directory with file names): value (custom names)
. After mapped, files can be accessed viaglobal.fileMap[(custom names)]
and stored asBuffer
.
Per command, there is:
-
hargs
: Some help about arguments required on the command -
hdesc
: Some information about what the command does -
fscope
: Function name inplugin_scope
that contains code capable of processing input data -
compatibly
: Because this bot can be cross-platform (like Facebook, Discord, ...), this value defines the command can run on what. This value is treated as binary. Every bits oncompatibly
is assigned to a platform. For example: 00000010 convert to decimal is 2, we enter 2 intocompatibly
. Now if we run the bot, then only Discord can execute that command, but not everything else. If we enter 1 (00000001) intocompatibly
, then only Facebook can execute that command. Currently the structure ofcompatibly
is000000DF
where0
isNot assigned
,D
isDiscord
,F
isFacebook
. If the value is 0, it'll indicate that this command can run on every platform this bot supported.
This file contains javascript code required to run commands. It need to be named after the name written in config.json
(plugin_exec
).
Example of content (plugin Ping):
var pingfunc = function (type, data) {
return {
handler: "internal",
data: "Pong!"
}
}
module.exports = {
fping: pingfunc
}
Ok, so if the function is a function that will be called by bots, then it will be called with 2 arguments type
and data
.
type
is a string that let the function knows that an user from "type
" called a command that linked to the function. It can be "Facebook", or "Discord".
data
is an object contains pretty much any data from users. It has a structure like this:
{
args: ["Some", "arguments", "that", "users", "typed", "alongside", "commands"],
time: 123456789, //Unix time inform received time
msgdata: {}, //An object returned by facebook-chat-api or discord.js
facebookapi: {}, //This is an object fca-unofficial return when log in.
prefix: "[Bot]", //Used only if response is handled by plugin itself.
admin: false, //Indicate if users requested the command is admin configured in config.
mentions: {
"FB-0": "@Someone", //Mentions from facebook-chat-api
"DC-0": {} //An MessageMention returned from discord.js
},
discordapi: {} //A Discord.Client object returned by discord.js
}
Just upload it to somewhere like Google Drive or MEGA, then submit an issues contains a link to plugins with label new plugins