|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Hi, I've posted before about an old nick tracking script that I wrote, but I'm now working on a new one. I'm having some problems where it's making a new entry in the text file like the nick or address isn't already there, when it is. I'm changing a few of the words in the script to generic terms, just for personal reasons, but it won't affect the script. Here's the code.
on 1:JOIN:#Chat: {
{ set -u5 %owner.chan $chan }
{ set %defaultqmsg my quit message
{ set %join.address. [ $+ [ $nick ] ] $address }
{ set %join.compaddress. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$address) }
{ set %join.compnick. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$nick) }
{ set %join.time. [ $+ [ $nick ] ] $mid($ctime,2,8) }
{ set %join.newnick. [ $+ [ $nick ] ] , $+ $nick %join.time. [ $+ [ $nick ] ] }
{ set %join.bothnew. [ $+ [ $nick ] ] $address $+ , $+ $nick %join.time. [ $+ [ $nick ] ] }
if (word1* iswm $nick) {
if (%join.address. [ $+ [ $nick ] ] = %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4$nick | unset *. $+ $nick }
else { echo 4 -a No Match $nick | unset *. $+ $nick }
}
elseif (word2* iswm $nick) {
if (%join.address. [ $+ [ $nick ] ] = %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4$nick | unset *. $+ $nick }
else { echo 4 -a No Match $nick | unset *. $+ $nick }
}
elseif (%join.address. [ $+ [ $nick ] ] = %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4$nick | goto NickEval }
else { write C:\mirc\nicks.txt %join.bothnew. [ $+ [ $nick ] ] | unset *. $+ $nick | echo 4 -a $nick is a new entry }
halt
:NickEval
if ($nick = %join.compnick. [ $+ [ $nick ] ]) { .notice $me Nick Match 4$nick | write -al %join.compaddress. [ $+ [ $nick ] ] C:\mirc\nicks.txt %join.newnick. [ $+ [ $nick ] ] | unset *. $+ $nick }
else { write -al %join.compaddress. [ $+ [ $nick ] ] C:\mirc\nicks.txt %join.newnick. [ $+ [ $nick ] ] | unset *. $+ $nick }
}
on 1:NICK: {
{ set %nick.address. [ $+ [ $newnick ] ] $address }
{ set %nick.compaddress. [ $+ [ $newnick ] ] $read(C:\mirc\nicks.txt,w,$address) }
{ set %nick.compnewnick. [ $+ [ $newnick ] ] $read(C:\mirc\nicks.txt,w,$newnick) }
{ set %nick.newnick. [ $+ [ $newnick ] ] , $+ $newnick %join.time }
{ set %nick.nicktime. [ $+ [ $newnick ] ] $mid($ctime,2,8) }
{ set %nick.bothnew. [ $+ [ $newnick ] ] $address $+ , $newnick %nick.nicktime. [ $+ [ $newnick ] ] }
if ($newnick = %nick.compnewnick. [ $+ [ $newnick ] ]) { .notice $me $newnick found-not writing | unset *. $+ $newnick }
elseif (%nick.address. [ $+ [ $newnick ] ] = %nick.compaddress. [ $+ [ $newnick ] ]) { write -al %nick.compaddress. [ $+ [ $newnick ] ] C:\mirc\nicks.txt | .notice $me new nick old address | unset *. $+ $newnick }
else { write C:\mirc\nicks.txt %nick.bothnew. [ $+ [ $newnick ] ] | unset *. $+ $newnick | echo 4 -a $newnick is a new entry }
}
Thanks for any help.
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Hi,
I just tried changing all the "set"s to "var %name =". I noticed for one thing that %join.compaddress.nick never seems to be getting set. So far, changing to var didn't seem to help anything.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
I'm not sure if this is the problem, but in this line:
{ set %join.compaddress. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$address) }
There are no wildcards given in $read. Maybe try it like this:
set %join.compaddress. [ $+ [ $nick ] ] $read(file.txt,w,* $+ $address $+ *)
A few other things:
- In an IF/WHILE comparison, you should use double equal-signs == for a case-insensitive match (as opposed to a single equal-sign like you have).
- You can't put a control code (or any other text) directly next to an identifier. You have 4$nick which would display literally this: $nick
- It is usually easier to read code when each command is on its own line instead of using the pipe "|" to put multiple commands on one line.
- You don't need the { } surrounding every line.
- If the global variables (/set %var value) you use in those events don't need to be kept for use in other event (other events where those variables can't be set again), then you should use local variables (/var %var = value) instead. And if that is the case, then you don't need to use dynamic variables (%var. [ $+ [ $nick ] ]) either. Each local variable gets its own namespace (assuming there isn't already a global variable with the same name) so they will not conflict with each other.
-genius_at_work
Last edited by genius_at_work; 12/01/06 11:18 PM.
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Thanks for the suggestions. I tried changing to var and nothing ended up getting set. I have it back to set and the only thing not getting set are the %join.compaddress. [ $+ [ $nick ] ] and %nick.compaddress. [ $+ [ $nick ] ]. I'm thinking that it's not reading the address in the line when it uses the $read command. Thanks for any help.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
I'm not sure of exactly what you need the text file to look like, but you can try this:
on *:JOIN:#chat:nicktrack $nick
on *:NICK:nicktrack $newnick
;
alias nickfile return nicks.txt
alias nicktrack {
var %nick = $1
var %readaddr = $iif($read($nickfile,w,$address $+ *),$v1)
;
if (%readaddr) {
write -dl $+ $readn $nickfile
[color:red]; *** Found a matching address ***[/color]
;
[color:blue]; *** Your special cases here:
if (genius* iswm %nick) .notice $me Address Match for nick: %nick
elseif (word2* iswm %nick) .notice $me Address match for nick: %nick[/color]
}
else {
[color:red]; *** Did not find matching address ***[/color]
%readaddr = $address
}
;
if (*, $+ %nick * !iswm %readaddr) {
[color:red]; *** Found matching nick in list ***[/color]
%readaddr = %readaddr $+ , $+ %nick $right($ctime,-2)
}
else {
[color:red]; *** Did not find matching nick in list ***[/color]
}
write $nickfile %readaddr
}
Since onNICK and onJOIN events have different nickname identifiers, the nickname is stored in a variable called %nickYou can add any echo's or notices as necessary in place of the red textYou seemed to have special cases in your original code. They can be added in place of the blue text.
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Hi,
I originally posted that the only variable being set was %join.time.PersonsNick, because that's the only variable that was showing up with any value in the variables tab. I just checked the text file and it is writing address and nick entries, which must mean that the %join.bothnew variable is getting set. Can someone explain why I never see the other variables set? Also, I still need to figure out how to get $read working so it can find the address in the text file of the person who joined or changed their nick. Currently, it is treating every join and nick change like it hasn't found the address and is a new entry. Thanks.
Last edited by bwr30060; 13/01/06 01:56 AM.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
The reason you can't see any variables is because they are being unset when you use this command:
unset *. $+ $nick
In your code, you are using global variables when they are not necessary. Also, you are using the $read command incorrectly.
The code I posted above should do what you want, or at least what I could interpret from the code you posted.
-genius_at_work
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
I took out all my unsets, so that shouldn't be a problem. Also, I've used $read like this before and it has worked. That's why it's confusing me this time.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
If the address is the only thing on the line, then the way you coded it would work. However, since you have other text on the line with the address, you need to use wildcard characters.
$read(filename.txt,w,$address $+ *)
I believe I mentioned that before...
-genius_at_work
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
I am using wildcard characters. Right now, that line is:
set %join.compaddress. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,s,* $+ $address $+ *)
I've tried it with s and w both using wildcard characters and it doesn't work.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
and can you post a sample of nicks.txt that you are currently using?
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
A line of the text file looks like this: *!*@whatever-A4341B25.asm.bellsouth.net,Blake 13717732
I've made a bunch of changes to the script, so I'll repost what it is now. [code] on 1:JOIN:#: { set %addlength. [ $+ [ $nick ] ] $len($wildsite) set -u5 %owner.chan $chan set %defaultqmsg my quit message set %join.address. [ $+ [ $nick ] ] $wildsite set %join.precompadress. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$wildsite $+ *) set %oldaddress $readn set %join.compaddress. [ $+ [ $nick ] ] $left(%join.precompadress. [ $+ [ $nick ] ],%addlength. [ $+ [ $nick ] ]) set %join.compnick. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$nick $+ *) set %oldnick $readn set %join.time. [ $+ [ $nick ] ] $mid($ctime,2,8) set %join.newnick $chr(44) $+ $nick %join.time set %join.bothnew $wildsite $+ $chr(44) $+ $nick %join.time. [ $+ [ $nick ] ] if (whatever1* iswm $nick) { if (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4 $nick } else { echo 4 -a No Match $nick } } elseif (whatever2* iswm $nick) { if (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4 $nick } else { echo 4 -a No Match $nick } } elseif (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4 $nick | goto NickEval } else { write C:\mirc\nicks.txt %join.bothnew | echo 4 -a $nick is a new entry } halt :NickEval if ($nick = %join.compnick. [ $+ [ $nick ] ]) { .notice $me Nick Match 4 $nick | write -l %oldnick %join.newnick C:\mirc\nicks.txt } else { write -l %oldaddress %join.newnick C:\mirc\nicks.txt } } on 1:NICK: { set %addlength. [ $+ [ $newnick ] ] $len($wildsite) set %nick.address. [ $+ [ $newnick ] ] $wildsite set %nick.precompaddress. [ $+ [ $newnick ] ] $read(C:\mirc\nicks.txt,w,$wildsite $+ *) set %oldaddress $readn set %nick.compaddress. [ $+ [ $newnick ] ] $left(%nick.precompaddress. [ $+ [ $newnick ] ],%addlength. [ $+ [ $newnick ] ]) set %nick.compnewnick $read(C:\mirc\nicks.txt,w,$newnick $+ *) set %oldnick $readn set %nick.newnick $newnick %join.time. [ $+ [ $nick ] ] set %nick.nicktime $mid($ctime,2,8) set %nick.bothnew $wildsite $+ $chr(44) $+ $newnick %nick.nicktime if ($newnick == %nick.compnewnick) { .notice $me $newnick found } elseif (%nick.address. [ $+ [ $newnick ] ] == %nick.compaddress. [ $+ [ $newnick ] ]) { write -l %oldnick $chr(44) $+ $newnick %nick.nicktime C:\mirc\nicks.txt | .notice $me new nick old address } else { write C:\mirc\nicks.txt %nick.bothnew | echo 4 -a $newnick is a new entry } } on 1:QUIT: { unset *. $+ $nick }
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Hi,
I have this script figured out now. There are more things that I'd like to add, like a check to make sure the variable won't be too long, and to delete old nicks as necessary, but I'll post the end result so far. This is just the basic part to get it to write the nicks and addresses in the format I want. Thanks for your help. [code] on 1:JOIN:#: { set %addlength. [ $+ [ $nick ] ] $len($wildsite) set -u5 %owner.chan $chan set %defaultqmsg my quit message set %join.address. [ $+ [ $nick ] ] $wildsite set %join.precompadress. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$wildsite $+ *) set %oldaddress $readn set %join.compaddress. [ $+ [ $nick ] ] $left(%join.precompadress. [ $+ [ $nick ] ],%addlength. [ $+ [ $nick ] ]) set %join.compnick. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$nick $+ *) set %oldnick $readn set %join.time. [ $+ [ $nick ] ] $mid($ctime,2,8) set %join.newnick $chr(44) $+ $nick %join.time set %join.bothnew $wildsite $+ $chr(44) $+ $nick %join.time. [ $+ [ $nick ] ] if (whatever1* iswm $nick) { if (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4 $nick } else { echo 4 -a No Match $nick } } elseif (whatever2* iswm $nick) { if (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4 $nick } else { echo 4 -a No Match $nick } } elseif (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { .notice $me Address Match 4 $nick | goto NickEval } else { write C:\mirc\nicks.txt %join.bothnew | echo 4 -a $nick is a new entry } halt :NickEval if ($nick = %join.compnick. [ $+ [ $nick ] ]) { .notice $me Nick Match 4 $nick | write -al %oldnick C:\mirc\nicks.txt %join.newnick } else { write -al %oldaddress C:\mirc\nicks.txt %join.newnick } } on 1:NICK: { set %addlength. [ $+ [ $newnick ] ] $len($wildsite) set %nick.address. [ $+ [ $newnick ] ] $wildsite set %nick.precompaddress. [ $+ [ $newnick ] ] $read(C:\mirc\nicks.txt,w,$wildsite $+ *) set %oldaddress $readn set %nick.compaddress. [ $+ [ $newnick ] ] $left(%nick.precompaddress. [ $+ [ $newnick ] ],%addlength. [ $+ [ $newnick ] ]) set %nick.compnewnick $read(C:\mirc\nicks.txt,w,$newnick $+ *) set %oldnick $readn set %nick.newnick $newnick %join.time. [ $+ [ $nick ] ] set %nick.nicktime $mid($ctime,2,8) set %nick.bothnew $wildsite $+ $chr(44) $+ $newnick %nick.nicktime if ($newnick == %nick.compnewnick) { .notice $me $newnick found } elseif (%nick.address. [ $+ [ $newnick ] ] == %nick.compaddress. [ $+ [ $newnick ] ]) { write -al %oldaddress C:\mirc\nicks.txt , $+ $newnick %nick.nicktime | .notice $me new nick old address } else { write C:\mirc\nicks.txt %nick.bothnew | echo 4 -a $newnick is a new entry } } on 1:QUIT: { unset *. $+ $nick }
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
As a suggestion, here's your current code with a bit of re-write. on 1:JOIN:#: {
set $+(%,addlength.,$nick) $len($wildsite)
set -u5 %owner.chan $chan
set %defaultqmsg my quit message
set $+(%,join.address.,$nick) $wildsite
set $+(%,join.precompadress.,$nick) $read(nicks.txt,w,$wildsite $+ *)
set %oldaddress $readn
set $+(%,join.compaddress.,$nick) $left($($+(%,join.precompadress.,$nick),2),$($+(%,addlength.,$nick),2))
set $+(%,join.compnick.,$nick) $read(nicks.txt,w,$nick $+ *)
set %oldnick $readn
;this line doesn't return the actual joining time, due to your useage of either $ctime or usage of $mid
;to get the correct joining time, I recommend just using $ctime
[color:red] set $+(%,join.time.,$nick) $mid($ctime,2,8)[/color]
;the variable %join.time is not set in this script, so unless it is set in another script that runs before this one, the value will always be 0
; I recommend changing %join.time to either $ctime (which would allow you to remove the line above), or use $($+(%,join.time.,$nick),2)
[color:red] set %join.newnick $chr(44) $+ $nick %join.time
[/color]
set %join.bothnew $+($wildsite,$chr(44),$nick) $($+(%,join.time.,$nick),2)
if (whatever1* iswm $nick) || (whatever2* iswm $nick) {
$iif($($+(%,join.address.,$nick),2) == $($+(%,join.compaddress.,$nick),2),.notice $me Address Match 4 $nick,echo 4 -a No Match $nick)
}
elseif ($($+(%,join.address.,$nick),2) == $($+(%join.compaddress.,$nick),2)) {
.notice $me Address Match 4 $nick
.write -al $iif($nick = $($+(%,join.compnick.,$nick),2),%oldnick,%oldaddress) nicks.txt %join.newnick
$iif($nick = $($+(%,join.compnick.,$nick),2),.notice $me Nick Match 4 $nick)
}
else {
write nicks.txt %join.bothnew
echo 4 -a $nick is a new entry
}
}
on *:NICK: {
set $+(%,addlength.,$newnick) $len($wildsite)
set $+(%,nick.address.,$newnick) $wildsite
set $+(%,nick.precompaddress.,$newnick) $read(nicks.txt,w,$wildsite $+ *)
set %oldaddress $readn
set $+(%,nick.compaddress.,$newnick) $left($($+(%,nick.precompaddress.,$newnick),2),$($+(%,addlength.,$newnick),2))
set %nick.compnewnick $read(nicks.txt,w,$newnick $+ *)
set %oldnick $readn
set %nick.newnick $newnick $($+(%,join.time.,$nick),2)
;same as mentioned earlier but in this case, referring to the time of the nick change, rather than the time of joining
[color:red] set %nick.nicktime $mid($ctime,2,8) [/color]
set %nick.bothnew $+($wildsite,$chr(44),$newnick) %nick.nicktime
if ($newnick == %nick.compnewnick) { .notice $me $newnick found }
elseif ($($+(%,nick.address.,$newnick),2) == $($+(%,nick.compaddress.,$newnick),2)) {
write -al %oldaddress nicks.txt , $+ $newnick %nick.nicktime
.notice $me new nick old address
}
else { write nicks.txt %nick.bothnew | echo 4 -a $newnick is a new entry }
}
on *:QUIT: { unset $+(*.,$nick) }
There are a few spots in this code that don't look right to me, and I've gone and marked those lines in red, and placed remarks above them indicating why I don't think they will work correctly.
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Thanks for those suggestions. Actually the join.time variable is getting set. The reason that I used $mid on the $ctime is to save space in the text file. The alias will add the first 1 to the left side and a 0 to the right side when I call back a line. Changing the right side number to 0 would only make it inaccurate to possibly a few seconds, which doesn't matter much. Thanks again to everyone who helped.
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Hi, I'm having a problem with one section of this script. It's supposed to send me a notice if it finds a nick or address match. When a person joins who is a match, it works and sends me a notice that "Nick was <list of nicks here>". I'm using %join.precompaddress. [ $+ [ $nick ] ] on JOIN and it works. I'm using %nick.precompaddress. [ $+ [ $newnick ] ] in the ON NICK section and I can see that the variable is getting set, but the notices only say "Nick was" with no information after it. Any ideas why this would be? Here's my ON NICK section
on 1:NICK: {
set %addlength. [ $+ [ $newnick ] ] $len($wildsite)
set %nick.address. [ $+ [ $newnick ] ] $wildsite
set %nick.precompaddress. [ $+ [ $newnick ] ] $read(C:\mirc\nicks.txt,w,$wildsite $+ *)
set %oldaddress $readn
set %nick.compaddress. [ $+ [ $newnick ] ] $left(%nick.precompaddress. [ $+ [ $newnick ] ],%addlength. [ $+ [ $newnick ] ])
set %nick.compnewnick $read(C:\mirc\nicks.txt,w,$newnick $+ *)
set %oldnick $readn
set %nick.newnick $newnick %nick.nicktime
set %nick.nicktime $mid($ctime,2,8)
set %nick.bothnew $wildsite $+ $chr(44) $+ $newnick %nick.nicktime
if ($newnick == $me) { echo }
elseif ($newnick == %nick.compnewnick) { echo -a nick match | .notice $me 4 $newnick was $remove(%nick.precompaddress. [ $+ [ $newnick ] ],$gettok(%nick.precompaddress. [ $+ [ $newnick ] ],1,44)) }
elseif (%nick.address. [ $+ [ $newnick ] ] == %nick.compaddress. [ $+ [ $newnick ] ]) { echo -a address match | write -al %oldaddress C:\mirc\nicks.txt , $+ $newnick %nick.nicktime | .notice $me 4 $newnick was $remove(%nick.precompadress. [ $+ [ $newnick ] ],$gettok(%nick.precompadress. [ $+ [ $newnick ] ],1,44)) }
else { write C:\mirc\nicks.txt %nick.bothnew | echo 4 -a $newnick is a new entry }
}
on 1:QUIT: {
unset % $+ *. $+ $nick
}
on 1:PART: {
unset % $+ *. $+ $nick
}
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
/me slaps forehead
Copy and paste can be an evil thing! My error was that "address" was spelled wrong in some of the viariable names, and I used copy and paste sometimes when variable names were similar.
|
|
|
|
|