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 

Voice user if in MYSQL db

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
traxwriter
Voice


Joined: 21 Mar 2007
Posts: 5

PostPosted: Thu Mar 29, 2007 10:42 am    Post subject: Voice user if in MYSQL db Reply with quote

Hi,

I'm looking for a script that will voice a user if their name is in a mysql db

if they are not in the db print "Please use your site name to gain your IRC bonus $username"

Thanks in advance

I have a irc idle script I wondder if I could integrate into that:

Code:



load /usr/lib/mysqltcl-2.30/libmysqltcl2.30.so
package require mysqltcl
set db_handle [mysqlconnect -host localhost -socket /var/run/mysqld/mysqld.sock -user user -password pass -db database]

bind join - "#channel *" join_main
bind part - "#channel *" part_main
bind sign - "#channel *" sign_main
bind nick - "#channel *" nick_main

proc sign_main {nick uhost hand channel reason} {
global db_handle botnick
  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'no' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    putlog "SQL - Error"
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :5 User Offline: \002$nick\002 - IRC bonus disabled"
  }
}

proc join_main {nick uhost hand channel} {
global db_handle botnick
  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'yes' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    putlog "SQL - error"
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :9 User Online: \002$nick\002 - IRC bonus enabled."
  }
}

proc part_main {nick uhost hand channel msg} {
global db_handle botnick
  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'no' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    putlog "SQL - Error"
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :5 User Offline: \002$nick\002 - IRC bonus disabled"
  }
}

proc nick_main {nick uhost handle channel newnick} {
global db_handle botnick
#  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'no' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    set sql "UPDATE users SET onirc = 'yes' WHERE username = '$newnick'"
    putloglev d * "ircstats: executing $sql"
    set result [mysqlexec $db_handle $sql]
    putlog "SQL - Error"
    if {$result != 1} {
      putlog "SQL - Error"
    } else {
       set id [mysqlinsertid $db_handle]
       puthelp "PRIVMSG $channel :9 User Online \002$newnick\002 - IRC bonus enabled"
    }
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :5 User Offline \002$nick\002 - IRC bonus disabled"
  }
}

Back to top
View user's profile Send private message
DayCuts
Voice


Joined: 15 Jun 2004
Posts: 37

PostPosted: Sat Apr 07, 2007 2:55 am    Post subject: Re: Voice user if in MYSQL db Reply with quote

All you really need to do is use pushmode after the user online messages.

Altered script (not tested but should be fine).

Code:
load /usr/lib/mysqltcl-2.30/libmysqltcl2.30.so
package require mysqltcl
set db_handle [mysqlconnect -host localhost -socket /var/run/mysqld/mysqld.sock -user user -password pass -db database]

bind join - "#channel *" join_main
bind part - "#channel *" part_main
bind sign - "#channel *" sign_main
bind nick - "#channel *" nick_main

proc sign_main {nick uhost hand channel reason} {
global db_handle botnick
  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'no' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    putlog "SQL - Error"
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :5 User Offline: \002$nick\002 - IRC bonus disabled"
  }
}

proc join_main {nick uhost hand channel} {
global db_handle botnick
  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'yes' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    putlog "SQL - error"
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :9 User Online: \002$nick\002 - IRC bonus enabled."
     pushmode $channel +v $nick
  }
}

proc part_main {nick uhost hand channel msg} {
global db_handle botnick
  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'no' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    putlog "SQL - Error"
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :5 User Offline: \002$nick\002 - IRC bonus disabled"
  }
}

proc nick_main {nick uhost handle channel newnick} {
global db_handle botnick
#  if {$nick==$botnick} {return 0}
  set sql "UPDATE users SET onirc = 'no' WHERE username = '$nick'"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlexec $db_handle $sql]
  if {$result != 1} {
    set sql "UPDATE users SET onirc = 'yes' WHERE username = '$newnick'"
    putloglev d * "ircstats: executing $sql"
    set result [mysqlexec $db_handle $sql]
    putlog "SQL - Error"
    if {$result != 1} {
      putlog "SQL - Error"
    } else {
       set id [mysqlinsertid $db_handle]
       puthelp "PRIVMSG $channel :9 User Online \002$newnick\002 - IRC bonus enabled"
       pushmode $channel +v $newnick
    }
  } else {
     set id [mysqlinsertid $db_handle]
     puthelp "PRIVMSG $channel :5 User Offline \002$nick\002 - IRC bonus disabled"
     pushmode -v $newnick
  }
}


Stand alone script.

Code:
load /usr/lib/mysqltcl-2.30/libmysqltcl2.30.so
package require mysqltcl
set vdb_handle [mysqlconnect -host localhost -socket /var/run/mysqld/mysqld.sock -user user -password pass -db database]

bind join - "#channel *" vjoin_main
bind nick - "#channel *" vnick_main

proc vjoin_main {nick uhost hand channel} {
  global vdb_handle botnick
  if {$nick==$botnick} {return 0}
  set nickv [mysqlescape $nick]
  set sql "SELECT username FROM users WHERE username = '$nickv' LIMIT 1"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlsel $db_handle $sql -flatlist]
  if {[llength [split $result]] == 1} {
    pushmode $chan +v $nick
  }
}

proc vnick_main {nick uhost handle channel newnick} {
  global vdb_handle botnick
  if {$newnick==$botnick} {return 0}
  set sql "SELECT username FROM users WHERE username = '[mysqlescape $newnick]' LIMIT 1"
  putloglev d * "ircstats: executing $sql"
  set result [mysqlsel $db_handle $sql -flatlist]
  if {[llength [split $result1]] == 1} {
    pushmode $chan +v $newnick
  } else {
    pushmode $chan -v $newnick
  }
}
Back to top
View user's profile Send private message
traxwriter
Voice


Joined: 21 Mar 2007
Posts: 5

PostPosted: Fri Apr 13, 2007 5:15 am    Post subject: Reply with quote

Thats great thanks DayCuts
Back to top
View user's profile Send private message
traxwriter
Voice


Joined: 21 Mar 2007
Posts: 5

PostPosted: Fri Apr 13, 2007 11:46 am    Post subject: Reply with quote

OK that didn't work, but you prompted me to sort it myself:

Replace:
pushmode $chan +v $nick
With:
putserv "MODE $channel +v $nick"

And Replace:
pushmode $chan -v $newnick
With:
putserv "MODE $channel -v $newnick"

Thanks
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 -> Script Requests 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