Jethro wrote:
Well, it's expected to get the result repeated if there's no new post made...
that creates a tiny little problem... if you have it checking the site every 30 seconds seconds for new posts it will just keep repeating the same already mentioned post if no new one is created. i tried creating a variable using
set %norepost $+($hget(data4,1).item)
and checking against it before messaging the channel. unfortunately i couldn't make this work. any ideas on how to check if you've already used a post before proceeding with the action?
this is what i have so far, but it stops displaying new posts to the channel :(
alias -l reddit {
var %sockname = reddit2
if ($sock(%sockname)) sockclose $v1
sockopen %sockname www.reddit.com 80
sockmark %sockname msg $1
inc %i
}
alias -l trans {
return $replace($1,<,<,>,>,",", ,$chr(160),&,&,&#39;,')
}
on *:sockopen:reddit2:{
if ($sockerr) {
echo 4 -ag $gettok($sock(reddit).mark,2,32) Error Connecting to $sock(reddit).addr
}
var %reddit2 = sockwrite -nt reddit2
%reddit2 GET $+(/r/,%reddits,/new.json?sort=new,$iif($hget(reddit,id),&after= $+ $v1)) HTTP/1.0
%reddit2 Connection: close
%reddit2 Host: $+($sock($sockname).addr,$str($crlf,2))
}
on *:sockread:reddit2:{
if ($sockerr) {
echo 4 $gettok($sock(reddit).mark,2,32) Error Reading $sock(reddit).addr
return
}
sockread &reddit2
var %g2 = $bvar(&reddit2,1-).text
if ($regex(%g2,/"title"\: "(.*)"/)) {
hadd -m data3 $gettok($trans($regml(1)),1,34)
}
if ($regex(%g2,/"id"\: "(.*)"/)) {
hadd -m reddit status old
if ($hget(reddit,id) != $gettok($trans($regml(1)),1,34)) {
hadd -m reddit id $v2
hadd -m reddit status new
hadd -m data4 $+($gettok($+(http://redd.it/,$&
$trans($regml(1))),1,34))
}
}
if ($regex(%g2,/"author"\: "(.*)"/)) {
hadd -m data5 $+($chr(3),12,$gettok($regml(1),1,34))
reddit.finished
sockclose $sockname
}
}
on *:sockclose:reddit2:{
reddit.finished
}
alias reddit.finished {
if ($hget(reddit,status) == new) && ($hget(data3)) && ($hget(data4)) {
$sock($sockname).mark $&
$+($chr(29),$hget(data3,1).item,$chr(32),$hget(data3,1).data,$chr(29),$chr(32),$chr(2),-,$chr(2)) $&
$hget(data4,1).item by $hget(data5,1).item
hfree -w data*
}
}
on me:*:join:#:{
if (%true) notice $me Reddit has been toggled off. Right-click on $&
the nicklist or channel to toggle it on. | unset %true
}
on *:disconnect: if (%reddits) $+(.timer,#,$network) off | set -e %true 1
on me:*:part:#: if (%reddits) $+(.timer,#,$network) off | set -e %true 1
on *:kick:#:{
if ($knick == $me) && (%reddits) $+(.timer,#,$network) off
set -e %true 1
}
on *:quit:{
if ($nick == $me) && (%reddits) {
var %c = 1
while ($comchan($me,%c)) {
$+(.timer,$v1,$network) off
set -e %true 1
inc %c
}
}
}
menu channel,nicklist {
Reddit
.ON {
if (!%reddits) {
set -e %reddits $$?"Which Reddit to Watch?"
set -e %reddittime $$?"How often do you want the latest post checked $&
and sent to the channel in seconds?"
$+(.timer,#,$network) 0 %reddittime reddit #
echo 2 # * Reddit Set for: $+($chr(2),%reddits)
echo 2 # * Time Interval in Seconds: $+($chr(2),%reddittime)
if (%true) unset $v1
}
else echo 4 # * Reddit is Already Switched On!
}
.OFF {
if (%reddits) {
$+(.timer,#,$network) off
echo 2 * Reddit Has Been Turned Off!
unset %reddit* %true
}
else echo 4 # * Reddit is Already Switched Off!
}
}
seriously, been cracking at this all day and i can't figure out a way to stop messaging posts that it has already mentioned. it's driving me craaaaaaaaaaaazy