Skip to content
BitQuote edited this page Apr 25, 2016 · 25 revisions

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.

Extension Resources

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
  • gif: Giphy search, usage gif(query, callback(url), rating)
  • image: Google Image Search, usage image(query, num, svrid, chid, callback(url))
  • rss: feed-read module, usage rss(svrid, url, svrid, callback(err, articles))
  • message: (not included for timer extensions) full content of the message
  • svr: { name: name of the server you're in, id: Discord ID of the server you're in, icon: URL for server icon, may be null }
  • ch: { name: name of the channel you're in, id: Discord ID of the channel you're in }
  • author: (not included for timer extensions) { username: name of sender, id: Discord ID of sender, icon: URL for user avatar, may be null }
  • selected: (for keyword extensions only) the index of the match in the key array
  • prettyDate: provide a Date object, returns nicely formatted string
  • secondsToString: provide n seconds, returns nicely formatted string
  • setTimeout, JSON, Math, isNaN, Date, Array, Number
  • store: an Array where you can save data
  • 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

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, svr.id, ch.id, 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

Command Extensions

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"}'
}

Timer Extensions

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
}

Clone this wiki locally