Yeah, that was my bad. It is this line:gamer12 wrote:It is doing what I wanted ;D
the only problem is, it keeps on displaying the same item again and again. It should display only when its changed
any help in it will be appreciated.
Thanks again speechless. Im speechless ;D
Code: Select all
if {[string equal "magic" $arg]} { regexp "$::news::ary(snip_lastid)" [lindex $casafreenews 1] - ::news::ary(last) }
Code: Select all
if {[string equal "magic" $arg]} { regexp "$::news::ary(snip_lastid)" [lindex $casafreenews 2] - ::news::ary(last) }
Code: Select all
set ary(bind_time) "*" ; # every minute
# url to news page
set ary(page) http://travian.gamingcrazy.net/erep-api/feeds/militaryfeeds.xml
# parsing regex used to gather news
set ary(regex) {<info>(.*?)</info>.*?<link>(.*?)</link>}
# how to snip last-id from the url mask
set ary(snip_lastid) {^(.*?)$}
# max amount of news items to announce
set ary(max_bot) 1
# max amount of news items for users
set ary(max_user) 1
Code: Select all
# Puh Rum Pum Pum Pum
# This script will announce news just like an rss script
# as well as allowing users to type commands and see
# the latest news via notice as well. Fully configurable.
# Enjoy, and may the force be with you.... always....
# speechles was here :P
package require http
setudef flag nopubnews
namespace eval news {
# config - make your changes here
# trigger character
set ary(pref) "!"
# command used to reply to user
# this can be a list of space delimited commands
set ary(commands) "events"
# amount user can issue before throttle
set ary(throttle) 2
# throttle time
set ary(throttle_time) 30
# time to announce new news items
# this can be a list of space delimited time binds.
# the one you wish to use for bind_time uncommented.
# set ary(bind_time) "00* 15* 30* 45*" ; # every 15 minutes
# set ary(bind_time) "00* 30*" ; # every 30 minutes
# set ary(bind_time) "00*" ; # every 60 minutes exactly on the hour
set ary(bind_time) "*" ; # every minute
# url to news page
set ary(page) http://travian.gamingcrazy.net/erep-api/feeds/militaryfeeds.xml
# parsing regex used to gather news
set ary(regex) {<info>(.*?)</info>.*?<link>(.*?)</link>}
# how to snip last-id from the url mask
set ary(snip_lastid) {^(.*?)$}
# max amount of news items to announce
set ary(max_bot) 1
# max amount of news items for users
set ary(max_user) 1
# display format for news messages, variables are: %info and %url
# these can be used and will be replaced with actual values, newline (\n) will
# let you span multiple lines if you wish. If something is too long it will
# be cut off, be aware of this... use colors, bold, but remember to \escape any
# special tcl characters.
set ary(display_format) "\[\002eRepublik\002\] \002\0033\Event:\002\ %info. - \002\0032\Link:\002\ %url"
# script version
set ary(version) "2.3"
}
# binds
foreach bind [split $::news::ary(commands)] {
bind pub -|- "$::news::ary(pref)$bind" ::news::pub_
bind msg -|- "$::news::ary(pref)$bind" ::news::msg_
}
foreach bind [split $::news::ary(bind_time)] {
bind time - $bind ::news::magic_
}
bind time - ?0* ::news::throttleclean_
namespace eval news {
# main - time bind - magic
proc magic_ {args} {
news_ $::botnick [getchanhost $::botnick] $::botnick "all" "magic"
}
# main - msg bind - notice
proc msg_ {nick uhost hand arg} {
news_ $nick $uhost $hand $nick "notice"
}
# main - pub bind - privmsg
proc pub_ {nick uhost hand chan arg} {
if {[channel get $chan nopubnews]} { return }
news_ $nick $uhost $hand $chan "privmsg"
}
# sub - give news
proc news_ {nick uhost hand chan arg} {
global existss
if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::news::ary(throttle_time)]} {
putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!"
}
set a "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
set t [::http::config -useragent $a]
catch { set t [::http::geturl $::news::ary(page) -timeout 30000] } error
# error condition 1, socket error or other general error
if {![string match -nocase "::http::*" $error] && ![isbotnick $nick]} {
putserv "$arg $chan :[string totitle [string map {"\n" " | "} $error]] \( $::news::ary(page) \)"
return
}
# error condition 2, http error
if {![string equal -nocase [::http::status $t] "ok"] && ![isbotnick $nick]} {
putserv "$arg $chan :[string totitle [::http::status $t]] \( $::news::ary(page) \)"
return
}
set html [::http::data $t]
::http::cleanup $t
set casafreenews [regexp -all -inline "$::news::ary(regex)" $html]
set c 0
foreach {junk info link} $casafreenews {
incr c ; set url "http://erepublik.com$link"
if {[isbotnick $nick]} {
if {$c > $::news::ary(max_bot)} { break }
regexp "$::news::ary(snip_lastid)" $url - id
if {[info exists ::news::ary(last)]} { if {$id == $::news::ary(last)} { break } }
} elseif {$c > $::news::ary(max_user)} { break }
set output [string map [list "%info" "[mapit_ [string map [list "<br />" ""] $info]]" "%url" "$url"] $::news::ary(display_format)]
if {![string equal "magic" $arg]} {
foreach line [split $output "\n"] {
if {![info exists existss($chan,$line)]} {
puthelp "$arg $chan :$line"
set existss($chan,$line) "[unixtime]"
}
}
} else {
foreach ch [channels] {
if {[channel get $ch nopubnews]} { continue }
foreach line [split $output "\n"] {
if {![info exists existss($ch,$line)]} {
puthelp "privmsg $ch :$line"
set existss($ch,$line) "[unixtime]"
}
}
}
}
if {[string equal "magic" $arg]} { regexp "$::news::ary(snip_lastid)" [lindex $casafreenews 2] - ::news::ary(last) }
}
}
# sub - map it
proc mapit_ {t} { return [string map [list "'" "'" """ "\""] $t] }
# Throttle Proc (slightly altered, super action missles) - Thanks to user
# see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc throttle_ {id seconds} {
if {[info exists ::news::throttle($id)]&&[lindex $::news::throttle($id) 0]>[clock seconds]} {
set ::news::throttle($id) [list [lindex $::news::throttle($id) 0] [set value [expr {[lindex $::news::throttle($id) 1] +1}]]]
if {$value > $::news::ary(throttle)} { set id 1 } { set id 0 }
} {
set ::news::throttle($id) [list [expr {[clock seconds]+$seconds}] 1]
set id 0
}
}
# sub - clean throttled users
proc throttleclean_ {args} {
set now [clock seconds]
foreach {id time} [array get ::news::throttle] {
if {[lindex $time 0]<=$now} {unset ::news::throttle($id)}
}
}
}
putlog "news and announce.tcl v$::news::ary(version) loaded."
I know you pace the floor looking for someone to help. Don't get me wrong. I can sense the eagerness. The feeling of needing something to do to make your tcl skills better. I dig it. You are useful. You submit scripts. Well done.Madalin wrote:* snipped exploitable code *
Code: Select all
set existss($ch,$line) "[unixtime]"
Code: Select all
# Puh Rum Pum Pum Pum
# This script will announce news just like an rss script
# as well as allowing users to type commands and see
# the latest news via notice as well. Fully configurable.
# Enjoy, and may the force be with you.... always....
# speechles was here :P
package require http
setudef flag usenews
namespace eval readxml {
# config - make your changes here
# trigger character
set ary(pref) "!"
# command used to reply to user
# this can be a list of space delimited commands
set ary(commands) "news"
# amount user can issue before throttle
set ary(throttle) 2
# throttle time
set ary(throttle_time) 30
# time to announce new news items
# this can be a list of space delimited time binds.
# the one you wish to use for bind_time uncommented.
# set ary(bind_time) "00* 15* 30* 45*" ; # every 15 minutes
# set ary(bind_time) "00* 30*" ; # every 30 minutes
# set ary(bind_time) "00*" ; # every 60 minutes exactly on the hour
set ary(bind_time) "*" ; # every minute
# url to news page
set ary(page) http://travian.gamingcrazy.net/erep-api/feeds/militaryfeeds.xml
# parsing regex used to gather news
set ary(regex) {<info>(.*?)</info>.*?<link>(.*?)</link>}
# how to snip last-id from the url mask
set ary(snip_lastid) {^(.*?)$}
# max amount of news items to announce
set ary(max_bot) 5
# max amount of news items for users
set ary(max_user) 5
# display format for news messages, variables are: %info and %url
# these can be used and will be replaced with actual values, newline (\n) will
# let you span multiple lines if you wish. If something is too long it will
# be cut off, be aware of this... use colors, bold, but remember to \escape any
# special tcl characters.
set ary(display_format) "\[\002NEWS\002\] %url\n%info"
# script version
set ary(version) "2.3"
}
# binds
foreach bind [split $::readxml::ary(commands)] {
bind pub -|- "$::readxml::ary(pref)$bind" ::readxml::pub_
bind msg -|- "$::readxml::ary(pref)$bind" ::readxml::msg_
}
foreach bind [split $::readxml::ary(bind_time)] {
bind time - $bind ::readxml::magic_
}
bind time - ?0* ::readxml::throttleclean_
namespace eval readxml {
# main - time bind - magic
proc magic_ {args} {
news_ $::botnick [getchanhost $::botnick] $::botnick "all" "magic"
}
# main - msg bind - notice
proc msg_ {nick uhost hand arg} {
news_ $nick $uhost $hand $nick "notice"
}
# main - pub bind - privmsg
proc pub_ {nick uhost hand chan arg} {
if {![channel get $chan usenews]} { return }
news_ $nick $uhost $hand $chan "privmsg"
}
# sub - give news
proc news_ {nick uhost hand chan arg} {
if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::readxml::ary(throttle_time)]} {
putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!"
# that missing return mentioned by caeser in this thread
# now makes its official appearance below...
return
}
set a "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
set t [::http::config -useragent $a]
catch { set t [::http::geturl $::readxml::ary(page) -timeout 30000] } error
# error condition 1, socket error or other general error
if {![string match -nocase "::http::*" $error] && ![isbotnick $nick]} {
putserv "$arg $chan :[string totitle [string map {"\n" " | "} $error]] \( $::readxml::ary(page) \)"
return
}
# error condition 2, http error
if {![string equal -nocase [::http::status $t] "ok"] && ![isbotnick $nick]} {
putserv "$arg $chan :[string totitle [::http::status $t]] \( $::readxml::ary(page) \)"
return
}
set html [::http::data $t]
::http::cleanup $t
set casafreenews [regexp -all -inline "$::readxml::ary(regex)" $html]
set c 0
foreach {junk info link} $casafreenews {
incr c ; set url "http://travian.gamin.ds$link"
if {[isbotnick $nick]} {
if {$c > $::readxml::ary(max_bot)} { break }
if {[info exists ::readxml::ary(last)]} { if {$url == $::readxml::ary(last)} { break } }
} elseif {$c > $::readxml::ary(max_user)} { break }
set output [string map [list "%info" "[mapit_ [string map [list "<br />" ""] $info]]" "%url" "$url"] $::readxml::ary(display_format)]
if {![string equal "magic" $arg]} {
foreach line [split $output "\n"] { puthelp "$arg $chan :$line" }
} else {
foreach ch [channels] {
if {![channel get $ch usenews]} { continue }
foreach line [split $output "\n"] { puthelp "privmsg $ch :$line" }
}
}
}
if {[string equal "magic" $arg]} { set ::readxml::ary(last) "http://travian.gamin.ds[lindex $casafreenews 2]" }
}
# sub - map it
proc mapit_ {t} { return [string map [list "'" "'" """ "\""] $t] }
# Throttle Proc (slightly altered, super action missles) - Thanks to user
# see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc throttle_ {id seconds} {
if {[info exists ::readxml::throttle($id)]&&[lindex $::readxml::throttle($id) 0]>[clock seconds]} {
set ::readxml::throttle($id) [list [lindex $::readxml::throttle($id) 0] [set value [expr {[lindex $::readxml::throttle($id) 1] +1}]]]
if {$value > $::readxml::ary(throttle)} { set id 1 } { set id 0 }
} {
set ::readxml::throttle($id) [list [expr {[clock seconds]+$seconds}] 1]
set id 0
}
}
# sub - clean throttled users
proc throttleclean_ {args} {
set now [clock seconds]
foreach {id time} [array get ::readxml::throttle] {
if {[lindex $time 0]<=$now} {unset ::readxml::throttle($id)}
}
}
}
putlog "news and announce.tcl v$::readxml::ary(version) loaded."
Just remember how to spell my name, speechles<guy1> wtf.. that speechles guy is a dick
<guy2> tell me about it
<speechles> SCREW YOU GUYS!
Code: Select all
if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::readxml::ary(throttle_time)]} {
putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!"
}
You are indeed correct. It needs a return or the evaluation needs to contain } else { # != throttled/botnick }caesar wrote:I was referring to:Isn't the whole idea to STOP the execution of the rest of the code if it's throttled? Maybe I'm missing something.Code: Select all
if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::readxml::ary(throttle_time)]} { putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!" }
It's more about it than that. It's about alterations, and who gets the credit/blame for the bugs those alterations cause. In this case I would get the complaints for it when it wasn't my doing. Right? Maybe? Bueller? Bueller?caesar wrote:Anyway, you two mind your manners. We aren't here in any sort of competition, so there's no 1st place, second or whatever. We all want to learn new stuff and expand our skills. Don't we?
I always prefer to wear shoes when walking outdoors. Don't you? Never know when you are going to step on a nail. Using that $line thing is akin to going barefoot. All I'm saying... hehcaesar wrote:Regarding the $line exploit, chill, the line is taken from that xml page, so I doubt they will start exploiting their own users that want to fetch some info.Good point anyway.
Dude, your name is hard to remember. Is it AE or EA? Without looking I have a 50/50 chance of getting your name right..caesar wrote:As for spelling names, speechles you are no stranger to this either.