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.

Help with joinmsg

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Help with joinmsg

Post by Fire-Fox »

Hey how do i add the
setudef flag
??

Something like :
setudef flag joinmsg

Code: Select all

package require mysqltcl

bind join - * join:testarea
bind rejn - * join:testarea

##################
### Mysql path ###
##################
# SQL info
set sql(host) "xxxxxxxxxx"
set sql(user) "xxxxxxxxxx"
set sql(pass) "xxxxxxxxxx"
set sql(db) "xxxxxxxxxx"
set sql(port) "xxxx"

##################
### Mysql path ###
##################
if {![info exists db_handle] } {
set db_handle [mysqlconnect -host $sql(host) -user $sql(user) -password $sql(pass) -db $sql(db) -port $sql(port)] 
}

###########################################
### Greeting MSG When User Join channel ###
###########################################
proc bt.join.class { chan nick class} {

switch $class {

   ### The number is the number of the class on the site
   ### "return 0" means no msg for that class


   "default"	{set class "Not Found" }
 }
}
#################
### Join Proc ###
#################
proc join:testarea {nick host hand chan} {
global botnick db_handle

  if {$nick != $botnick} {
  
       if {[mysqlping $db_handle] != 1} { 
           putserv "PRIVMSG $chan : The connection to the mysql server has been lost."
             return 0
       }
       
       set sqlnick "SELECT userid FROM joinmsgnicks WHERE nick='[mysqlescape $nick]'"
       set resultnick [mysqlquery $db_handle $sqlnick]
             
       set nicki 0
       while {[set record [mysqlnext $resultnick]] != ""} {
         set userid [lindex $record 0]
         incr nicki
       } 
             
       if { $nicki == 0 } { return 0 }
             
       if { $userid == "" } { return 0 }
             
       set sql "SELECT username, class FROM joinmsgircuser WHERE id='[mysqlescape $userid]'"
       
       set result [mysqlquery $db_handle $sql]
             
       set i 0
       while {[set record [mysqlnext $result]] != ""} {
                    
         set username [lindex $record 0];
         set class [lindex $record 1];
       }
       
       set sql "SELECT username, class FROM joinmsgircuser WHERE id='[mysqlescape $userid]'"
       set result [mysqlquery $db_handle $sql]
             
       set i 0
       while {[set record [mysqlnext $result]] != ""} {
                    
         set username [lindex $record 0];
         set class [lindex $record 1];
       }
       mysqlendquery $result
       
       bt.join.class $chan $nick $class

    }
  }
  putlog "Joinmsg"
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I must say you pretty much answered your own question there..
To define the custom channel flag "joinmsg", make sure the following piece of code to your script, in such fashion that it will be executed as the script loads (usually in the top of the script):

Code: Select all

setudef flag joinmsg
Once this is done, this flag can be used just like any other flag available in your eggdrop. You probably would like to read up on the channel command (doc/tcl-commands.doc), especially the get option.
NML_375
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Hey

I did the following thing

Code: Select all

proc bt.join.class { chan nick class} {
[b]if {[channel get $chan joinmsg]} { [/b]
switch $class {

   ### The number is the number of the class on the site
   ### "return 0" means no msg for that class

   "default"	{set class "Not Found" }
  }
[b] }[/b]
}
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

That would be the proper way of testing whether "joinmsg" is set for the specific channel, yes.
NML_375
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Yes i noticed, i tryed with +joinmsg, and made a /hop (the bot reply with the welcome msg) and then with -joinmsg (Nothing happend)

so i must say it works :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Sorry for bump :D

Is it possible to add so i can add the users via !tcl commands instead of i have to login to the mysql to add the users?

the output :
[@LillePil] Welcome To ::: Apache ::: Bot Commander
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Assuming the account has insert/update privileges for the table, sure.

Would be a mere matter of a proper INSERT query sent using the mysqlquery command
Since I don't know the table structure for your database, I really can't say much more than that.
NML_375
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

nml375 wrote:Assuming the account has insert/update privileges for the table, sure.

Would be a mere matter of a proper INSERT query sent using the mysqlquery command
Since I don't know the table structure for your database, I really can't say much more than that.
Hey again :)

Here is the table structure :)

Code: Select all

CREATE TABLE `joinmsgircuser` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `username` varchar(40) NOT NULL default '',
  `class` tinyint(3) unsigned NOT NULL default '1',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `username` (`username`),
  KEY `username_status` (`username`)
) TYPE=MyISAM AUTO_INCREMENT=32 ;


CREATE TABLE `joinmsgnicks` (
  `id` int(16) NOT NULL auto_increment,
  `nick` varchar(32) NOT NULL default '',
  `userid` int(16) default NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=33 ;
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I was hoping for a slight explanation of the fields and any relationship.. but here it goes...

Generic syntax for inserts:

Code: Select all

INSERT INTO table (field1, field2) VALUES (data1, data2)
In this case, you've got two auto_increment-fields, so you should not set these. This leaves us with "username", "class" for the joinmsgircuser table, and "nick", "userid" for the joinmsgnicks table.

The code you've posted suggests joinmsgnicks.userid links with joinmsgircuser.id, but you'll have to confirm this...

In order to retrieve the last_insertid, use the mysqlinsertid command.

Btw, I am a bit puzzled as to why you repeat the same query.
NML_375
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

nml375 wrote:I was hoping for a slight explanation of the fields and any relationship.. but here it goes...

Generic syntax for inserts:

Code: Select all

INSERT INTO table (field1, field2) VALUES (data1, data2)
In this case, you've got two auto_increment-fields, so you should not set these. This leaves us with "username", "class" for the joinmsgircuser table, and "nick", "userid" for the joinmsgnicks table.

The code you've posted suggests joinmsgnicks.userid links with joinmsgircuser.id, but you'll have to confirm this...

In order to retrieve the last_insertid, use the mysqlinsertid command.

Btw, I am a bit puzzled as to why you repeat the same query.
Hey :D
Btw, I am a bit puzzled as to why you repeat the same query.
A mate of mine made it a while back. it was made like this:

If a user signed up on a site, and when the same user joined irc they got a greeting message, something like : Welcome ::: Nick ::: UserClass (On the site)

And yes then the script don't need the second script i believe?

but could you help me make it right? im not that good to anything :cry:
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Roger that.
The following code will create new records in both joinmsgnicks and joinmsgircuser, based on the previous mentioned assumption:

Code: Select all

set query1 [mysqlquery "INSERT INTO joinmsgircuser (username, class) VALUES (\"[mysqlescape $username]\", [mysqlescape $class])"]
set query2 [mysqlquery "INSERT INTO joinmsgnicks (nick, userid) VALUES (\"[mysqlescape $nickname]\", [mysqlinsertid $db_handle])"]
mysqlendquery $query1
mysqlendquery $query2
This would then be placed in some proc, triggered with the binding of your liking. Data should be made available in the variables username, class, and nickname.
NML_375
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

nml375 wrote:Roger that.
The following code will create new records in both joinmsgnicks and joinmsgircuser, based on the previous mentioned assumption:

Code: Select all

set query1 [mysqlquery "INSERT INTO joinmsgircuser (username, class) VALUES ("[mysqlescape $username]", [mysqlescape $class])"]
set query2 [mysqlquery "INSERT INTO joinmsgnicks (nick, userid) VALUES ("[mysqlescape $nickname]", [mysqlinsertid $db_handle])"]
mysqlendquery $query1
mysqlendquery $query2
This would then be placed in some proc, triggered with the binding of your liking. Data should be made available in the variables username, class, and nickname.
Thanks. but why should i remove from the script (it not used to a site anymore. only when users join my irc channel :))

Could i get you to add it into the script i pasted?

And then add a tcl command so i just need to type !addmsg (or something) Nickname (and some text)

So it would look like : "Welcome ::: NickName ::: Some text here

Self retrived from the database.
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

If you simply want someone to "fix" the script for you, I would recommend that you try the "Script Request" category instead.
NML_375
Post Reply