baines / insobot

C99 modular IRC bot with markov chains
MIT License
74 stars 5 forks source link

Expand mod_alias to support alias permissions, multiple triggers, /me aliases #2

Closed chr-1x closed 8 years ago

chr-1x commented 8 years ago

mod_alias has been expanded to more complicated alias handling. Alias data format has been changed. Instead of two arrays:

char** alias_keys;
char** alias_values;

There are now three:

char** alias_keys;
int* alias_val_offsets;
Alias* alias_pool;

When a new alias is created, it is pushed onto the alias pool. The val_offset corresponding to an alias key specifies which value in the alias_pool to reference -- it's not a direct pointer, as the pointers to Aliases in the alias_pool are unstable (stretchy_buffer). This way multiple alias_keys can point to the same Alias in the pool.

Several new functions have been added to help deal with manipulating these structures.

Parsing of the log file on init has been expanded to support a new data format, which is written out on save. The parser is backwards-compatible with the old alias format, though the format is not. The old format:

 key Some message here.

The new format:

[key1 key2 key3 ]:PERMISSION Some message here.

PERMISSION must be specified and a valid permission string (current NORMAL, WLIST, or ADMIN), or it will drop to old-format parsing and read incorrect values for the keys. A future patch could address this by making the permission string optional, potentially at the expensive of slightly more verbose parsing.

The IRC-level command interface has not changed significantly, with two exceptions:

  1. !alias now special cases a certain string format which specifies that key1 should be a reference to key2:

    !alias key1 -> key2

  2. !chaliasmod, which changes the permission of an alias to one of "normal", "wlist", or "admin".

    !chamod key wlist

Finally, alias messages that being with the string "/me" will automatically be converted into CTCP ACTION messages upon sending. If a future revision of the core bot adds support for CTCP messages, this module should be updated to use that.

insofaras commented 8 years ago

Thanks, this is a nice increase in functionality.

There are a couple of things I would change about the implementation before merging it though. I'm happy to make these changes myself.

This would also mean there would be no need for alias_val_offsets, since they would map 1:1 like they currently do.

In the latter case, it's possible to use the fact that alias keys are always saved in lowercase to differentiate them from the permission, so the format could become:

(<alias_key> <space>)+ <PERMISSION> <space> <alias_text>

which doesn't need to use any special chars like [ ] or : to delimit stuff, so the keys could still contain them.

insofaras commented 8 years ago

I merged it with the changes I talked about made, not sure how to let GitHub know that this was merged manually...