egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED]Dont add whats already there

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Tue May 12, 2020 6:58 am    Post subject: [SOLVED]Dont add whats already there Reply with quote

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
View user's profile Send private message MSN Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed May 13, 2020 9:55 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber