egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IRC Online Script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
MIODude
Voice


Joined: 09 Oct 2006
Posts: 32

PostPosted: Sat Jun 05, 2010 5:16 pm    Post subject: IRC Online Script Reply with quote

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:

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
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jun 05, 2010 6:04 pm    Post subject: Reply with quote

You can't use // for comments... Only # will work for comments.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
MIODude
Voice


Joined: 09 Oct 2006
Posts: 32

PostPosted: Sat Jun 05, 2010 6:14 pm    Post subject: Reply with quote

doh!

thanks.. getting a new error now, but I will continue to trouble shoot.. at least this error I can work with!!
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sun Jun 06, 2010 2:47 pm    Post subject: Reply with quote

Btw, you should use:
Code:

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

instead of:
Code:

if {$nick==$botnick} {return 0}

_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Jun 06, 2010 11:26 pm    Post subject: Reply with quote

caesar wrote:
Btw, you should use:
Code:

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

instead of:
Code:

if {$nick==$botnick} {return 0}


caesar, closely look at your post above. heh. I'm sure you meant this instead.
Code:
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:
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
}

_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
MIODude
Voice


Joined: 09 Oct 2006
Posts: 32

PostPosted: Mon Jun 07, 2010 8:39 am    Post subject: Reply with quote

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:

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:

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"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber