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.

on|off function

Old posts that have not been replied to for several years.
Locked
z
zyxep

on|off function

Post by zyxep »

hey ppl

i will bould an on|off function to my scripts..

but i dont know exactly how..

i have this code..

Code: Select all

##########
#### sæt default så den automatisk er sat til eller ikke
#### 0 => off
#### 1 => on
##########
set cup_auto "0"

##########
#### Loader mysqltcl
##########

load /usr/local/lib/mysqltcl-2.50/libmysqltcl2.50.so

bind pub m|m ".auto" pub:auto

proc pub:auto {nick host hand chan text} {
	global msql cup_auto cup_users
	set connection [mysqlconnect -host $msql(host) -user $msql(user) -password $msql(pass)]
	mysqluse $connection $msql(db)
	set default [mysqlsel $connection "select status from $msql(table)" -list]
	foreach cup $default {
		if {$cup == 0} {
			putserv "NOTICE $nick :Automatisk cup er nu sat til \002off\002"
	} elseif {$cup == 1} {
		putserv "NOTICE $nick :Automatisk cup er nu sat til \002on\002"
	}
	}
}
an a mysql connection..

i need to get it like this

if i add the bot to a channel does it add the channel in the mysql database with the default flags auto_cup

0 is off
1 os on

the bot set 0 in the mysql database

then if i write .auto 1

does it change the settings for the channel to 1

and then it is on..
User avatar
Jil Larner
Voice
Posts: 14
Joined: Fri Aug 20, 2004 8:28 am
Location: France

Post by Jil Larner »

Hi,

this part of the script doesn't add anything in the database... It only selects. Look for a "INSERT INTO" somewhere, and there, modify the default value you want.
z
zyxep

Post by zyxep »

i know.. but is the code right if i add a mysql insert line?

EDIT

how can i do so it checks the mysql database for the channel?
User avatar
Jil Larner
Voice
Posts: 14
Joined: Fri Aug 20, 2004 8:28 am
Location: France

Post by Jil Larner »

i'm not sure of what you want but...

Your command gives you the status avaible in the mysql table. If you want to change this status do default, i think you should make another command. Otherwise you would always set database field to you default variable. So; why check in a database a thing which is defined in a local variable ?
In the new command destinated to update mysql status, use an UPDATE more than a INSERT which would add a new row/line each time you trigger the command.

To my mind, if you want to add a ON/OFF command, just define a couple of commands which bind or unbind events.
z
zyxep

Post by zyxep »

can you give me a code for it??
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Code: Select all

##########
#### sæt default så den automatisk er sat til eller ikke
#### 0 => off
#### 1 => on
##########
set cup_auto "0"

##########
#### Loader mysqltcl
##########

load /usr/local/lib/mysqltcl-2.50/libmysqltcl2.50.so

bind pub m|m ".auto" pub:auto

proc pub:auto {nick host hand chan arg} {
  global msql cup_auto cup_users
  # why catch and not set cause set might return an error
  # you could use an if statement and make error handling with this
  # check tcl man for more info about catch
  catch {mysqlconnect -host $msql(host) -user $msql(user) -password $msql(pass)} sql_hand
  mysqluse $sql_hand $msql(db)
  if {[string equal {} [lindex $arg 0]]} {
    foreach c [mysqlsel $sql_hand "select status from $msql(table)" -list] {
      if {!($c)} {
        putserv "NOTICE $nick :Automatisk cup er nu sat til \002off\002"
      } else {
      	putserv "NOTICE $nick :Automatisk cup er nu sat til \002on\002"
      }
    }
  } else {
    mysqlexec $sql_hand ""
    #UPDATE persondata SET age=age+1; 
    # i do not know how ur tables are build .. or how the table names are well this part u have to do ur self 
    # but update i think is a good way to go do not insert as this will add new data not update it !!!
  }
  mysqlclose $sql_hand
} 
XplaiN but think of me as stupid
z
zyxep

Post by zyxep »

Ofloo

if i give you my sql query will you try to make it?

you can edit all that you want ... self my variables and lang ;)
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

i gues ill see ;)
XplaiN but think of me as stupid
z
zyxep

Post by zyxep »

CREATE TABLE cupbots_channels (
id int(11) NOT NULL auto_increment,
channel varchar(255) NOT NULL default '',
status enum('0','1') NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;


there is the structure..


edit so much you will.. self the lang ;) only english :D
Locked