Code: Select all
# ----------------------------------------------------------------------
# news
# !news
# Querys the last 5 lines of news from the database or the news line
# number entered
# ----------------------------------------------------------------------
Code: Select all
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]
}
}
}
Im my code chngeCoCooner 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 ?
Code: Select all
puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
Code: Select all
return 0
Code: Select all
if {![channel get $channel newsengine]} {
return 0
}
Code: Select all
query
while (having results) {
parse them
}
free-up memory and close the mysql connection
Code: Select all
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
}
Code: Select all
proc decr var {
uplevel 1 [list incr $var -1]
}
Code: Select all
foreach chan [channels] {
Code: Select all
foreach channel [channels] {