| View previous topic :: View next topic |
| Author |
Message |
Nara Halfop
Joined: 23 Jul 2006 Posts: 40
|
Posted: Sat Nov 11, 2006 9:24 am Post subject: Does utimer/timer have to be a proc or can it be like an if? |
|
|
Alright - just a quick q, no script. See topic.
~Nara |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Nov 11, 2006 1:37 pm Post subject: |
|
|
(u)timer takes two arguments, the time to delay, and <tcl-command>
That is, anything in <tcl-command> will be executed by the tcl-interpreter once the delay has passed. You'll have to remember that this will be run in globalspace, and not the namespace occupied by the proc that called it (if any).
Also, keep in mind the ways the tcl-interpreter operates, especially the variable- and command substitutions.
The two snippets below look quite similar, yet behave quite differently (both assumed to be run in globalspace)
| Code: | timer 10 [list puthelp "PRIVMSG #mychannel :I'm $botnick"]
timer 10 [list puthelp {PRIVMSG #mychannel :I'm $botnick}] |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sat Nov 11, 2006 3:30 pm Post subject: |
|
|
| Yes, it can be run from an if test within the global space, as nml said, of a script (eg, outside of a proc) |
|
| Back to top |
|
 |
Nara Halfop
Joined: 23 Jul 2006 Posts: 40
|
Posted: Sat Nov 11, 2006 6:26 pm Post subject: |
|
|
Alright, here's what I'm doing:
I'm doing a warning script within my ads/kicks, and this is the script I plan on using. Will this work or will it need mods?
| Code: | bind pub - * battle:mainchan
proc battle:warnnick {nick host hand chan text} {
putserv "NOTICE $nick :You almost stepped on a landmine there Mr. Rock star. check out @rockrules and @advertising"
}
proc battle:mainchan {nick host hand chan text} {
global text1 text2 mainchan
set chan [string tolower $chan]
if {[string equal $chan $mainchan]} {
set text [stripcodes bcruag $text]
if {[string match -nocase "text1" $text] || [string match -nocase "text2" $text} {
return 0
} elseif {[string match -nocase "#" $text] || [string match -nocase "www" $text] || [string match -nocase ".com" $text] || [string match -nocase ".net" $text] || [string match -nocase ".org" $text] || [string match -nocase "http" $text]} {
battle:warnnick nick host hand chan text
if {$nick.warned == 1} {
putserv "PRIVMSG Chanserv :$mainchan addtimedban $nick 3m Ads"
set $nick.warned 0
} else {
set $nick.warned 1
timer 60 if {$nick.warned == 1} {set $nick.warned 0}
}
} else {
return 0
}
}
} |
~Nara |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Nov 11, 2006 6:59 pm Post subject: |
|
|
It will need some modifications..
First of all, (u)timer take two arguments, of which one is the delay..
| Code: | | timer 60 if {$nick.warned == 1} {set $nick.warned 0} |
has 4 arguments == 2 too many...
Would have to be changed into something like this:
| Code: | | timer 60 [list if {$nick.warned == 1} {set $nick.warned 0}] |
However, this will only work as expected if $nick.warned is a variable in globalspace, as this code snippet is not run within the environment of of the proc... Also, since the code includes a variable controlled by users, there's the risk of code injection (changing nick to foo[die]bar might get ugly if proper encapsulations are not in place)..
There's a few more things to considder, that I'll get to alittle later this evening
edit:
The main problem with your code above is the $nick.warned variable. You mix using it as a proc-local variable and a globalspace variable, without using "global" or any other means of accessing globalspace variables from proc's..
Since you wish to use dynamic variable names, this gets alittle messier..
Also due to the same reason, you really should test wether the variable actually exists before you try to use it (even in if-conditionals)
Finally, using a dot "." in your variable name will cause problems with conditional statements, considder using a different separator-char or named arrays (also solves the problem with dynamic variable names) _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Nov 12, 2006 1:11 am Post subject: |
|
|
Ohh my..is that the entire script? Cos..it's wrong in a lot of places..Starting with:
bind pub - * battle:mainchan
if you want a trigger to work on any possible input, you need to use pubm, which accepts wildcards, bind pub does not.
Where are the text1 and text2 global vars defined? They're not in the script as posted..
"string match" needs wildcards like
string match -nocase "*.com*" $text
unless you anticipate an exact match (just .com in the $text var)
text input from users should be split, [split $text] to make it safe, many functions will choke on tcl-special chars, otherwise. Read: http://www.peterre.com/characters.html
And actually, instead of using string match so much, and since you'd be wise to [split $text] you'd prolly be better off using lsearch to compare lists, like for your channel check:
in the global space:
set mychans "#mychan #chan2 #etc"
then within the pub (or pubm)q proc:
| Code: |
proc whatever {nick uhost hand chan text} {
global mychans
if {[lsearch -exact $mychans $chan]} {
#this is a matching channel
# do stuff
} else {
# this is not a match
# return
}
|
Using [split] creates a list, on which you can use lsearch, lindex, lrange, lreplace, etc.
As for the timer, I'd make a seperate proc to run the test in. You'd need to set a global var to pass to the other proc as well, so within your
proc battle:mainchan, make nickwarned a global var, add it to the list of global vars at the beginning of the proc, then have it set by the proc. Also within the proc battle:mainchan you set your timer:
timer 60 [list someproc $nick]
Then when your timer runs the seperate proc for testing, you add that nickwarned var as a global there too:
| Code: |
proc someproc {nick}
global nickwarned
if {$nick.warned == 1} {set $nick.warned 0}
}
|
|
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun Nov 12, 2006 12:09 pm Post subject: |
|
|
You need to create not a variable, but an array. A global array. For example:
| Code: | proc bla {nick uhost hand chan} {
global warned
# ...etc
set warned($nick) 0
timer 60 [list blo $nick]
}
proc blo nick {
global warned
if {$warned($nick) == 1} { set warned($nick) 0 }
} |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Sun Nov 12, 2006 12:25 pm Post subject: |
|
|
I think you mean
| Code: | | set warned($nick) 1 | in the first proc  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun Nov 12, 2006 12:30 pm Post subject: |
|
|
I noticed it, but didn't edit it. After all, it's just an example  _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Nara Halfop
Joined: 23 Jul 2006 Posts: 40
|
Posted: Sun Nov 12, 2006 8:16 pm Post subject: |
|
|
Alright - here's what I'm trying to do, so help me out here.
This is an anti-ad script. I already fixed the wildcard and the bind [mistakes from coding all of this in under 2 minutes].
It needs to have a warning system, hence the $nick.warned stuff. I need a good way to store all nicks that are warned and then permit me to run them all through hourly. [probably with a bind time for hourly if it can be put into a protocol?] |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun Nov 12, 2006 8:18 pm Post subject: |
|
|
Store them in an array (as I showed you above). _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Nara Halfop
Joined: 23 Jul 2006 Posts: 40
|
Posted: Sun Nov 12, 2006 8:32 pm Post subject: |
|
|
| Sir_Fz wrote: | | Store them in an array (as I showed you above). |
Then where does the list of nicks to check come from? [I never got much experience in lists and while loops, so if you could help, I'd most appreciate.]
~Nara |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun Nov 12, 2006 10:22 pm Post subject: |
|
|
"array names" is your friend here; returns a list of all the keys in a speciffic array.
Something like this I suppose:
| Code: | proc test_nicks {} {
global warned
foreach nick [array names warned] {
if {$warned($nick) == 1} {
#evil spammer
}
}
} |
Modify to suit your needs _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|