| View previous topic :: View next topic |
| Author |
Message |
Fire-Fox Master

Joined: 23 Sep 2006 Posts: 270 Location: /dev/null
|
Posted: Tue May 12, 2020 6:58 am Post subject: [SOLVED]Dont add whats already there |
|
|
I have this script made by ceasar
I would like it to reply back when another user adds to the dbase with already added info. Like !start 'that have been made'
then it should reply back in chan: 'that is already added'
and IF it's not in the dbase, it should add like it already does?
I am thinking 'string match' / 'string first' ?
| Code: |
proc infoadd {nick uhost handle chan text} {
if {![channel get [string tolower $chan] rlsAdd]} { return 0 }
global dbInfo chann_
if {[scan $text {%s} info] != 1} {
putserv "NOTICE $nick :Usage: !start <info>"
return
}
variable dbInfo
if {[scan $dbInfo %s%s%s%s hostname username password database] != 4} return
set time [unixtime]
set info [::mysql::escape $info]
set nick [::mysql::escape $nick]
set con [::mysql::connect -host $hostname -user $username -password $password -db $database]
set query1 [::mysql::sel $con "SELECT info,nick,unixtime FROM testbook WHERE info = '$info'" -flatlist];
if {"$query1" !=""} {
foreach {info nick timestamp} $query1 {
putlog "Book Info: $info / $nick / $timestamp "
set addedago [getadded $timestamp]
puthelp "PRIVMSG $chann_(rls) \0037Book Info\003:\0039$info\003 \0037Allerede Startet Af\003 -> $nick \[ $addedago \]"
putlog "Book Info: $info / $nick / $addedago "
}
} else {
set query [::mysql::query $con "INSERT INTO testbook (id,unixtime,info,nick) VALUES (NULL, UNIX_TIMESTAMP(), '$info', '$nick')"]
puthelp "PRIVMSG $chann_(rls) :\0037Book Info\003:\0039 $info\003 \0037Added by\003 $nick => \[\00314TiME:\003 [clock format $time -format %d-%m-%Y] [clock format $time -format %H:%M:%S] \]"
putlog "Book Info: $info / $nick / $time "
}
::mysql::endquery $con
::mysql::close $con
}
#END
|
_________________ GreatZ
Fire-Fox | Denmark
Scripts: Relay | Store Text | TvMaze
Last edited by Fire-Fox on Sat May 16, 2020 2:34 pm; edited 1 time in total |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed May 13, 2020 9:55 am Post subject: |
|
|
If you don't use '-flatlist' at you select, then it will return 0 if there's no match or the amount of results in the select.
For example:
| Code: |
% ::mysql::sel $con "SELECT title FROM books WHERE id= '5'"
1
% ::mysql::sel $con "SELECT title FROM books WHERE id = '123'"
0
% ::mysql::sel $con "SELECT title FROM books"
5
|
I would pair the sel with map so instead of:
| Code: |
set query1 [::mysql::sel $con "SELECT info,nick,unixtime FROM testbook WHERE info = '$info'" -flatlist];
if {"$query1" !=""} {
foreach {info nick timestamp} $query1 {
putlog "Book Info: $info / $nick / $timestamp "
set addedago [getadded $timestamp]
puthelp "PRIVMSG $chann_(rls) \0037Book Info\003:\0039$info\003 \0037Allerede Startet Af\003 -> $nick \[ $addedago \]"
putlog "Book Info: $info / $nick / $addedago "
}
|
would turn it into:
| Code: |
set count [::mysql::sel $con "SELECT info,nick,unixtime FROM testbook WHERE info = '$info'"]
if {$count} {
::mysql::map $con {info user time} {
putlog "Book Info: $info / $user / $time"
set when [getadded $time]
puthelp "PRIVMSG $chann_(rls) \0037Book Info\003:\0039$info\003 \0037Allerede Startet Af\003 -> $user \[ $when\]"
putlog "Book Info: $info / $user / $when"
}
}
|
basically should have the same functionality.
Edit: You realize that you can use just one 'clock format' to show the date and time and don't need two of them, right?
I mean instead of:
| Code: |
[clock format $time -format %d-%m-%Y] [clock format $time -format %H:%M:%S]
|
can go with:
| Code: |
[clock format $time -format "%d-%m-%Y @ %H:%M:%S"]
|
result being:
| Code: |
% clock format [clock scan now] -format "%d-%m-%Y @ %H:%M:%S"
13-05-2020 @ 17:13:03
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
|
|
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
|
|