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 

private channel user checked against mysql

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


Joined: 13 Feb 2011
Posts: 3

PostPosted: Sun Feb 13, 2011 9:34 pm    Post subject: private channel user checked against mysql Reply with quote

hi
im trying to make a script so the eggdrop checks against a mysql db
if a user that is not in the database tries to enter the room he/she is kicked

ive been trying to modify a script all is good except when it comes to executing the kick ,or welcoming a member into the room.

Code:

package require mysqltcl


###### Set Site address ###########################

set site_add "http://www.******"


###### Setup Your database info here ##############


set dbuser "****"
set dbpassword "****"
set name "****"
set portno "3306"

##### Set site channels ##########################


set chanmember "#test"
set memberclassno "1"

##################################################
# Connect to Database #
##################################################

set db_handle [mysqlconnect -host localhost -port $portno -user $dbuser -password $dbpassword -db $name]

##################################################
# #
##################################################

global db_handle chanmember

set sql "SELECT  id FROM users WHERE username='[mysqlescape $nick]'"
set result [mysqlsel $db_handle $sql -list]

if {$result > 1} {


putserv "NOTICE $nick :welcome to $nick to the members IRC-Channel!"

} else {

}

if {$result < 1} {
putserv "MODE +k $nick"
putserv "NOTICE KICK $nick :your names not down your not comming in"



mysqlendquery $db_handle
}


any help would be appreciated ty
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Feb 14, 2011 1:55 pm    Post subject: Reply with quote

First off, it would seem that you forgot to place your code as part of a proc declaration:
Code:
proc procname {argument list here} {
  code here...
}


Secondly, your script lacks a binding to trigger this proc. I would assume you'd like the check to be done as a user joins the channel; so thus you need to use the join-binding:
bind join - "#test *" procname
You'll also have to make sure that your proc accepts the proper parameters (see the argument list). Join bindings pass the following parameters to the proc when it triggers: nickname, user@host, handle, channel
Code:
proc procname {nick host handle channel} {
  code goes here...
}


Thirdly, "MODE +k $nick" is not a valid MODE command. The first parameter is expected to be the target; either a channel name, or the name of the bot. In your case, this would probably be the channel. Next, the +k mode is channel key, not kick/ban/etc. I doubt you intended to lock the channel with the offender's nickname as key/password, but rather you intended to ban him/her. Use +b mode along with a proper banmask for this instead.

Passing the -list option to mysqlsel causes it to return a list of Result Sets. Doing a simple less-then/greater-then check is technically not correct, though I think you'll get away with it in this case.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
rickity
Voice


Joined: 13 Feb 2011
Posts: 3

PostPosted: Wed Feb 16, 2011 1:28 pm    Post subject: Reply with quote

i manged to work it out thanks to your help
im over the moon Very Happy Very Happy

Code:

package require mysqltcl



#-> Change the information below to connect to your MySQL database



set mysqlserver localhost;

set mysqluser ***;

set mysqlpwd ***;

set mysqldb ***;


#-> Change the chan below for the chan you wish to monitor



set userChan "#test"



bind join - * joins

proc joins {nick host hand chan args} {

        global userChan

        if {$chan == $userChan } {

               set db_handle [mysqlconnect -h  $::mysqlserver -u $::mysqluser -password $::mysqlpwd];

                mysqluse $db_handle $::mysqldb
   set sql "SELECT id FROM users WHERE username='[mysqlescape $nick]'"
   set result [mysqlsel $db_handle $sql -list]

               

        }

set result [mysqlsel $db_handle $sql -list]

if {$result > 0 } {

putserv "NOTICE $userChan $nick :welcome"

} else {

putserv "kick $userChan $nick :your names not down your not comming in!"


mysqlclose $db_handle;
}
}
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Feb 16, 2011 2:01 pm    Post subject: Reply with quote

A few things..
Don't use "args" as an argument name unless you know what you are doing. Unless you intend to re-use the proc for other bindings such as pub and/or pubm, there'd be no point in using it here.
Code:
proc joins {nick host hand chan} {


$chan == $userChan
This test is case-sensitive, and the value of $chan is whatever the user used to join the channel. Irc-servers on the other hand, treat channel-names in a case-insensitive manner; #test and #Test is the same channel. Use the "string" command instead:
Code:
if {[string equal -nocase -- $chan $userChan]} {

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
rickity
Voice


Joined: 13 Feb 2011
Posts: 3

PostPosted: Wed Feb 16, 2011 2:20 pm    Post subject: Reply with quote

works brilliantly ty so much Very Happy Very Happy
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