| View previous topic :: View next topic |
| Author |
Message |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Thu Mar 13, 2008 4:12 pm Post subject: |
|
|
| nml375 wrote: | Splitting a second time?
I think you are abit confused 'bout splitting...
Split converts a string to a list, $t is a string since it originates from the binding. Hence it should (must) be splitted prior being used with any commands expecting a list as a parameter. Using your code with a "reason" such as "evil user typing {" would illustrate how your script was broken, and how split is necessary.
A bad habit, in my opinion, is not bothering to keep track whether the content of a variable is a string or a list (always considder user input to be a string, never a list). |
you seem a bit confused about how lrange works
[lrange $x 0 end] may be used to force x to have list (as opposed to string) representation - this enhances performance in some situations. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Thu Mar 13, 2008 4:21 pm Post subject: |
|
|
| DragnLord wrote: | | nml375 wrote: | Splitting a second time?
I think you are abit confused 'bout splitting...
Split converts a string to a list, $t is a string since it originates from the binding. Hence it should (must) be splitted prior being used with any commands expecting a list as a parameter. Using your code with a "reason" such as "evil user typing {" would illustrate how your script was broken, and how split is necessary.
A bad habit, in my opinion, is not bothering to keep track whether the content of a variable is a string or a list (always considder user input to be a string, never a list). |
you seem a bit confused about how lrange works
[lrange $x 0 end] may be used to force x to have list (as opposed to string) representation - this enhances performance in some situations. |
| Quote: | NAME
lrange - Return one or more adjacent elements from a list
SYNOPSIS
lrange list first last
DESCRIPTION
List must be a valid Tcl list. This command will return a new list consisting of elements first through last, inclusive. First or last may be end (or any abbreviation of it) to refer to the last element of the list. If first is less than zero, it is treated as if it were zero. If last is greater than or equal to the number of elements in the list, then it is treated as if it were end. If first is greater than last then an empty string is returned. Note: ``lrange list first first'' does not always produce the same result as ``lindex list first'' (although it often does for simple fields that aren't enclosed in braces); it does, however, produce exactly the same results as ``list [lindex list first]'' |
just so we are clear here, both lrange and lindex work with lists, and want to have lists given to them, hence they begin with l.
Now, the difference between a string and a list is what is at issue here more than the commands. Because sure, anyone can use list commands on strings and string commands on lists. The problem is this isn't natural to do, so unexpected problems always arise, and must be compensated for.
Keep in mind, lists use curly bracing to denote list elements and fields. Strings do not. So any time you mistakenly give a list command a string with any curly braces in it, expect dilemma. Instead use [split $string] (this will protect the curly braces within the string from being interpreted as list elements or fields).
Instead of being arrogant and refusing to see that while your way is faster (not needing to split, indeed you save clock cycles). You need to see that it introduces more work later, extraneous filters and work arounds... |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Mar 13, 2008 4:41 pm Post subject: |
|
|
| DragnLord wrote: | | nml375 wrote: | Splitting a second time?
I think you are abit confused 'bout splitting...
Split converts a string to a list, $t is a string since it originates from the binding. Hence it should (must) be splitted prior being used with any commands expecting a list as a parameter. Using your code with a "reason" such as "evil user typing {" would illustrate how your script was broken, and how split is necessary.
A bad habit, in my opinion, is not bothering to keep track whether the content of a variable is a string or a list (always considder user input to be a string, never a list). |
you seem a bit confused about how lrange works
[lrange $x 0 end] may be used to force x to have list (as opposed to string) representation - this enhances performance in some situations. |
I considder myself quite well-versed when it comes to list operations, and would call the above a very ugly hack, that will only work with specially crafted strings. And even in this case, the output would be similar to split. split however, expects the input to be a string, and can handle any case, such as the one below:
| Code: | % set string "ad {dwer fva{ aer"
ad {dwer fva{ aer
% lrange $string 0 end
unmatched open brace in list
% lindex $string 2
unmatched open brace in list
% split $string
ad \{dwer fva\{ aer
%
|
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Thu Mar 13, 2008 5:13 pm Post subject: |
|
|
This has strayed far enough off topic.
As I have stated more then once in this topic already, coding before coffee is bad.
The entire idea behind this script is bad.
I never said the script was perfect, nothing ever is (or eggdrop and TCL would have both stopped at version 1.0).
I simply stated the script worked in my testing (at least I tested it).
While nicknames may contain braces (and/or other special characters), IP addresses may NOT contain those. And my script allows for using *@IP as a fall back target for nicknames with odd characters.
The "proper" answer to the original issue should be;
"If you trust your abuse team 100%, give them operator status that restricts them to banning commands (kline. gline, etc.). This can be done easily enough by creating a single oper and having the abuse team all use that single oper. Remember to carefully set exemptions." |
|
| Back to top |
|
 |
CyberWar Voice
Joined: 04 Feb 2008 Posts: 36
|
Posted: Fri Mar 14, 2008 3:05 am Post subject: |
|
|
Ok DragnLord
Well thank you to all here nice support now i know more about scripts and errors etc.
i will test it the script from DragnLord i think it works fine  |
|
| Back to top |
|
 |
CyberWar Voice
Joined: 04 Feb 2008 Posts: 36
|
Posted: Fri Mar 14, 2008 3:27 pm Post subject: |
|
|
Hi guys i have a script where works fine
One question when i make a gline i want that the bot write: Requested by $nick
this is my script
set eggver 1
| Code: | bind pub - !gline holm-pub_gline
proc holm-pub_gline {nick uhost hand chan text} {
set bantime "360m"
set knick [lindex $text 0]
set reason [lrange $text 1 end]
if ![matchattr $hand G|G $chan] {
putserv "NOTICE $nick :Access Denied"
return 0
}
if {$knick == ""} {
putserv "notice $nick :Usage: !gline <nick> <reason>"
return 0
} else {
putserv "gline $knick $bantime :$reason ([strftime %d-%m-%Y/%H:%M:%S])"
return 0
if {$reason == ""} {
putserv "PRIVMSG $chan :Requested by $nick"
}
}
} |
Look at the line: putserv "PRIVMSG $chan :Requested by $nick"
whats wrong?
i want the follow result e.g.
| Quote: |
[ ° ] Quits: root ( root@ps-C2EA4D2A.server4you.de ) has left irc [ User has been banned from blanet (test (14-03-2008/20:23:09)) ]
« Area51 » Requested by $nick
|
the Bot write atm nothing about: Requested by $nick |
|
| Back to top |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Fri Mar 14, 2008 4:13 pm Post subject: |
|
|
Hopefully this is what your after:
| Code: | bind pub G|G !gline pub:gline
proc pub:gline {nick host hand chan text} {
global lastbind
if {[set who [lindex [split $text] 0]] == ""} {
putserv "NOTICE $nick :Syntax: $lastbind <nick|host> ?bantime? ?reason?."
} else {
if {![regexp {[\d]{1,}(m|h|d|w|y)} [lindex [split $text] 1]]} {
set bantime "360m"
}
if {[set reason [lrange $text [expr {[regexp {[\d]{1,}(m|h|d|w|y)} [lindex [split $text] 1]] ? "2" : "1"}] end]]} {
set reason "Requested by $nick"
}
set time [strftime %d-%m-%Y/%H:%M:%S]
putquick "GLINE $who $bantime :$reason ($time)"
putserv "PRIVMSG $chan :Requested by $nick"
}
} |
_________________ r0t3n @ #r0t3n @ Quakenet |
|
| Back to top |
|
 |
CyberWar Voice
Joined: 04 Feb 2008 Posts: 36
|
Posted: Fri Mar 14, 2008 4:25 pm Post subject: |
|
|
This script does not work. My script version works fine, but he dont make a msg to the channel when i make a gline. i want that my script make a msg to the channel when i maked a gline.
e.g.: BotNick: Requested by $nick |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Fri Mar 14, 2008 11:22 pm Post subject: |
|
|
| You want the message to go to the channel that the script is called from, or do you want the message to go to a specific channel regardless of where it's called from? |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Sat Mar 15, 2008 2:33 am Post subject: |
|
|
| I think this script will do what you want. If it doesn't, let me know. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|