3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-29 06:02:39 +01:00
dbot/modules/command
Douglas Gardner a53eb5e0d2 begin transition from English to ISO-639 with #234
This patch converts all English language strings used within
depressionbot's localisation interface (that is, strings.json) to their
ISO-639-1 equivalents.

The purpose of this patch is to make the strings.json file less
English-dependent.

All languages with an ISO-639-1 code have been converted; that is,
English, Spanish and Welsh, to ``en``, ``es`` and ``cy`` respectively.

This patch does not attempt to force a solution to the issue of Na'vi:
the language does not have a large enough corpus to warrant its own ISO
639-3 code, and as such there is no perfect solution. For the time
being, this patch keeps the Na'vi language as its English language
string ("Na'vi"). A possible solution to this discrepancy includes using
the ISO 639-3 code ``art``, used for artificial languages that do not
qualify for an official code, or by using local use codes specified
in ISO 639-3 (qaa to qtz).

This patch requires collaboration with upstream repositories that also
use strings.json, such as the Github and Stats modules.
2013-02-12 18:39:15 +00:00
..
api.js Add check for channel ignorance in command execution logic [#190] 2013-01-27 16:48:14 +00:00
command.js Add check for channel ignorance in command execution logic [#190] 2013-01-27 16:48:14 +00:00
commands.js Much better! [#131] 2013-01-14 16:24:38 +00:00
config.json remove useless crap from modules [#136] 2013-01-15 16:54:51 +00:00
README.md Add check for channel ignorance in command execution logic [#190] 2013-01-27 16:48:14 +00:00
strings.json begin transition from English to ISO-639 with #234 2013-02-12 18:39:15 +00:00

Command

Handles the command execution logic for DBot.

Description

Command flow:

  1. Does the input match a command key in the loaded commands?
    • If command not found and quotes is loaded, attempt to print quote of given command name
  2. Is the user banned from running the given command?
  3. Is the user ignoring the command?
  4. Is the channel ignoring the command?
  5. Does the use have the access level to run the command?
  6. Is the command set as disabled?
  7. Apply regex to the command, pass into event object.
    • If regex does not apply, show usage info.
  8. Run the command.

This is the only module which is force loaded, even if its not specified in the configuration file.

Commands

~usage command

Show usage information for a given command.

~help [command|module]

Link module help for a module given either the module name or the name of a command belonging to a module.

API

isBanned(user, command)

Return whether a user is currently banned from a given commands.

hasAccess(user, command)

Return whether a user has the access level (moderator, admin) to run a given command.

isIgnoring(user, command)

Return whether a user is currently marked as ignoring a given command.

addHook(command, callback)

This API function allows you to hook functions into DBot commands. For example, you may add a hook to post on Identica when a new quote is added to the database with the ~qadd command. As a less useful example, here is how you might add a hook to log to the console every time someone uses the reload command:

dbot.api.command.addHook('reload', function() {
    console.log('Reload run!');    
});

Hook arguments are populated by the return values of the functions they are hooked into, and command hooks are not run if the command explicitly returns false. For example, the ~qadd command returns [ key, quote ], and the hook function will be called with these variables given in the order they were returned, so you would retrieve the key and the quote from a hook to ~qadd like this:

dbot.api.command.addHook('~qadd', function(key, quote) { ...

The best place to add hooks to commands is in the onLoad function of your module, as this ensures it will be run while all other modules are loaded. If the target command does not exist (for example if its module was not loaded), the hook will not be added and no errors will be thrown.