mIRC Homepage
Posted By: revolutecbx [Twitch] World Record Command - 08/07/15 11:47 PM
Hi, I have literally no idea how to do this, so if anybody could help, I would appreciate it.

I am wanting a world record command for my twitch bot, I know it's possible, I've seen other bots with this command.
The way this command would be used would be !wr (game) (category)

I believe the bots that have this command connect to speedrun.com to find the world records.

If you do this for me, I will love you, and if you don't, I understand, it's probably not a simple command.

Thanks.
Posted By: Sakana Re: [Twitch] World Record Command - 09/07/15 12:39 AM
It seems they have an API so it's not that hard, e.g:

http://www.speedrun.com/api_records.php?game=Grand%20Theft%20Auto:%20Vice%20City

You can paste that text into a JSON viewer to understand the structure (http://jsonviewer.stack.hu/)

You'll need to google a script called JSON for mIRC. If you search for JSON on this forum there should be many examples on how to use it.
Posted By: revolutecbx Re: [Twitch] World Record Command - 09/07/15 12:57 AM
Ok, thanks!

I'm not too sure how to turn this into a command, can you help me just a little more? ._.
Posted By: Sakana Re: [Twitch] World Record Command - 09/07/15 02:58 AM
ok, this is untested (there's probably something wrong), but after loading the mIRC JSON script you could do something like this


Code:
on *:text:!wr *:#:{
  jsonopen -du game http://www.speedrun.com/api_records.php?game= $+ $replace($2-,$chr(32), $chr(37) $+ 20)
  if ($json(game,$2-,Any $+ $chr(37),time) == $null) { 
  msg # No data found | return }
  else { 
    msg # $json(game,$2-,Any $+ $chr(37),player) $json(game,$2-,Any $+ $chr(37),time) $json(game,$2-,Any $+ $chr(37),video)   
  }
}
Posted By: revolutecbx Re: [Twitch] World Record Command - 09/07/15 08:11 PM
Yeah, I think something's wrong with that, or I'm not using it correctly, thanks for the help, by the way smile .

Messing around with it right now, I'll let you know if I get it working.

It works, but there's a bit of a problem: It displays the time in seconds, I was wondering if there was a way to make it display the time like hours:minutes:seconds, that would be nice.

Also, this one isn't as much of a problem, and it doesn't need to be fixed, but, if I type !wr mm, for example, it uses the page for Majora's Mask, which doesn't work because... I'm not too sure how to explain it, so I'm going to post an image of what I mean. http://i.imgur.com/Mz7zHKz.png
Posted By: Sakana Re: [Twitch] World Record Command - 09/07/15 11:10 PM
$duration() should convert to hours/minutes


For the other thing you need the first key in the array. AFAIK this JSON script doesn't have that functionality. Instead you would have to make a http request using sockets and then filter the name of the game from the response
Posted By: revolutecbx Re: [Twitch] World Record Command - 09/07/15 11:21 PM
Thanks so much for your help! But I have one last question: Where do I put $duration()?

Nevermind, got it!

Thank you SOOOO much! <3
Posted By: Sakana Re: [Twitch] World Record Command - 10/07/15 12:30 AM
use it on

$json(game,$2-,Any $+ $chr(37) $+ ,time)

but save that to a temp variable first

var %time = $json(game,$2-,Any $+ $chr(37) $+ ,time)
var %time = $duration(%time)
© mIRC Discussion Forums