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.

Searching from MySQL db and posting to chan?

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
D
Danko
Voice
Posts: 18
Joined: Thu Mar 09, 2006 1:07 pm

Searching from MySQL db and posting to chan?

Post by Danko »

I'm using eggdrop with mysqltcl, i need a small code to search a mysql db and posting result to chan.

Mysql db is set up as;
id time info secondayinfo
example:
37 1143405316 Soundblaster-Creative Soundcard

So, how do search the info field (Soundblaster-Creative), and posting the info to channel as "Soundblaster-Creative (Soundcard) got updated xDxMxS (monts/days/hrs/etc) ago"..?

Its probably easy as heck, but i've tried for hours now and still havent been able to figure it out.. :|
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

Code: Select all

foreach result [mysqlsel $mysql(conn) "SELECT * FROM `releases` WHERE `rls` LIKE '%$arg%' LIMIT 10" -list] {
  set time [lindex $restul 1]
  set rls [lindex $result 2]
  set sect [lindex $result 3]
  putserv "PRIVMSG $chan :$rls ($sec) got updated [duration [expr [unixtime]-$time]] ago"
}
something like that? $arg is search string...
D
Danko
Voice
Posts: 18
Joined: Thu Mar 09, 2006 1:07 pm

Post by Danko »

Yes thanks a million, dwickie. Just what I needed. :)

(except for the one typo in restul/result, heh)
D
Danko
Voice
Posts: 18
Joined: Thu Mar 09, 2006 1:07 pm

Post by Danko »

One more thing, is it possible to change the standard output "days, hours, minutes, etc" to d, h, m, s, w, mn, etc? :)
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

Danko wrote:One more thing, is it possible to change the standard output "days, hours, minutes, etc" to d, h, m, s, w, mn, etc? :)

Code: Select all

string map {" years" y " year" y " weeks" w " week" w " days" d " day" d " hours" h " hour" h " minutes" m " minute" m " seconds" s " second" s} $time
will convert $time (for example 36 years 13 weeks 3 days 12 hours 3 minutes 13 seconds) to 36y 13w 3d 12h 2m 9s
D
Danko
Voice
Posts: 18
Joined: Thu Mar 09, 2006 1:07 pm

Post by Danko »

Short question;
How do I add a "No info found" to channel if nothing is found? :?
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

Danko wrote:Short question;
How do I add a "No info found" to channel if nothing is found? :?
simple edit:

Code: Select all

set query [mysqlsel $mysql(conn) "SELECT * FROM `releases` WHERE `rls` LIKE '%$arg%' LIMIT 10" -list]
if {$query==""} { putserv "PRIVMSG $chan :Nothing found" ; return }
foreach result $query {
  set time [lindex $restul 1]
  set rls [lindex $result 2]
  set sect [lindex $result 3]
  putserv "PRIVMSG $chan :$rls ($sec) got updated [duration [expr [unixtime]-$time]] ago"
} 
User avatar
ayie
Voice
Posts: 38
Joined: Thu Feb 20, 2003 3:13 am

Post by ayie »

dwickie :
what about if i have some file like etc.db etc1.db etc2.db and when user use command fro example !db 1234 ... then the bot will search all the db file and return to user like this User 1234|data|from|db|file.
can it possible in tcl file ?
Post Reply