-
Notifications
You must be signed in to change notification settings - Fork 0
Extensions
Starting with version 3.2, AwesomeBot supports extensions! They are code snippets run in response to a keyword or command, managed per-server via the admin console. To add an extension to a server, send a JSON file (described below) to the bot after logging into the admin console for a server.
Extensions are sandboxed and given 5 seconds to execute. They cannot store data between runs and are only given access to:
-
unirest: lightweight HTTP request library -
imgur: preauthenticated imgur-node-api module -
image: Google Image Search, usageimage(query, num, svrid, callback(url)) -
rss: feed-read module, usagerss(svrid, url, svrid, callback(err, articles)) -
message: (not included for timer extensions) full content of the message -
svrid: the Discord ID of the server you're in -
selected: (for keyword extensions only) the index of the match in thekeyarray -
author: (not included for timer extensions) tag for the sender -
setTimeout,JSON,Math,isNaN,Date,Array,Number -
send: write final output to this
You are responsible for validating applicable input and ensuring that the extension writes a value to send within 3 seconds.
Keyword extensions are run in response to one or more keywords in a message. Your JSON file must follow this format:
{
name: name of extension,
type: "keyword",
key: array of keywords,
case: boolean for case sensitivity,
channels: (optional) array of accepted channel names,
process: code to execute, as a string
}
You can use this website to stringify your code. Here's an example of a fun keyword extension that uses image search:
{
"name": "Praise DuARTe",
"type": "keyword",
"key": ["praise duarte"],
"case": false,
"channels": ["circlejerk"],
"process": "image('matias duarte', Math.floor(Math.random() * (19 - 0 + 1)) + 0, svrid, function(img) {imgur.upload(img, function(error, res) {if(error) {send = img;} else {send = res.data.link;}});});"
}
If you don't know who DuARTe is, head over to /r/acj
This extension type emulates regular bot commands. It can parse parameters from the full message content and supports data for the help section. The JSON file should include:
{
name: name of extension,
type: "command",
key: one-word command,
usage: (optional) parameters, e.g. "<param1> <param2>",
extended: (optional) detailed help for command extensions
channels: (optional) array of applicable channel names,
process: code to execute, as a string
}
You can use this website to stringify your code. The following example reimplements the bot's native twitter command:
{
name: "Twitter Reimplementation",
type: "command",
key: "extwitter",
usage: "<username>"
extended: "This command fetches a user's Twitter feed via RSS",
process: 'var suffix=message.substring(suffix.indexOf(" ")+1);if(suffix){var user=suffix.substring(0,suffix.indexOf(" "));var count=parseInt(suffix.substring(suffix.indexOf(" ")+1));if(user==""||!user||isNaN(count)){user=suffix;count=5}rss(svrid,"http://twitrss.me/twitter_user_to_rss/?user="+user,count,function(err,articles){if(err){send=author+" Twitter user `"+user+"` not found. Make sure not to include the `@`"}else{var info="";for(var i=0;i<articles.length;i++){var tmpinfo=articles[i].link+"\n"}send=info}})}else{send=author+" Please provide a Twitter username"}'
}
Useful for posting status updates, timer extensions are run periodically by the bot. They do not respond to messages and cannot parse input. Here's what the JSON file should look like:
{
name: name of extension,
type: "timer",
interval: timer interval in seconds,
channels: array of applicable channel names,
process: code to execute, as a string
}
Last updated for AwesomeBot v3.4.3 — http://awesomebot.xyz/