This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

IRC Online Script

Help for those learning Tcl or writing their own scripts.
Post Reply
M
MIODude
Voice
Posts: 32
Joined: Mon Oct 09, 2006 6:26 pm

IRC Online Script

Post by MIODude »

This is similar to irc idle script., but we've modified it so that when people use alternate nicks in IRC, it works to show people 'online' on a website.

so.. we got the join, sign and part procedures changed without a problem, but the nick change we're struggling.

Essentially.. if a person is using their USERNAME nick or their IRCNAME nick (thats the field names in the SQL database) , and changes their nick to something other than USERNAME, or IRCNAME, it says they are offline.
If they change their nick to USERNAME, it marks them online. If they change their nick to their IRCNAME, it marks them online.

Below is the procedure for the nick change. I know the binding works, because before we implemented the alternate nick with IRCNAME, it worked fine.

Right now,

If I change my nick in irc, i get this error: (regardless what my current nick is or going to be). I can't figure out what is creating this error!

Tcl error [nick_main]: wrong # args: should be "set varName ?newValue?"

Code: Select all

proc nick_main {nick uhost handle channel newnick} {

global db_handle botnick

  if {$nick==$botnick} {return 0}
# first section is the check if your existing nick (before change) now matches username or IRC name, or no longer matches irc name or user name.

  set sql "UPDATE CC_users SET onirc = 'no' WHERE username = '$nick'"  // check if existing nick (before change) matches username then make it NO!
  putlog "Step 1: $sql"
  putloglev d * "ircstats: executing $sql"
  putlog "Step 2: $result"
  set result [mysqlexec $db_handle $sql]

    if {$result != 1} {              // existing nick doesn't exist in the database so this triggers If statement...
    set sql2 "UPDATE CC_users SET onirc = 'no' WHERE ircname = '$nick'"  // check if existing nick (before change) matches ircname then make it No!
    putlog "SQL2: $sql2"
    putloglev d * "ircstats: executing $sql2"
    set result2 [mysqlexec $db_handle $sql2]
    putlog "result2: $result2"

        if {$result2 != 1} {                // existing nick doesn't match ircname either... So.. lets check if the newnick matches username
              set sql3 "UPDATE CC_users SET onirc = 'yes' WHERE username = '$newnick'"   //check newnick if it matches username
              putlog "SQL3: $sql3"
              putloglev d * "ircstats: executing $sql3"
              set result3 [mysqlexec $db_handle $sql3]
              putlog "result3: $result3"

                        if {$result3 != 1} {                // new nick doesn't match username, so.. lets check if the newnick matches ircname
                        set sql4 "UPDATE CC_users SET onirc = 'yes' WHERE ircname = '$newnick'"    //check if newnick matches ircname
                        putlog "SQL4: $sql4"
                        putloglev d * "ircstats: executing $sql4"
                        set result4 [mysqlexec $db_handle $sql4]
                        putlog "result4: $result4"

                               if {$result4 != 1} {  // new nick doesn't match ircname either
                               putlog "SQL - Error"  // sucks to be you.. no idle bonus for you!

                               } else {         // but WAIT newnick matched ircname!!  give him his bonus!
                               set id [mysqlinsertid $db_handle]
                               puthelp "PRIVMSG $channel :User Online: \002$newnick\002 - IRC bonus enabled."
                               pushmode $channel +v $newnick
                               }
                        } else {                // // but WAIT newnick matched username!!  give him his bonus!
                        set id [mysqlinsertid $db_handle]
                        puthelp "PRIVMSG $channel :User Online: \002$newnick\002 - IRC bonus enabled."
                        pushmode $channel +v $newnick
                        }
              } else {                // // but WAIT original nick matched ircname!!  so disable his bonus since he just changed from it
              set id [mysqlinsertid $db_handle]
              puthelp "PRIVMSG $channel :User Offline: \002$nick\002 - IRC bonus disabled."
              pushmode $channel -v $newnick
              }
    } else {                // // but WAIT original nick matched username!!  Does New Nick Match ircname?

      set sqlirc "UPDATE CC_users SET onirc = 'yes' WHERE ircname = '$newnick'"
      putlog "SQLirc: $sqlirc"
      putloglev d * "ircstats: executing $sqlirc"
      set resultirc [mysqlexec $db_handle $sqlirc]
      putlog "resultirc: $resultirc"
             if {$resultirc != 1} {
                set id [mysqlinsertid $db_handle]
                puthelp "PRIVMSG $channel :User Offline: \002$nick\002 - IRC bonus disabled."
                pushmode $channel -v $newnick
             }
       }
  }
All help is appreciated! I've been working on this for days now
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You can't use // for comments... Only # will work for comments.
NML_375
M
MIODude
Voice
Posts: 32
Joined: Mon Oct 09, 2006 6:26 pm

Post by MIODude »

doh!

thanks.. getting a new error now, but I will continue to trouble shoot.. at least this error I can work with!!
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Btw, you should use:

Code: Select all

if {![isbotnick $nick]} {return 0}
instead of:

Code: Select all

if {$nick==$botnick} {return 0} 
Once the game is over, the king and the pawn go back in the same box.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

caesar wrote:Btw, you should use:

Code: Select all

if {![isbotnick $nick]} {return 0}
instead of:

Code: Select all

if {$nick==$botnick} {return 0} 
caesar, closely look at your post above. heh. I'm sure you meant this instead.

Code: Select all

if {[isbotnick $nick]} {return 0}

and something like this is easier, since most of those nested if's simply do the same thing you can create sub procedures to make it easier to understand the code without needing those comments. A simple list to hold those sql commands makes it easier.

Code: Select all

set db_sqllist [list "UPDATE CC_users SET onirc = 'no' WHERE username = '$nick'" \
                     "UPDATE CC_users SET onirc = 'no' WHERE ircname = '$nick'" \
                     "UPDATE CC_users SET onirc = 'yes' WHERE username = '$newnick'" \
                     "UPDATE CC_users SET onirc = 'yes' WHERE ircname = '$newnick'"]

proc nick_main {nick uhost handle channel newnick} {
	global db_handle
	if {[isbotnick $nick]} {return 0}
	if {[db_handle_helper 1 0] != 1} {
		if {[db_handle_helper 2 1] != 1} {
			if {[db_handle_helper 3 2] != 1} {
				if {[db_handle_heler 4 3] != 1} {
					putlog "SQL - Error"
				} else {
					db_handle_voicer "+" [mysqlinsertid $db_handle] $channel $nick $newnick
				}
			} else {
				db_handle_voicer "+" [mysqlinsertid $db_handle] $channel $nick $newnick
			}
		} else {
			db_handle_voicer "-" [mysqlinsertid $db_handle] $channel $nick $newnick
		}
	} elseif {[db_handle_helper "irc" 3] != 1} {
		db_handle_voicer "-" [mysqlinsertid $db_handle] $channel $nick $newnick	
	}
} 

proc db_handle_helper {s call} {
	global db_handle db_sqllist
	set sql [lindex $db_sqllist $call]
	putlog "SQL$s: $sql"
	putloglev d * "ircstats: executing $sql"
	set result [mysqlexec $db_handle $sql]
	putlog "result$s: $result"
	return $result
}

proc db_handle_voicer {mode id channel nick newnick} {
	switch -- $mode {
		"-"	{ puthelp "PRIVMSG $channel :User Offline: \002$nick\002 - IRC bonus disabled." }
		"+"	( puthelp "PRIVMSG $channel :User Online: \002$newnick\002 - IRC bonus enabled." }
	}
	pushmode $channel ${mode}v $newnick
	return
}
M
MIODude
Voice
Posts: 32
Joined: Mon Oct 09, 2006 6:26 pm

Post by MIODude »

speechles wrote: no need to quote that much!
Thanks!

I was getting this error though on the loading of the script

invalid command name "UPDATE CC_users SET onirc = 'no' WHERE ircname = 'ToonHead'" while executing ""UPDATE CC_users SET onirc = 'no' WHERE ircname = '$nick'" \ " invoked from within "set db_sqllist [list "UPDATE CC_users SET onirc = 'no' WHERE username = '$nick' " \ "UPDATE CC_users SET onirc = 'no' WHERE ircna..." (file "scripts/ircidle.tcl" line 183)

so I changed it to

Code: Select all

set lista "UPDATE CC_users SET onirc = 'no' WHERE username = '$nick'"
set listb "UPDATE CC_users SET onirc = 'no' WHERE ircname = '$nick'"
set listc "UPDATE CC_users SET onirc = 'yes' WHERE username = '$newnick'"
set listd "UPDATE CC_users SET onirc = 'yes' WHERE ircname = '$newnick'"

set db_sqllist [list lista listb listc listd] 
But.. now I'm getting the error that the 2nd procedure doesn't know what the $mode is..

Code: Select all

proc db_handle_voicer {mode id channel nick newnick} { 
   switch -- $mode { 
      "-"   { puthelp "PRIVMSG $channel :User Offline: \002$nick\002 - IRC bonus disabled." } 
      "+"   ( puthelp "PRIVMSG $channel :User Online: \002$newnick\002 - IRC bonus enabled." } 
   } 
   pushmode $channel ${mode}v $newnick 
   return 
}
I tried adding global mode, but that didn't help. It didn't know channel either, but i added a set channel statement, then added global channel. I can see the mode is being passed to the procedure.. so why doesn't it know?

the error is:
can't read "mode": no such variable while executing "pushmode $channel ${mode}v $newnick " (file "scripts/ircidle.tcl" line 232) invoked from within "source scripts/ircidle.tcl"
Post Reply