mIRC Home    About    Download    Register    News    Help

Print Thread
#249278 22/11/14 01:47 PM
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Hi, I'm trying to make a socket script around this page
http://www.mtggoldfish.com/player/Player_Name_Here

(For example http://www.mtggoldfish.com/player/smdster)

Eventually, what I'm trying to do is this: someone types "!lookup smdster" and the bot returns with "The last 3 Standard decks played by smdster are RG, RG, RG"

But before going that far I'm just trying to paste all the page's source code info into a window, but this shows up in the mIRC window
Code:
<p>The requested URL <code>/player/smdster</code> was not found on this server. <ins>That’s all we know.</ins>


What am I doing wrong? :<

This is the script

Code:
on *:text:!lookup*:#:{
set %player $2-
set %channel #
lookup

}

alias lookup {
sockclose lookup
sockopen lookup mtggoldfish.com 80

}

on *:sockopen:lookup:{

if ($sockerr) { sockclose $sockname | halt }
sockwrite -n $sockname GET /player/ $+ %player HTTP/1.1
sockwrite -n $sockname Host: www.mtggoldfish.com 
sockwrite -n $sockname $crlf
}

on *:sockread:lookup: {
window -deC @ $+ $sockname -1 -1 700 700
var %read
sockread -f %read
aline -p @ $+ $sockname : $+ %read
}

on *:sockclose:lookup:{ 
unset %channel
unset %player
}






Last edited by Sakana; 22/11/14 01:57 PM.
Sakana #249279 22/11/14 01:53 PM
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
on *:sockopen:lookup{
on *:sockopen:lookup:{


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Sakana #249280 22/11/14 01:54 PM
Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
try fix this
Code:
on *:sockopen:lookup{

to
Code:
on *:sockopen:lookup:{
and retry


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
westor #249281 22/11/14 02:01 PM
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Sorry, I'm a moron. I had already fixed that, but somehow pasted the wrong code anyway

This is the first line I get in the window:

<title>Error 404 (Not Found)!!1</title>

Does this mean you can't use sockets with this site, or is there another problem?

Sakana #249282 22/11/14 02:04 PM
Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
That mean that the site that you are trying to open is incorrect you must check 2 thing if this appear.

1. sockwrite -n $sockname GET /player/ $+ %player HTTP/1.1

2. sockopen lookup mtggoldfish.com 80

one of these 2 has incorrect value.


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
westor #249302 24/11/14 12:12 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Thank you, got it working.

Can someone tell me how to return "Abzan Midrange" from this piece of HTML when I'm searching for *Standard* ?

Code:
<td><a href="/tournament/16294">Standard Daily #7589650</a></td>
<td>3</td>
<td>1</td>
<td><a href="/deck/249722">Abzan Midrange</a></td>


I am stuck at this:

Code:
on *:sockread:price: {
  var %read
  sockread %read
  if (*Standard* iswm %read) {
    tokenize 32 %read
    ????
  }
}

Last edited by Sakana; 24/11/14 12:15 AM.
Sakana #249303 24/11/14 04:01 AM
Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Code:
on *:SOCKREAD:price: {
if ($sockerr) { halt }
else {
var %sockreader
sockread %sockreader
if (*<td><a href="/tournament/16294">Standard Daily #7589650</a></td>* iswm %sockreader-3) {
noop $regex(%sockreader,/(.*?)/Si)
var %type $regml(1)
.msg %chan deck type: %type
sockclose $sockname
}


I'm sure this isn't exactly what you want...but something like this?

Belhifet #249304 24/11/14 04:42 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
That's missing two }'s at the end, right? The code doesn't seem to get a value for %type when I try it. If I need to use $regex and $regml, I'll read up on them because they're not familiar to me - thank you! smile

Last edited by Sakana; 24/11/14 04:43 AM.
Sakana #249305 24/11/14 07:13 AM
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
I made this yesterday, but then you deleted the thread...

Code:
alias lookup_test {
  var %s lookup $+ $calc($sock(lookup*,0) + 1)
  sockclose %s
  sockopen %s www.mtggoldfish.com 80
  sockmark %s 0
}

on *:sockopen:lookup?*:{
  sockwrite -n $sockname GET /player/smdster HTTP/1.1
  sockwrite -n $sockname Host: www.mtggoldfish.com 
  sockwrite -n $sockname
}

on *:sockread:lookup?*:{
  var %read
  sockread %read
  ;echo -s %read
  if ($sockbr) {
    if (*<td><a href="/deck/?*">?*</a></td>* iswm %read) {
      echo -a $gettok($gettok(%read,3,62),1,60)
      if ($calc($sock($sockname).mark + 1) == 3) sockclose $sockname
      else sockmark $sockname $v1
    }
  }
}
Type /lookup_test
The socket name are now dynamic so you can get more than one running at the same time, it use the /sockmark command to create the counter (to 3)


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #249307 24/11/14 08:40 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
That's very close to what I had in mind. I understand things much better now - should be able to figure out the rest. Thanks so much 8)


Link Copied to Clipboard