RSS Feed Reader

By Ayon on Jul 16, 2009

Well finally after several hours of work and some regex help from guys on #help.script @ QuakeNet (you know who you are) i'm ready to release the first version of my rss feed reader.

I know there's some bugs here and there, but they'll be fixed along the way :)
but please let me know when you stumble over one :) i might not know about it

just type /rss or use the channel/menubar menu to open it

NOTE: this script requires MDX

Image

;=======================================================
; RSS Feed Reader v1.0
; written by Ayon
;
; Make sure the alias mdx links to the correct
; path of your MDX
;=======================================================

;=====[ READER GUI ]=====
dialog rss.gui {
  title "RSS Feed Reader v1.0 - by Ayon [/rss]"
  size -1 -1 536 297
  option dbu
  box "Archive", 1, 4 4 102 290
  box "Quick connect", 2, 108 4 318 22
  box "News", 3, 108 28 422 206
  box "Description", 4, 108 236 422 58
  list 5, 8 12 94 266, size
  button "Add", 6, 8 280 29 10
  button "Remove", 7, 72 280 29 10
  text "Address:", 8, 112 13 22 8
  edit "", 9, 136 12 202 10
  text "Port:", 10, 340 13 12 8
  edit "80", 11, 356 12 26 10
  button "Connect", 12, 384 12 37 10, default
  list 13, 112 36 414 194, size
  text "", 14, 112 244 413 44
  text "", 15, 108 124 421 8, center
  button "Edit", 16, 40 280 29 10
}
dialog rss.add.gui {
  title ""
  size -1 -1 186 42
  option dbu
  text "Title:", 1, 4 4 12 8
  edit "", 2, 28 4 154 10, autohs
  text "Address:", 3, 4 16 22 8
  edit "", 4, 28 16 114 10, autohs
  text "Port:", 5, 144 17 12 8
  edit "", 6, 160 16 22 10, autohs
  button "OK", 7, 52 28 37 12, ok
  button "Close", 8, 92 28 37 12, cancel
}

on *:DIALOG:rss.*:*:*:{
  if ($dname == rss.gui) {
    if ($devent == init) {
      mdxinit
      mdx SetControlMDX $dname 13 ListView report rowselect single grid > scripts\libs\mdx\views.mdx
      did -i $dname 13 1 headerdims 400 280 120
      did -i $dname 13 1 headertext $tabs(Title,URL,Published)
      did -h $dname 13
      did -f $dname 9
      did -b $dname 7,16
      rss.list.archive
    }
    elseif ($devent == sclick) {
      if ($did == 6) {
        dialog $iif($dialog(rss.add.gui),-g,-m) rss.add.gui rss.add.gui
      }
      elseif ($did == 16) {
        set %rss.edit.feed 1
        dialog $iif($dialog(rss.add.gui),-g,-m) rss.add.gui rss.add.gui
      }
      elseif ($did == 12) {
        if ($did($dname,9) && $did($dname,11)) {
          rss.connect $did($dname,9) $did($dname,11)
        }
      }
      elseif ($did == 13) {
        var %rss.sel.title = $xdid($did($dname,13).seltext,1)
        ;echo -atg %rss.sel.title
        var %rss.fname = rss
        var %rss.fsize = $file(%rss.fname).size
        bread %rss.fname 0 %rss.fsize &rss
        var %rss.pos.start = $bfind(&rss,1,$gettok(%rss.sel.title,$iif($numtok(%rss.sel.title,32) > 4,1-4,1-),32)).text
        var %rss.pos.start = $bfind(&rss,%rss.pos.start,<description>).text
        var %rss.pos.end = $bfind(&rss,%rss.pos.start,</description>).text
        var %rss.description = $striphtml($bvar(&rss,%rss.pos.start,$calc(%rss.pos.end - %rss.pos.start)).text)
        unset %string
        did -a rss.gui 14 %rss.description
      }
    }
    elseif ($devent == dclick) {
      if ($did == 5) {
        var %rss.link = $gettok($read($+($scriptdir,rss-archive.dat),$did($dname,5).sel),2,18)
        var %rss.port = $gettok($read($+($scriptdir,rss-archive.dat),$did($dname,5).sel),3,18)
        rss.connect %rss.link %rss.port
      }
      elseif ($did == 13) {
        var %rss.link = $xdid($did($dname,13).seltext,2)
        url -a %rss.link
      }
    }
    elseif ($devent == close) {
      if ($isfile(rss)) { .remove rss }
    }
  }
  elseif ($dname == rss.add.gui) {
    if ($devent == init) {
      if (!%rss.edit.feed) {
        dialog -t $dname Add Feed
      }
      elseif (%rss.edit.feed) {
        dialog -t $dname Edit Feed
      }
    }
    elseif ($devent == sclick) {
      if ($did == 7) {
        var %rss.title = $did($dname,2), %rss.link = $did($dname,4), %rss.port = $did($dname,6)
        if (!%rss.title) { var %rss.error = $+(- Missing feed title.,$crlf) }
        if (!%rss.link) { var %rss.error = $+(%rss.error,- Missing feed link.,$crlf) }
        if (!%rss.port) { var %rss.error = $+(%rss.error,- Missing feed port.) }
        if (!$regex(%rss.port,/[\d+]/g)) { var %rss.error = $+(%rss.error,- Post must be a number.,$crlf) }
        if (%rss.error) { noop $input($+(Following errors found:,$crlf,%rss.error),ho,RSS Feed Reader) }
        else {
          write $+($scriptdir,rss-archive.dat) %rss.title $chr(18) %rss.link $chr(18) %rss.port
          did -r rss.gui 5
          rss.list.archive
        }
      }
    }
  }
}
;=====[ ALIASES ]=====
alias mdx .dll $+($scriptdir,mdx.dll) $1-
alias mdxinit {
  mdx SetMircVersion $version
  mdx MarkDialog $dname
}
alias rss {
  dialog $iif($dialog(rss.gui),-g,-m) rss.gui rss.gui
}
alias rss.list.archive {
  var %i = 1, %x = $lines($+($scriptdir,rss-archive.dat))
  while (%x >= %i) {
    did -a rss.gui 5 $gettok($read($+($scriptdir,rss-archive.dat),%i),1,18)
    inc %i
  }
}
alias rss.connect {
  if ($isfile(rss)) { .remove rss }
  set %rss.domain $gettok($remove($1,http://),1,47)
  set %rss.subdomain $+(/,$gettok($remove($1,http://),2-,47))
  set %rss.port $iif($2,$2,80)
  if ($dialog(rss.gui) && (!%rss.publish)) {
    did -r rss.gui 13,14
    did -h rss.gui 13
    did -va rss.gui 15 Connecting and recieving info from $qt($+(%rss.domain,%rss.subomain,:,%rss.port))
  }
  sockopen rss %rss.domain %rss.port
}
alias htmlencode {
  var %str = $replace($1-,&amp;,&,&lt;,&#60;,&gt;,&#62;)
  var %str = $regsubex(%str,/&#(\d+?);/g,$chr(\1))
  var %str = $regsubex(%str,/&#x([\dA-F][\dA-F]);/g,$chr($base(\1,16,10)))
  return %str
}
alias striphtml {
  noop $regsub($htmlencode($1-),/(<(?:.+?)>)/g,$null,%string)
  return %string
}

;=====[ EVENT TRIGGER ]=====
#rss.trigger off
on 1:TEXT:!rss &:#:{
  if (!%rss.in.progress) {
    set %rss.chan $chan
    set %rss.publish 1
    set %rss.in.progress 1
    rss.public $2 $iif(!$3,80,$3)
  }
}
#rss.trigger end
alias rss.public {
  set %rss.publish 1
  set %rss.in.progress 1
  rss.connect $1 $iif(!$2,80,$2)
}

;=====[ MENU ]=====
menu menubar,channel {
  RSS Feed Reader
  .Reader:rss
  .Public trigger ( $+ $group(#rss.trigger) $+ ):$iif($group(#rss.trigger) == on,.disable,.enable) #rss.trigger | echo -atg * RSS trigger has been $iif($group(#rss.trigger) == on,enabled,disabled)
}

;=====[ SOCKET ]=====
on *:SOCKOPEN:rss:{
  sockwrite -n $sockname GET %rss.subdomain HTTP/1.1
  sockwrite -n $sockname Host: %rss.domain
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}
on *:SOCKREAD:rss:{
  sockread &rss
  breplace &rss 13 32 10 32
  bwrite rss -1 $remove(&rss,$cr,$lf)
  while ($sockbr) {
    sockread &rss
    breplace &rss 13 32 10 32
    bwrite rss -1 $remove(&rss,$cr,$lf)
  }
}
on *:SOCKCLOSE:rss:{
  if ($dialog(rss.gui) && (!%rss.publish)) {
    var %rss.fname = rss
    var %rss.fsize = $file(%rss.fname).size
    bread %rss.fname 0 %rss.fsize &rss
    var %rss.pos.itemStart = $bfind(&rss,1,<item).text
    var %rss.pos.itemEnd = $bfind(&rss,%rss.pos.itemStart,</item>).text
    while (%rss.pos.itemStart) {
      whilefix
      var %rss.item.string = $bvar(&rss,%rss.pos.itemStart,$calc(%rss.pos.itemEnd - %rss.pos.itemStart)).text
      var %rss.item.title = $striphtml($regml($regex(%rss.item.string,/<title>(.+)<\/title>/g)))
      var %rss.item.link = $striphtml($regml($regex(%rss.item.string,/<link>(.+)<\/link>/g)))
      var %rss.item.pub = $striphtml($iif($regml($regex(%rss.item.string,/<pubDate>(.+)<\/pubDate>/g)) == 0,N/A,$v1))
      var %rss.pos.itemStart = $bfind(&rss,%rss.pos.itemEnd,<item)
      var %rss.pos.itemEnd = $bfind(&rss,%rss.pos.itemStart,</item>)
      did -a rss.gui 13 $tabs($htmlencode(%rss.item.title),%rss.item.link,%rss.item.pub)
    }
    did -h rss.gui 15
    did -v rss.gui 13
    unset %rss.*
  }
  elseif (!$dialog(rss.gui) && (%rss.publish)) {
    if (!%rss.anti.flood) { set %rss.anti.flood 3 }
    msg %rss.chan RSS Feed from: $+(%rss.domain,%rss.subdomain)
    var %rss.fname = rss
    var %rss.fsize = $file(%rss.fname).size
    bread %rss.fname 0 %rss.fsize &rss
    var %rss.pos.itemStart = $bfind(&rss,1,<item).text
    var %rss.pos.itemEnd = $bfind(&rss,%rss.pos.itemStart,</item>).text
    var %i = 1
    while (%rss.anti.flood >= %i) {
      whilefix
      var %rss.item.string = $bvar(&rss,%rss.pos.itemStart,$calc(%rss.pos.itemEnd - %rss.pos.itemStart)).text
      var %rss.item.title = $striphtml($regml($regex(%rss.item.string,/<title>(.+)<\/title>/g)))
      var %rss.item.link = $striphtml($regml($regex(%rss.item.string,/<link>(.+)<\/link>/g)))
      var %rss.pos.itemStart = $bfind(&rss,%rss.pos.itemEnd,<item)
      var %rss.pos.itemEnd = $bfind(&rss,%rss.pos.itemStart,</item>)
      msg %rss.chan Title: $htmlencode(%rss.item.title) Link: %rss.item.link
      inc %i
    }
    unset %rss.*
  }
}

Comments

Sign in to comment.
dma   -  Dec 23, 2015

I need Help Getting started.. ill start with yahoo.sports or news

 Respond  
Cold_Fussion   -  Nov 27, 2010

WHILEFIX -> what code is in it??????? would help if u added that in. lol FAIL

 Respond  
Nuk3d   -  Feb 28, 2010

where can you find the aliases you need..

 Respond  
fraguk   -  Sep 27, 2009

WHILEFIX Unknown command

 Respond  
DJ_Nick   -  Sep 14, 2009

where do you get the mdx.dll part of the script from because that is the touble i'm having and also i am having this trouble as well Line too long: $bvar (line 214, script.ini)

 Respond  
err0r007   -  Aug 01, 2009

you are missing several alias you will need to make this work.. whilefix, tabs, etc. You need an alias for views.dll instead of using your path.. I would suggest that once you fix this, test this in a clean version of mirc to ensure it works properly. I'll save rating it til there is a working copy

 Respond  
Ayon   -  Jul 22, 2009

@Hawkee, FordLawnmower & Knoeki:
Thanks for all the good feedback on my script :) I've done what you've said and added 4 routines that's needed for this to work properly. Also updated the top comment abit with a short instruction for the mdx alias. Hopefully it'll work better now :)

 Respond  
knoeki   -  Jul 16, 2009

Ah, cool stuff :_) would be nice if .rar would be accepted for uploads there as well then, if possible... but it's getting a bit off-topic now :p

 Respond  
Hawkee   -  Jul 16, 2009

knoeki, we're still working on redoing the script engine here. It's really old and needs an entire re-hash. I'm still trying to figure out how to handle the file uploads though. We have to be careful to virus check each one before they become public.

 Respond  
knoeki   -  Jul 16, 2009

alternatively, it could be zipped up, including mdx, and submitted as a script here ;_)

 Respond  
Hawkee   -  Jul 16, 2009

I agree with FordLawnmower, I think the additional functions should just be included.

 Respond  
FordLawnmower   -  Jul 16, 2009

@Ayon , You really must include all the routines this script uses , in the code. You are not going to find many people who are willing to put your strip and encode routines in there alias.ini to use this script. I see you have put a lot of work into this but not including the whole script has turned it into a puzzle that not many people will be willing to solve.

 Respond  
knoeki   -  Jul 16, 2009

Can you offer a link to a working version of MDX in your introduction?

I'm afraid it will be hard, he's gone for a month or so due to moving to a new appartment, and it takes a while to get internet there. :|

I'll try to play with it and post back when I get positive results.

 Respond  
Hawkee   -  Jul 16, 2009

This looks very promising but I'm having some trouble. I downloaded MDX, but it may not be the right version. I downloaded it from mirc.net by DragonZap. The problem is that there is no mdxinit alias included with this DLL, so I'm getting a function not found error. Can you offer a link to a working version of MDX in your introduction?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.