Skip to content

Create a new plugins

lequanglam edited this page Feb 9, 2020 · 9 revisions

//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

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 is name (directory with file names): value (custom names). After mapped, files can be accessed via global.fileMap[(custom names)] and stored as Buffer.

Per command, there is:

  • hargs: Some help about arguments required on the command
  • hdesc: Some information about what the command does
  • fscope: Function name in plugin_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 on compatibly is assigned to a platform. For example: 00000010 convert to decimal is 2, we enter 2 into compatibly. Now if we run the bot, then only Discord can execute that command, but not everything else. If we enter 1 (00000001) into compatibly, then only Facebook can execute that command. Currently the structure of compatibly is 000000DF where 0 is Not assigned, D is Discord, F is Facebook. If the value is 0, it'll indicate that this command can run on every platform this bot supported.

Javascript executable file

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
}

Submit your new plugins

Just upload it to somewhere like Google Drive or MEGA, then submit an issues contains a link to plugins with label new plugins

Clone this wiki locally