Factoids Plugin

This plugin adds a way of storing standard responses for common queries.

It has no required dependencies, but optionally depends on the admin role/plugin. Just make sure that you load the admin role/plugin before you load this plugin. If you just pass the plugin names to the configuration, make sure this plugin is after the admin role/plugin.

The database is a Dirty db, choosen because it requires no binary parts or starting a remote server. If you want to use something else, the plugin could be changed to accomodate. File an issue.

The bot will listen to private messages, and when it sees a private message that matches a factoid key, the bot will respond with the description that matches the key. You can add a trigger that must prefix the key with configuration.

Configuration

factoids-database
Required String. A relative path from the current working directory to the location of the factoids database. Will use an in-memory database if an empty string is given.
factoids-trigger
Optional String. Only messages that start with the trigger will look up factoids.
factoids-max-alias-depth
Optional Number. Maximum (integral) aliases to dive into before giving up. Defaults to 3.
factoids-safe-replace
Added in v5.1.0. When enabled, users cannot use =, :=, !=, or @= to replace a factoid that already exists. Instead they must either use f= (to replace =) or !forget and then teach the new factoid. Used to make sure users don't accidentally rewrite factoids. By default, disabled.

Commands

!factoid <factoid-name>

Look up a factoid by the specified name.

Failure to find a factoid will be reported.

!learn <factoid-name> = <factoid-description>

Learn a factoid by the name of the factoid. This will also add the time and hostmask of the editor to the database.

You can also use other operators than just =.

!=

Make the factoid response an action.

Ex:

[user] !learn dance != does a jig.
[bot] Learned factoid 'dance'.
[user] !dance
* bot does a jib

:=

Define a term by prefixing the response with the key and the word is. The case of the key matters.

Ex:

[user] !learn Moon := a place made out of cheese.
[bot] Learned factoid 'moon'.
[user] !moon
[bot] Moon is a place made out of cheese.

@=

Aliases the key on the left to the key on the right.

Note: The alias is not smart, and if the key it aliases doesn't exist, it'll being aliasing nothing.

Note: Modifying this factoid with += or ~= modifies what key this is aliasing, the the response itself.

+=

Appends more to the description of a factoid. The factoid must already exist.

Ex:

[user] !math
[bot] 2 + 2 = 4. 2 * 3 = 6.
[user] !learn math += 10 - 7 = 3.
[bot] Successfully did replacement on 'math'
[user] !math
[bot] 2 + 2 = 4. 2 * 3 = 6. 10 - 7 = 3.

~= s/search/replace/flags

Does a sed-style search and replace on the description. The search is a JavaScript regular expression. The replace is a string. To use a "/" in either search or replace, use "\/". If you don't know regular expressions, you should not use this variant except for literal to literal translations using only alphanumeric, spaces, and periods.

The flags are either "", "g", "i", or "gi".

f= or F=

Force sets a factoid. As = but allows rewriting if safe-replace is enabled.

If the factoid is locked, you must be an admin to be able to edit it.

!forget <factoid-name>

Removes the factoid from being able to be looked up. The editor and time of deletion are stored in the database.

If the factoid is locked, you must be an admin to be able to forget it.

!lock <factoid-name>
Locks a factoid so that only an admin can create and edit it. You must be an admin to use this command.
!unlock <factoid-name>
Removes a lock from a factoid. You must be an admin to use this command.
!factoid-metadata <factoid-name>
Returns metadata about the factoid. Specifically its kind (action, say, alias, deleted, never existed), last editor, last edit time, and for aliases - what it aliases to.

Source

GitHub