##########
#### 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
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.
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.
##########
#### 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
}