| View previous topic :: View next topic |
| Author |
Message |
CoCooner Voice
Joined: 09 Feb 2009 Posts: 3
|
Posted: Sat Oct 16, 2010 7:46 am Post subject: Add news as auto announce |
|
|
hi there
first sry for my bad english
i've downloaded an installed the add news script from here
http://www.egghelp.org/cgi-bin/tcl_archive.tcl?mode=download&id=1268
works great but is it possible to make this script announce every 30 minutes ?
maybe with a extra script ?
I've tried to contact the coder but unfortunately all his contact types are offline  |
|
| Back to top |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Sat Oct 16, 2010 11:17 am Post subject: |
|
|
After | Code: | # ----------------------------------------------------------------------
# news
# !news
# Querys the last 5 lines of news from the database or the news line
# number entered
# ----------------------------------------------------------------------
|
add this | Code: | bind time - "30 * * * *" autonews
bind time - "00 * * * *" autonews
proc autonews {mins hours days months years} {
global db_handle news_noflags
foreach channel [channels] {
if {![channel get $channel newsengine]} {
return 0
}
set x 5
while {$x > 0} {
set y [expr $x - 1]
set sql "SELECT * FROM news ORDER BY id desc limit $y,1"
putloglev d * "NewsEngine: executing $sql"
set result [mysqlquery $db_handle $sql]
if {$x == 5} {
puthelp "PRIVMSG $channel :NEWS:"
}
if {[set row [mysqlnext $result]] != ""} {
set id [lindex $row 0]
set news [lindex $row 3]
set by [lindex $row 1]
set when [clock format [lindex $row 5] -format "%d %b %Y %H:%M"]
set chan [lindex $row 4]
if {$chan != $channel} {
puthelp "PRIVMSG $channel :\[\002$id\002\] $when from $by on $chan: $news"
} else {
puthelp "PRIVMSG $channel :\[\002$id\002\] $when from $by: $news"
}
} else {
if {$x == 1} {
puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
}
}
if {$x == 1} {
puthelp "PRIVMSG $channel :End of news"
}
mysqlendquery $result
set x [expr $x - 1]
}
}
} |
I didnt test this. _________________ Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/ |
|
| Back to top |
|
 |
CoCooner Voice
Joined: 09 Feb 2009 Posts: 3
|
Posted: Sat Oct 16, 2010 12:09 pm Post subject: |
|
|
great work thx
now i have another problem ...if no news in the database the bot is posting
Couldn't find any news (try adding news first!)
is it possible if no news in the databse the bot is nothing to announce ?
and I find it just on that one! news now can not retrieve it
[19:43:10] Tcl error [mcpshandlepubOK]: invalid command name "news" |
|
| Back to top |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Sat Oct 16, 2010 1:56 pm Post subject: |
|
|
| CoCooner wrote: | great work thx
now i have another problem ...if no news in the database the bot is posting
Couldn't find any news (try adding news first!)
is it possible if no news in the databse the bot is nothing to announce ?
|
Im my code chnge | Code: | | puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)" | to _________________ Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/ |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Oct 16, 2010 4:19 pm Post subject: |
|
|
| Code: |
if {![channel get $channel newsengine]} {
return 0
}
|
if you wish to exit from a loop either use 'break' or 'continue' (self both are explanatory), not 'return'.
You should move the SQL query outside the while loop and change the 'limit' to suit your needs, meaning it's stupid to do 5 queries when you can do just one to fetch 5 results from the table and then have them parsed how you wish, something like:
| Code: |
query
while (having results) {
parse them
}
free-up memory and close the mysql connection
|
Edit: In mysqlnews.sql I would change from "timestamp bigint(20)" to "timestamp int(10)" if the time is stored in this way.
Here is my (foolish) attempt on doing this:
| Code: |
bind time - "30 * * * *" autonews
bind time - "00 * * * *" autonews
proc autonews {mins hours days months years} {
global db_handle news_noflags
set limit 5
foreach channel [channels] {
if {![channel get $channel newsengine]} {
continue
}
set results [mysqlquery $db_handle "SELECT id, news, by, FROM_UNIXTIME(timestamp, "%d %b %Y %H:%M") AS when FROM news WHERE channel = $chan ORDER BY id DESC LIMIT $limit"]
if {![moreresult $results]} {
puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
} else {
puthelp "PRIVMSG $channel :NEWS:"
while {[set row [mysqlfetch $results]] != ''} {
set id [lindex $row 0]
set news [lindex $row 1]
set by [lindex $row 2]
set when [lindex $row 3]
puthelp "PRIVMSG $channel :\[\002$id\002\] $when from $by on $chan: $news"
}
puthelp "PRIVMSG $channel :End of news"
}
mysqlendquery $results
}
mysqlclose $db_handle
}
|
haven't tested it but theoretically should work. I'm not 100% sure about the 'FROM_UNIXTIME' thing. Anyway, I would appreciate some feedback on this.
user (a very resourceful fountain of information IMHO, too bad he's been idle lately, among others) once posted a decr proc you should use in your scripts:
| Code: |
proc decr var {
uplevel 1 [list incr $var -1]
}
|
Btw, ::mysql::map looks interesting.
Edit: Ahh, updated. Thanks username.  _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Tue Oct 18, 2011 2:13 am; edited 2 times in total |
|
| Back to top |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Sun Oct 17, 2010 3:21 am Post subject: |
|
|
Change | Code: | | foreach chan [channels] { | to | Code: | | foreach channel [channels] { |
_________________ Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/ |
|
| Back to top |
|
 |
|