Setudef: Difference between revisions
(Initial commit) |
(Finish setudef) |
||
Line 2: | Line 2: | ||
== User-defined Channel Flags (Preferred) == | == User-defined Channel Flags (Preferred) == | ||
=== Adding a channel flag === | |||
From [https://docs.eggheads.org/using/tcl-commands.html doc/tcl-commands.doc], you can use the [https://docs.eggheads.org/using/tcl-commands.html#setudef-flag-int-str-name setudef command]: | From [https://docs.eggheads.org/using/tcl-commands.html doc/tcl-commands.doc], you can use the [https://docs.eggheads.org/using/tcl-commands.html#setudef-flag-int-str-name setudef command]: | ||
<pre> | <pre> | ||
Line 29: | Line 30: | ||
User defined channel flags: | User defined channel flags: | ||
+myscript | +myscript | ||
</pre> | |||
=== Checking a channel flag === | |||
So now that you've added a channel flag that the user can interact with, how does a script use that information? The answer is the [https://docs.eggheads.org/using/tcl-commands.html#channel-get-name-setting channel get] Tcl command. | |||
<pre> | |||
channel get <name> [setting] | |||
Returns: The value of the setting you specify. For flags, a value of 0 means it is disabled (-), and non-zero means enabled (+). If no setting is specified, a flat list of all available settings and their values will be returned. | |||
</pre> | |||
To check if a flag is enabled for a flag, you would use: | |||
<pre> | |||
channel get #test myscript | |||
</pre> | |||
Or, perhaps a more useful example: | |||
<pre> | |||
if [channel get #test myscript] { | |||
putserv "PRIVMSG #test :This is a message that is only sent if the myscript flag is enabled" | |||
} | |||
=== Example Tcl script === | |||
So now, let's write a simple greet script that can be turned on and off via the partyline for each channel: | |||
<pre> | |||
bind join * * greetNewUser | |||
setudef flag greetScript | |||
proc greetNewUser{nick user hand chan} { | |||
if {[channel get $chan greetScript]} { | |||
putserv "PRIVMSG $chan :Hello $nick, welcome to $chan!" | |||
} | |||
} | |||
</pre> | </pre> |
Revision as of 22:55, 29 August 2022
Eggdrop users often like a script's functionality to work on only some of the channels the Eggdrop resides on. For example, an Eggdrop running a Tcl script that greets every user is nice on a small channel, but would quickly become annoying on a busy channel where users are joining every 30 seconds. There are two ways you can enable a script to work on only some channels the Eggdrop resides on.
User-defined Channel Flags (Preferred)
Adding a channel flag
From doc/tcl-commands.doc, you can use the setudef command:
setudef <flag/int/str> <name> Description: initializes a user defined channel flag, string or integer setting. You can use it like any other flag/setting. IMPORTANT: Don’t forget to reinitialize your flags/settings after a restart, or it’ll be lost.
This command creates a new flag setting that can be used via the
.chanset
command, and viewed via the
.chaninfo
command. To create a custom flag that a script can check, create it by adding the setudef command:
setudef flag myscript
This will add a flag that can be viewed, enabled or disabled via the partyline:
User defined channel flags: -myscript
As with any other Eggdrop channel flag, it can be enabled or disabled with the .chanset command:
.chanset #test +myscript Successfully set modes { +myscript } on #test. [22:42:18] #-HQ# chanset #test +myscript .chaninfo #test User defined channel flags: +myscript
Checking a channel flag
So now that you've added a channel flag that the user can interact with, how does a script use that information? The answer is the channel get Tcl command.
channel get <name> [setting] Returns: The value of the setting you specify. For flags, a value of 0 means it is disabled (-), and non-zero means enabled (+). If no setting is specified, a flat list of all available settings and their values will be returned.
To check if a flag is enabled for a flag, you would use:
channel get #test myscript
Or, perhaps a more useful example:
if [channel get #test myscript] { putserv "PRIVMSG #test :This is a message that is only sent if the myscript flag is enabled" } === Example Tcl script === So now, let's write a simple greet script that can be turned on and off via the partyline for each channel: <pre> bind join * * greetNewUser setudef flag greetScript proc greetNewUser{nick user hand chan} { if {[channel get $chan greetScript]} { putserv "PRIVMSG $chan :Hello $nick, welcome to $chan!" } }