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.

[SOLVED]Dont add whats already there

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
Fire-Fox
Master
Posts: 289
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

[SOLVED]Dont add whats already there

Post by Fire-Fox »

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: Select all

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
Last edited by Fire-Fox on Sat May 16, 2020 2:34 pm, edited 1 time in total.
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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: Select all

% ::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: Select all

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: Select all

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: Select all

[clock format $time -format %d-%m-%Y] [clock format $time -format %H:%M:%S]
can go with:

Code: Select all

[clock format $time -format "%d-%m-%Y @ %H:%M:%S"]
result being:

Code: Select all

% 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.
Post Reply