I'm trying to write a command for an IRC chat bot to check viewers in each day. When someone types !chirp I want the bot to either: 1) add the users name and date they checked in, 2) add just the check in date if they're already on the list, or 3) do nothing if they've already checked in that day. The problem I'm running into is the second if-statement: seems to think it's true and proceeds when it shouldn't. The /echo lines are strictly for debugging.
Text file format is(one value per line):
username
username
date
date
username
date
username
etc.
Here's the code (written as a remote function):
on *:TEXT:!chirp:#: {
;INITIALIZE VARIABLES
set %i 1
set %lines $lines(chirp.txt)
set %line NULL
set %lineafter NULL
set %date $adate
set %temp NULL
while ( %i <= %lines ) {
set %line $read(chirp.txt, n, %i)
set %lineafter $calc($readn +1)
set %temp $calc(%i + 1)
;/echo -a %i $char(32) %line $char(32) %lineafter $char(32) %temp
;/echo -a $read(chirp.txt, n, %temp)
if ( %line == $nick ) {
if( $read(chirp.txt, nw, *%temp*) === %date ) {
msg $chan /w $nick You've already checked in today!
/halt
} else {
/write -il $+ %lineafter chirp.txt $adate
msg $chan /w $nick Welcome back! Thanks for checking in!
/halt
}
}
/inc %i
}
/write chirp.txt $nick
/write chirp.txt $adate
}
;END OF CODE