Official mIRC forums announcement

By Wims on Feb 01, 2015

This is a code I made for a bot running on my channel, it displays the new posts made to the different thread on the official mIRC forum
It currently only check for the bugs and features forums but can be easily edited to support others forums.

Example:

[Bug Reports] [Nick changes ignore '[x] User addresses' option.] [Thread's Author: Raccoon] [Post's Author: Khaled] - Link: http://forums.mirc.com/ubbthreads.php/topics/250521/Nick_changes_ignore_%27%5Bx%5D_User_#Post250781

One little problem is that it will reannounce a previous post if the last post for the thread has been deleted, I didn't bother dealing with this.

Setup:
You must have $decode enabled (you can keep $decode disabled if you provide your own $safe alias which doesn't use $decode)
The code is currently made to be used on one connection and one channel only, locate the alias 'getforum_warn' line 86 and edit the channel name here.
You can easily edit this alias to include this code to your existing bot and/or to support multi servers/channels.

WATCH OUT for the first time you run this, it will find a lot of new posts since your database is empty, there is an antiflood which will result in one message per second sent, you can also edit that if you want (line 79 in the timer)

on *:start:{
  .hmake mircforumdb
  if ($exists($scriptdirmircforumdb.txt)) {
    hload mircforumdb $qt($scriptdirmircforumdb.txt)
  }
  .timergetforum 0 30 getforum
}

alias getforum {
  hadd -m getforum state1 login_http
  hadd getforum state2 login_http
  sockclose getforum1
  sockopen getforum1 forums.mirc.com 80
  sockclose getforum2
  sockopen getforum2 forums.mirc.com 80
}

on *:sockopen:getforum?:{
  var %id $right($sockname,1)
  if ($sockerr) { 
    write getforum.log $time(HH:nn:ss) sockopen error $v1 on socket $sockname : $sock($sockname).wserr $sock($sockname).wsmsg
    return
  }
  var %sw sockwrite -n $sockname,%GET $iif(%id == 1,/ubbthreads.php/forums/8/1/Bug_Reports,/ubbthreads.php/forums/6/1/Feature_Suggestions)
  %sw GET %GET HTTP/1.1
  %sw Host: forums.mirc.com
  %sw User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0
  %sw Connection: Close
  %sw
}
on *:sockread:getforum?:{
  var %id $right($sockname,1)
  if ($sockerr) { write getforum.log $time(HH:nn:ss) sockread error $v1 on socket $sockname $sock($sockname).wserr $sock($sockname).wsmsg | return }
  var %a | sockread %a | tokenize 32 %a
  if ($hget(getforum,state $+ %id) == login_http) {
    if ($2 != 200) { write getforum.log $time(HH:nn:ss) sockread issue: no 200 received when trying to grab $iif(%id == 1,bugs,feature) | sockclose $sockname | return }
    hadd getforum state $+ %id login_headers
  }
  elseif ($hget(getforum,state $+ %id) == login_headers) {
    if (!%a) hdel getforum state $+ %id
  }
  elseif ($hget(getforum,state $+ %id) == topicauthor) {
    if ($regex(%a,/\s*<span class="small">by/)) {
      hadd getforum currentauthor $+ %id $remove($noHTML(%a),by)
      hadd getforum state $+ %id time
    }
  }
  elseif ($hget(getforum,state $+ %id) == time) {
    if ($regex(r,%a,m@\s*<a href="/(ubbthreads\.php/[^"]+)"@)) {
      hadd getforum currentlinklastpost $+ %id http://forums.mirc.com/ $+ $urlencode($regml(r,1))
      noop $regex($regml(r,1),/^(.*)(#.*)$/)
      hadd getforum currentpost $+ %id $regml(2)
      hadd getforum state $+ %id lastpostauthor
    }
  }
  elseif ($hget(getforum,state $+ %id) == lastpostauthor) {
    if ($regex(%a,m@\s*<a href="/ubbthreads\.php/users/)) {
      hadd getforum currentlastpostauthor $+ %id $noHTML(%a)
      if ($hget(mircforumdb,$hget(getforum,currentid $+ %id)) == $null) || ($v1 != $hget(getforum,currentpost $+ %id)) {
        var %msg $iif(%id == 1,[Bug Reports],[Feature Suggestions]) $+([,$iif($v1 == 1 && $hget(getforum,currentname $+ %id) == mIRC beta,$+($chr(2),$chr(31),$v1,$chr(15)),$hget(getforum,currentname $+ %id)),]) [Thread's Author: $hget(getforum,currentauthor $+ %id) $+ ] [Post's Author: $hget(getforum,currentlastpostauthor $+ %id) $+ ] - Link: $hget(getforum,currentlinklastpost $+ %id) 
        noop $getforum_queue_push(%msg)
        hadd -m mircforumdb $hget(getforum,currentid $+ %id) $hget(getforum,currentpost $+ %id)
      }
      hdel getforum state $+ %id 
    }
  }
  else {
    if ($regex(%a,m@\s*(<a href="/ubbthreads\.php/topics/([^/]+)[^"]+.*)\s*@)) {
      hadd getforum state $+ %id topicauthor
      hadd getforum currentid $+ %id $regml(2)
      hadd getforum currentname $+ %id $html2ascii($noHTML($regml(1)))
    }
  }
}
on *:sockclose:getforum?:{
  if ($sock(getforum*,0) == 1) {
    var %a 1
    while ($getforum_queue_pop != $null) {
      .timergetforumsend $+ %a 1 %a getforum_warn $safe($v1)
      inc %a
    }
    if ($hget(getforum)) hfree getforum
  }
}

alias getforum_warn {
  msg #channel $1-
}
alias -l safe return $!decode( $encode($1,m) ,m)
alias -l HT2AS {
  var %A quot amp lt gt nbsp iexcl cent pound curren yen brvbar sect uml copy ordf $&
    laquo not shy reg macr deg plusmn sup2 sup3 acute micro para middot cedil sup1 $&
    ordm raquo frac14 frac12 frac34 iquest Agrave Aacute Acirc Atilde Auml Aring AElig $&
    Ccedil Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml ETH Ntilde Ograve Oacute $&
    Ocirc Otilde Ouml times Oslash Ugrave Uacute Ucirc Uuml Yacute THORN szlig agrave $&
    aacute acirc atilde auml aring aelig ccedil egrave eacute ecirc euml igrave iacute $&
    icirc iuml eth ntilde ograve oacute ocirc otilde ouml divide oslash ugrave uacute $&
    ucirc uuml yacute thorn yuml trade
  var %B 34 38 60 62 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 $&
    177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 $&
    199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 $&
    221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 $&
    243 244 245 246 247 248 249 250 251 252 253 254 255 153
  return $chr($gettok(%B,$findtokcs(%a,$1,32),32))
}
alias -l html2ascii {
  var %r /&(.{2,6});/Ug
  return $regsubex($1-,%r, $iif(#* iswm \t, $chr($mid(\t,2) ), $HT2AS(\t) ))
}
alias -l urlEncode return $regsubex($1, /(\W)/g, $+(%, $base($asc(\t), 10, 16, 2)))
alias -l noHTML return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,)
alias getforum_queue_push {
  if (!$window(@queue_getforum)) window -h @queue_getforum
  aline @queue_getforum $1
}
alias getforum_queue_pop {
  var %tok = $line(@queue_getforum, 1)
  if (!$line(@queue_getforum,0)) window -c @queue_getforum
  else dline @queue_getforum 1
  return %tok
}

Comments

Sign in to comment.
wobbleidz   -  Jun 22, 2015

Can I get help making this work with my PHP-Fusion website? That'd be so awesome

raccoon  -  Jun 24, 2015

What makes you think it even relates? This is simple content specific page scraping. The code is specialized for parsing absolutely only one thing: The recent activity page on mirc.com's ubbthreads web forum. You're asking an auto mechanic to build you an iphone.

wobbleidz  -  Jun 24, 2015

I don't think you understood my question, I need this code to work with a "bot" that would announce in the channel when a new forum post was made on my php-fusion forum, I assumed it was the same principle, your arguement that I'm asking a mechanic to build an iphone is irrelevant.

Wims  -  Jun 24, 2015

Hey, while the principle might be the same, it might not work exactly the same depending on how your forum works exactly, feel free to join #mircscripting @ irc.swiftirc.net and I'll help you there :)

@raccoon: I'm not looking at the recent activiy page ^^

Sign in to comment

Hawkee   -  Feb 05, 2015

Looks like you've got a misspelled word in your title.

Wims  -  Feb 05, 2015

Lol, fixed it, thanks!

Sign in to comment

raccoon   -  Feb 01, 2015

What about a feature to only track posts sent by Khaled?

Wims  -  Feb 01, 2015

It's not the point of that script, but you could eventually use this code and add all forums to it, then you would just add a check on the author of the post to match Khaled's name lol :)

sagargulati  -  Feb 06, 2015

@Hawkee : PM? No response? O.o

Sign in to comment

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.