mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2015
Posts: 19
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Mar 2015
Posts: 19
Hello, I was wondering how I can get mIRC to read text from a remote php file to post the short text in to chat.

Ex.
User: !bf4stats
Output:{streamer}'s Battlefield 4(pc) Stats | Rank: 140 | Kills: 66393 | K/D: 2 | W/L: 1.38 | Score: 60646533 | Time Played: 53.27 days | Accuracy: 14.17%

The output is via battlefield API. I just want to read it from the file and write it in to chat kinda like !uptime

Last edited by Blood_Wolf89; 24/03/15 05:03 AM.
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
could you link to the URL that has that information?

--

Edit: using the JSON parser from my signature:
Code:
on *:TEXT:*:#:{
  if ($strip($1) === !bf4stats) {
    var %user = $iif($2, $strip($2), $nick)
    var %urlSafeUser = $regsubex(%user, /[^a-z\d_-]/gi, % $+ $base($asc(\t), 10, 16, 2))
    var %url = http://api.bf4stats.com/api/playerInfo?plat=pc&name= $+ %urlSafeuser

    JSONOpen -ud bf4stat %a

    var %name = $JSON(bf4stat, player, name)
    var %rank = $JSON(bf4stat, player, rank, nr)
    var %score = $JSON(bf4stat, player, score)

    var %kills = $JSON(bf4stat, stats, kills)
    var %deaths = $JSON(bf4stat, stats, deaths)
    var %kdRatio = $round($calc(%kills / %deaths), 2)

    var %wins = $JSON(bf4stat, stats, numWins)
    var %losses = $JSON(bf4stat, stats, numLosses)
    var %wlRatio = $round($calc(%wins / %losses), 2)


    var %played = $duration($JSON(bf4stat, stats, timePlayed))

    var %hits = $JSON(bf4stat, stats, shotsHit)
    var %misses = $JSON(bf4stat, stats, shotsFired)
    var %accuracy = $round($calc(%hits / %misses * 100),2) $+ %

    msg # %name $+ 's Battlefield 4(PC) Stats $(|,0) Rank: %rank $(|,0) Kills: %kills $(|,0) K/D: %kdRatio $(|,0) W/L: %wlRatio $(|,0) Score: %score $(|,0) Time Played: %played $(|,0) Accuracy: %accuracy
  }
}


Results with:
Code:
<1ApRiL> !bf4stats
<SReject> 1ApRiL's Battlefield 4(PC) Stats | Rank: 106 | Kills: 10277 | K/D: 1.17 | W/L: 1.28 | Score: 9689475 | Time Played: 1wk 2days 2hrs 37mins 48secs | Accuracy: 10.13%
<timmy> !bf4stats 1ApRiL
<SReject> 1ApRiL's Battlefield 4(PC) Stats | Rank: 106 | Kills: 10277 | K/D: 1.17 | W/L: 1.28 | Score: 9689475 | Time Played: 1wk 2days 2hrs 37mins 48secs | Accuracy: 10.13%


Last edited by FroggieDaFrog; 24/03/15 07:47 AM.

I am SReject
My Stuff
Joined: Mar 2015
Posts: 19
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Mar 2015
Posts: 19
It is on wamp on my pc so I would need to share my IP...

EDIT:
The file was just parsing info from the API but if I can parse it in mIRC, i would much rather do that!

EDIT:
I am trying to make it so people can type in the name to search. but even before that I need to get it to work with parser.

at the moment it dont appear to be working. I pasted in the !bf4stats code from you and after that I pasted in the JSON pars code. what else do I have to do?

Last edited by Blood_Wolf89; 24/03/15 07:18 AM.
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Are you using windows as your Operating system?


I am SReject
My Stuff
Joined: Mar 2015
Posts: 19
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Mar 2015
Posts: 19
Yes I am, Win 8

Joined: Mar 2015
Posts: 19
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Mar 2015
Posts: 19
The JSON Parse I just copy and paste after the !bf4stats?

EDIT:
I just looked in mIRC Aliases and I see this JSON error..

"JSONError return Required parameters missing
url_pattern return m@(?:^| )((?:(?:https?|ircs?)://)?(?:(?:[-\w]+\.)+)[-\w]+(?:\d+)?(?:/(?:[-a-zA-Z;/\d#:?=&,]*))?)@ig"

EDIT:
It is kind of working. The output I get is as follows

Quote:
's Battlefield 4(PC) Stats | Rank: | Kills: | K/D: 0 | W/L: 0 | Score: | Time Played: | Accuracy: 0%

Last edited by Blood_Wolf89; 24/03/15 01:42 PM.
Joined: Mar 2015
Posts: 19
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Mar 2015
Posts: 19
Originally Posted By: Blood_Wolf89
The JSON Parse I just copy and paste after the !bf4stats?

EDIT:
I just looked in mIRC Aliases and I see this JSON error..

"JSONError return Required parameters missing
url_pattern return m@(?:^| )((?:(?:https?|ircs?)://)?(?:(?:[-\w]+\.)+)[-\w]+(?:\d+)?(?:/(?:[-a-zA-Z;/\d#:?=&,]*))?)@ig"

EDIT:
It is kind of working. The output I get is as follows

Quote:
's Battlefield 4(PC) Stats | Rank: | Kills: | K/D: 0 | W/L: 0 | Score: | Time Played: | Accuracy: 0%


I still was unable to get the stats to show up. The most that I get is the template shown above

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
There was a typo in the script, %a was used instead of %url

Code:
JSONOpen -ud bf4stat %url

Joined: Mar 2015
Posts: 19
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Mar 2015
Posts: 19
Thanks Loki, Everything works great! an other question. How can I get data from a class on a page. For example..

Html:
<span class="servername">
 



<span class="common-playing-link" data-track="friend.playing.server.link">



 <a title="-|TBG|- INFANTRY ONLY + LIGHT VEHICLES | NO LAG | TBGCLAN.COM"
 class="common-playing-link "
 href="/bf4/servers/show/PC/29443877-42b9-47ea-a5f3-7f91c7bff615/TBG-INFANTRY-ONLY-LIGHT-VEHICLES-NO-LAG-TBGCLAN-COM/">
 


-|TBG|- INFANTRY...

 </a>
</span></span>

I want to get the server name and the url to post in chat when someone types !bf4server. I want the Name: {url} so they an join me if they wish


Link Copied to Clipboard