Metal Gear Solid (1-4) Memorable Quotes

By Kirby on May 07, 2009

Just a small socket bot script I whipped up, mainly focusing on more regex and some hash tables.
This script just gets a random memorable quote from one of the four pages on IMDb.

[size=14]Syntax: .mgs <1 ~ 4>[/size]

* The number represents the game number in the whole series.

Here's a picture for those with good eye sight:
Image

Here's a picture for those who are blind:
Image

Enjoy! :D

#MGS On
on $*:text:/^[.!@]mgs*/Si:#: {
  if ($2 !isnum 1-4) .notice $nick Syntax: $1 <1 ~ 4>
  elseif ($2 isnum 1-4) && (!$sock(mgs)) {
    sockopen mgs www.imdb.com 80
    sockmark mgs # $2 $iif($2 == 1,$r(1,96) tt0180825,$iif($2 == 2,$r(1,140) tt0249008,$iif($2 == 3,$r(1,79) tt0365498,$iif($2 == 4,$r(1,36) tt0462423)))))
  }
}
#MGS End
menu * {
  $iif($group(#MGS) == On,$style(1)) Metal Gear Solid Memorable Quotes
  .$iif($group(#MGS) == On,$style(2)) On: .enable #MGS
  .$iif($group(#MGS) == Off,$style(2)) Off: .disable #MGS
}
on *:sockopen:mgs: {
  sockwrite -n $sockname GET $+(/title/,$gettok($sock(mgs).mark,4,32),/quotes) HTTP/1.0
  sockwrite -n $sockname Host: www.imdb.com
  sockwrite -n $sockname $crlf
}
on *:sockread:mgs: {
  sockread %mgs
  if ($regex(%mgs,<a name="qt[\d]+"></a>)) {
    hinc -m MGS 1
    if ($hget(MGS,1) == $gettok($sock(mgs).mark,3,32)) {
      while (!$regex(%mgs,<hr width="30%">)) {
        sockread %mgs
        if ($regex(%mgs,<b><a href="/name/.*/">(.*)</a></b>:|<b>(.*)</b>:)) {
          hinc -m MGS 2 | hadd -m MGS_Quotes $hget(MGS,2) $+(<,$gettok(~.&.@.%.+.,$r(1,5),46),$regml(1),>)
          sockread %mgs
          hinc -m MGS 2 | hadd -m MGS_Quotes $hget(MGS,2) $regsubex(%mgs,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null)
        }
      }
    }
  }
  elseif ($regex(%mgs,<title>.*:(.*) \([\d]+\)|<title>(.*) \([\d]+\))) hadd -m MGS Name $regml(1)
}
on *:sockclose:mgs: {
  tokenize 32 $sock(mgs).mark
  var %x 1, %y $hget(MGS_Quotes,0).item | $iif(%y > 2,msg $1 $+([Metal Gear Solid ,$2, - $qt($hget(MGS,Name)) Quote]:))
  while (%x <= %y) { msg $1 $iif(%y <= 2,$+([,$qt($hget(MGS,Name)) Quote]:)) $hget(MGS_Quotes,%x) $hget(MGS_Quotes,$calc(%x + 1)) | inc %x 2 }
  hfree -w MGS* | unset %mgs
}

Comments

Sign in to comment.
Jonesy44   -  May 08, 2009

ahh i see! very nice :)

 Respond  
Jethro   -  May 08, 2009

\n = Matches a new line

\r = Carriage return

Below is an example:
Text: an anaconda ate Anna Jones
Regex: \w+\r\n
Match: ate

Depending on your operating system you might have to combine the \r and \n character escapes to create the correct new line sequence for your platform. For Microsoft Windows systems you should generally use \r\n which is a carriage return then line feed (CRLF). To simply match the end of a line or string use the dollar sign ($).

Souce: from from what I read about Regex.

 Respond  
bone282   -  May 07, 2009

is there no \r \n in mirc regex?

 Respond  
Kirby   -  May 07, 2009

jonesy44 said:> Why the second sockread %mgs?

I need the second sockread %mgs because that is used to get the actual quote itself.

Let's take

<b><a href="/name/nm0371684/">Solid Snake</a></b>:
This reminds me of when we first met. 
<br>

for instance.

        if ($regex(%mgs,<b><a href="/name/.*/">(.*)</a></b>:|<b>(.*)</b>:)) {

gets the person who said the quote from the Solid Snake: part, and then after that, I need to get the actual quote itself. By using sockread again, I can get the next line, which contains the quote.

Hope this clarifies your question.

 Respond  
Jonesy44   -  May 07, 2009

Why the second sockread %mgs?

 Respond  
Kirby   -  May 07, 2009

Haha, same. :D

 Respond  
Jethro   -  May 07, 2009

Gee, I love playing metal gear solid 4! I can't wait for the series 5 to come out in the future. It's the best stealth game ever!

 Respond  
Kirby   -  May 07, 2009

I tried to make the quotes look IRC-like, but it seems it doesn't work that way. :D

[size=28]LAUGH ALL YOU WANT NEMESIS!!! ;][/size]

 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.