mIRC Home    About    Download    Register    News    Help

Print Thread
Update topic #237021 11/04/12 01:28 PM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Hi guys.
Could someone make a really simple snippet for me that checks an online file which contains only one line. For example http://mysite.com/news.php , and all it says is - I am the new topic . So could you make it, so each 30 minutes, this script checks this website and if the line differs from the previously checked line, it changes it to the new one?

Example: if website says - I am the new topic , and the actual topic is I am very old topic, then it changes it to I am the new topic .

Thanks wink

Re: Update topic [Re: spermis] #237026 11/04/12 04:53 PM
Joined: Mar 2012
Posts: 38
Twitch Offline
Ameglian cow
Offline
Ameglian cow
Joined: Mar 2012
Posts: 38
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.
Re: Update topic [Re: Twitch] #237039 12/04/12 06:14 AM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Thanks, but it somehow doesn't update. The webpage doesnt contain any html, but it just doesnt. One interesting thing was, when I changed something in news.php file and got an error, and then tried to updatetopic, it changed the topic to that PHP error, but when everything was fine, it didnt update it.

Yes I am OP on the channel, and I think that I have provided everything correctly on this part
Code:
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 trick-jumps.lv
    ;- Set the page you want to GET, using the
    ;- preceding forward slash '/' as shown below.
    hadd -m %s get /mirc/news.php
    hadd -m %s read $false
    sockopen %s $hget(%s,host) 80
  }
}


You can see the page - http://trick-jumps.lv/mirc/news.php , it could not get any simpler, but still, something is wrong. What could it be?

Re: Update topic [Re: spermis] #237040 12/04/12 06:45 AM
Joined: Mar 2012
Posts: 38
Twitch Offline
Ameglian cow
Offline
Ameglian cow
Joined: Mar 2012
Posts: 38
oh, sorry, that's my fault, I forgot the -f switch in the sockread command. with out this switch the line would need to be $crlf terminated.. this switch forces mIRC to read the buffer data regardless.

so in the 'on sockread' event, you will see;

Code:
sockread %t


just add the -f switch, like so;

Code:
sockread -f %t


Lost in your digital reality.
#mIRC / #Helpdesk on DALnet.
Re: Update topic [Re: Twitch] #237041 12/04/12 07:30 AM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
still the same problem frown

Re: Update topic [Re: spermis] #237042 12/04/12 07:40 AM
Joined: Mar 2012
Posts: 38
Twitch Offline
Ameglian cow
Offline
Ameglian cow
Joined: Mar 2012
Posts: 38
that's very odd, adding the -f switch worked just fine for me, and i used your site page to do it as well..

This is what I have (I omitted the on join part):

Code:
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 trick-jumps.lv
    ;- Set the page you want to GET, using the
    ;- preceding forward slash '/' as shown below.
    hadd -m %s get /mirc/news.php
    hadd -m %s read $false
    sockopen %s $hget(%s,host) 80
  }
}
on *:sockopen:topicup.*: {
  if ($sockerr) { echo $color(info2) -at * Socket Open ERROR: $sock(%s).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))
}
on *:sockread:topicup.*: {
  var %t, %s = $sockname, %c = $gettok(%s,2,46)
  sockread -f %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 }
  }
}


ran the command manually:

Code:
/updatetopic #channel


and it worked just fine:

Code:
[03:33 00] * Tw|tch sets mode: +o Smeagol
[03:33 33] * Smeagol changes topic to 'News: I am the news'


Lost in your digital reality.
#mIRC / #Helpdesk on DALnet.
Re: Update topic [Re: Twitch] #237043 12/04/12 08:12 AM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
That is very odd, because I copied what you pasted, and used /updatetopic #mychannel , but still nothing happened. Tried it on mIRC versions 6.21 and 7.22 ..

Re: Update topic [Re: spermis] #237045 12/04/12 08:59 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Just so we have some information about your mIRC install, could you tell us what this returns when typed from the command line?
Code:
//echo -a $version $os $md5($mircexe,2) $file($mircexe).sig $dll(0) $script(0)

Also make sure this is the only loaded version of this script.

Re: Update topic [Re: 5618] #237046 12/04/12 09:01 AM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
7.22 XP 912dfaee60f144853a33231688312686 ok 0 1

Re: Update topic [Re: Twitch] #237047 12/04/12 09:13 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Twitch: shouldn't the second-to-last line read
Code:
if ((!$hget(%s,read)) && (%t != $null)) {
?
(because $hget(%s,read) is/needs to be $false)

Re: Update topic [Re: 5618] #237048 12/04/12 09:44 AM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Originally Posted By: 5618
Twitch: shouldn't the second-to-last line read
Code:
if ((!$hget(%s,read)) && (%t != $null)) {
?
(because $hget(%s,read) is/needs to be $false)


I tried this, now it at least does something, but not the correct thing. When i tried /updatetopic #blurrr it did this:
Code:
[12:42:39] * name changes topic to 'HTTP/1.1 200 OK'
[12:42:39] * name changes topic to 'Date: Thu, 12 Apr 2012 09:42:13 GMT'
[12:42:39] * name changes topic to 'Server: Apache/2.2.22 (Debian)'
[12:42:39] * name changes topic to 'X-Powered-By: PHP/5.4.0-3'
[12:42:39] * name changes topic to 'Vary: Accept-Encoding'
[12:42:41] * name changes topic to 'Content-Length: 18'
[12:42:43] * name changes topic to 'Connection: close'
[12:42:47] * name changes topic to 'Content-Type: text/html; charset=utf-8'

Re: Update topic [Re: 5618] #237050 12/04/12 02:01 PM
Joined: Mar 2012
Posts: 38
Twitch Offline
Ameglian cow
Offline
Ameglian cow
Joined: Mar 2012
Posts: 38
Originally Posted By: 5618
Twitch: shouldn't the second-to-last line read
Code:
if ((!$hget(%s,read)) && (%t != $null)) {
?
(because $hget(%s,read) is/needs to be $false)


I set this to $false at the start of the process, as seen in 'alias updatetopic':
Code:
hadd -m %s read $false

The first blank line the code sees in the sockread tells me we have gotten past the header data reply. so i set it to $true:
Code:
if (%t == $null) { hadd -m %s read $true }

Then I make sure this is set to $true (meaning we have gotten past the header data) and that the buffer line is not $null with this:
Code:
if (($hget(%s,read)) && (%t != $null)) {

I hope that clears up the reason why I'm checking to make sure it is $true here, other wise you would get this:

Originally Posted By: spermis
I tried this, now it at least does something, but not the correct thing. When i tried /updatetopic #blurrr it did this:
Code:
[12:42:39] * name changes topic to 'HTTP/1.1 200 OK'
[12:42:39] * name changes topic to 'Date: Thu, 12 Apr 2012 09:42:13 GMT'
[12:42:39] * name changes topic to 'Server: Apache/2.2.22 (Debian)'
[12:42:39] * name changes topic to 'X-Powered-By: PHP/5.4.0-3'
[12:42:39] * name changes topic to 'Vary: Accept-Encoding'
[12:42:41] * name changes topic to 'Content-Length: 18'
[12:42:43] * name changes topic to 'Connection: close'
[12:42:47] * name changes topic to 'Content-Type: text/html; charset=utf-8'



And just for the record, I have the same reply:

Code:
7.22 XP 912dfaee60f144853a33231688312686 ok 0 1


Lost in your digital reality.
#mIRC / #Helpdesk on DALnet.
Re: Update topic [Re: Twitch] #237059 12/04/12 11:26 PM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
yeah but well, I dont know why but it is not working. maybe there is another way to do the same thing with little more or less code, so it would work for me?

Re: Update topic [Re: spermis] #237061 13/04/12 12:00 AM
Joined: Mar 2012
Posts: 38
Twitch Offline
Ameglian cow
Offline
Ameglian cow
Joined: Mar 2012
Posts: 38
Try adding some echos in the code to see what is happening, like so:
Code:
on *:sockread:topicup.*: {
  var %t, %s = $sockname, %c = $gettok(%s,2,46)
  sockread -f %t
  if ($sockerr) { echo $color(info2) -at * Socket Read ERROR: $sock(%s).wsmsg | return }
  echo -ag Sock Data1: %t
  if (%t == $null) { hadd -m %s read $true }
  if (($hget(%s,read)) && (%t != $null)) {
    echo -ag Sock Data2: %t
    if ($chan(%c).topic != %t) { topic %c %t }
  }
}

The only other thing i could suggest, is to have your news.php page insert a blank line after the topic line.

I'm not really sure what else to say, the code works just fine for me.


Lost in your digital reality.
#mIRC / #Helpdesk on DALnet.
Re: Update topic [Re: Twitch] #237077 13/04/12 10:20 AM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
it doesnt even get to Data2.

Sock Data1: HTTP/1.1 200 OK
Sock Data1: Date: Fri, 13 Apr 2012 10:19:26 GMT
Sock Data1: Server: Apache/2.2.22 (Debian)
Sock Data1: X-Powered-By: PHP/5.4.0-3
Sock Data1: Vary: Accept-Encoding
Sock Data1: Content-Length: 18
Sock Data1: Connection: close
Sock Data1: Content-Type: text/html; charset=utf-8
Sock Data1:

Re: Update topic [Re: spermis] #237083 13/04/12 01:24 PM
Joined: Mar 2012
Posts: 38
Twitch Offline
Ameglian cow
Offline
Ameglian cow
Joined: Mar 2012
Posts: 38
this is indeed very strange..

try this, take the news.php file, and add a blank line after the topic text, just hit <enter> at the end of the topic text line..

if you have time today, find me on IRC, maybe we can work on this problem a little faster.. my location is in my signature..


Lost in your digital reality.
#mIRC / #Helpdesk on DALnet.
Re: Update topic [Re: Twitch] #237086 13/04/12 02:34 PM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Omg. Thanks smile Actually it worked by adding not 1, but two blank lines smile not it is working perfectly smile appreciate your help smile

Re: Update topic [Re: spermis] #237087 13/04/12 02:40 PM
Joined: Mar 2012
Posts: 38
Twitch Offline
Ameglian cow
Offline
Ameglian cow
Joined: Mar 2012
Posts: 38
good deal, i am certainly glad its working now, very strange the -f switch didn't fix the issue..
but that alright, as long as its working now. =)


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