This will update the channel topic, provided you are an op on the channel given,
and the channel topic doesnt match the data from the page you are requesting..


Usage (Please note, the channel name required):
Code:
/updatetopic #channel

You will need to set your site and data page in the 'alias updatetopic' code..
Code:
;--Start topic update timer(s) when you join your set channel(s)..
on me:*:join:#mychannelname: {
  ;-- First time waits 5 seconds to run,
  ;-- so you have a chance to get channel ops..
  .timerupdtopicjoin 1 5 updatetopic $chan
  ;-- Second timer runs every 1800 seconds (30 mins)
  .timeruptopinter 0 1800 updatetopic $chan
}
;-- Alias to set the data to hash tables for easy retrieval..
alias updatetopic {
  if ($me !isop $$1) { echo $color(info2) -at * Topic Update Error: You are not an op on $1 , halting topic update check. }
  else {
    var %s = $+(topicup.,$$1)
    if ($sock(%s)) { sockclose %s }
    ;- set the site name:
    hadd -m %s host mysite.com
    ;- Set the page you want to GET, using the
    ;- preceding forward slash '/' as shown below.
    hadd -m %s get /news.php
    hadd -m %s read $false
    sockopen %s $hget(%s,host) 80
  }
}
;-- Open the socket to get the data...
on *:sockopen:topicup.*: {
  if ($sockerr) { echo $color(info2) -at * Socket Open ERROR: $sock($sockname).wsmsg | return }
  sockwrite -nt $sockname GET $hget($sockname,get) HTTP/1.1
  sockwrite -nt $sockname Host: $hget($sockname,host)
  sockwrite -nt $sockname Accept-Language: en-us
  sockwrite -nt $sockname User-Agent: Mozilla/??
  sockwrite -nt $sockname $+(Connection: close,$str($crlf,2))
}
;-- Read the socket data..
on *:sockread:topicup.*: {
  var %t, %s = $sockname, %c = $gettok(%s,2,46)
  sockread %t
  if ($sockerr) { echo $color(info2) -at * Socket Read ERROR: $sock(%s).wsmsg | return }
  if (%t == $null) { hadd -m %s read $true }
  if (($hget(%s,read)) && (%t != $null)) {
    if ($chan(%c).topic != %t) { topic %c %t }
  }
}


Some side notes:

  • There is only a basic check to make sure you are an op on the channel given.
  • There is no formatting of the page output, so if it has HTML in it, you will need to parse that..
  • This code assumes there will only be one line of page data for the topic text.
  • you can use this for multiple channels, by comma seperating them in the on join event, eg:
    on me:*:join:#mychan1,#mychan2,#mychan3: { ... }


I hope this makes sence, and gets you what you are looking for, good luck and happy scripting. =)

Last edited by Twitch; 11/04/12 04:57 PM.

Lost in your digital reality.
#mIRC / #Helpdesk on DALnet.