Add chanset bind
Patch by: Geo Fixes: #1393
This PR adds a bind that triggers when a channel setting is set via the chanset partyline command.
Single setting:
.tcl bind chanset * greet foo
Tcl: greet
.tcl proc foo {chan setting value} {putlog "omg! $setting on $chan was set to $value!"}
Tcl:
.chanset #eggdroptest +greet
[06:27:28] omg! greet on #eggdroptest was set to +!
Successfully set modes { +greet } on #eggdroptest.
[06:27:28] #-HQ# chanset #eggdroptest +greet
Mask bind:
.tcl bind chanset * * foo
Tcl: *
.tcl proc foo {chan setting value} {putlog "omg! $setting on $chan was set to $value!"}
Tcl:
.chanset #eggdroptest +greet flood-chan 3:30 +revenge
[06:30:26] omg! greet on #eggdroptest was set to +!
[06:30:26] omg! flood-chan on #eggdroptest was set to 3:30!
[06:30:26] omg! revenge on #eggdroptest was set to +!
Successfully set modes { +greet flood-chan { 3:30 } +revenge } on #eggdroptest.
[06:30:26] #-HQ# chanset #eggdroptest +greet flood-chan { 3:30 } +revenge
Multi-chan binds:
.chanset * +greet
[06:31:11] omg! greet on #eggdroptest was set to +!
[06:31:11] omg! greet on #foo was set to +!
Successfully set modes { +greet } on all channels.
[06:31:11] #-HQ# chanset * +greet
We should use the return value of the Tcl proc to deny the change as invalid. That could be in a new PR, but it is one of the main reasons for the bind, so you can reject a "setudef str" value if it's not valid for your use-case.
Added @thommey great suggestion:
.tcl proc foo {chan setting value} {putlog "Nope!"; return 1}
Tcl:
.tcl bind chanset * bitch foo
Tcl: bitch
.chaninfo #eggtest
Settings for dynamic channel #eggtest:
<snip>
-bitch -autoop -autovoice -nodesynch
<snip>
.chanset #eggtest +bitch
[15:13:32] Nope!
.chaninfo #eggtest
Settings for dynamic channel #eggtest:
<snip>
-bitch -autoop -autovoice -nodesynch
Updated logic to allow other chanset values submitted in a single command that don't match the bind to proceed
Using the same proc/bind as above:
.chanset #eggtest +inactive +bitch +seen
[03:19:16] Nope!
Successfully set modes { +inactive +seen } on #eggtest.
[03:19:16] #-HQ# chanset #eggtest +inactive +seen
Note +bitch was not set, but other values in the chanset command were. One more example that involves the other call to check_tcl_chanset():
.tcl bind chanset * need-op foo
.chanset #eggtest +seen need-op hi
[03:30:16] Nope!
Successfully set modes { +seen } on #eggtest.
[03:30:16] #-HQ# chanset #eggtest +seen