Closed chr-1x closed 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.
alias_keys
and each Alias->keys
, I think this could be simplified by just turning alias_keys
into a char***
and not storing the list of keys inside the Alias struct. 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.
alias_delete
, since it calls sb_erase
on the pool which will shift all the aliases that follow it down by 1, but the offsets are not updated to reflect this.I merged it with the changes I talked about made, not sure how to let GitHub know that this was merged manually...
mod_alias has been expanded to more complicated alias handling. Alias data format has been changed. Instead of two arrays:
There are now three:
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.
alias_new
allocates an alias from the pool and initializes the fields of the alias, as well as pushing on a new key at the same time.alias_delete
will attempt to delete an alias from the alias_pool, but will not do so if the alias still lists at least one key in itskeys
field.alias_remove_reference
will remove a key from an Alias'skeys
list, and if this was the last reference to the Alias, delete it by callingalias_delete
.alias_update
changes themsg
andperm
values of an Alias, allowing you to specify whether it should create an entirely new Alias if doing so would change the values of other Aliases. The current !alias handling code always opts to preserve the values of other references, and will thus always create a new Alias if there are other references.alias_add_reference
specifies that an Alias has a new key referencing it,newkey
. Ifnewkey
already pointed to an alias, it removes that reference before adding a reference to the new target Alias.alias_add
attempts to create a new alias with the given key, message, and permission unless the given key already exists, in which case it callsalias_update
with the provided information.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:
The new format:
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:
!alias
now special cases a certain string format which specifies that key1 should be a reference to key2:!alias key1 -> key2
!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.