Skip to content
TORNLIFE More

mSL: basic profile reader using API

Started by PMV [1577993] on in API Development.

29 replies · 687 views · thread synced · 6 days ago · View on torn.com
About this thread

Posts archived: 30 / 30 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
30
Discussion span
→
Authority score
69 / 100
Historical score
39 / 100
Story score
50 / 100
Engagement score
69 / 100

People posting, likes and official posts are not counted for this thread yet: on threads longer than one page they come from a periodic pass over the archive, which has not covered it.

Mentioned in this thread

Hopslam [795412] ×2 PMV [1577993] ×2 Malfurion [796969] ×1

PMV [1577993]

I've had a few people ask me to make a simple !info command standalone script from UTA. So, I wrapped it up in a simple single script. It stores/retrieves IDs (!addid !delid), provides basic links (like !id, !bust, !mug, !revive, etc), and the !info profile display command.

This should make it easier for those who want to just have the !info command without the extras from UTA, or who want to add the functionality for their bots.

All I ask is that you give credit to me as the author if you use/copy it. ie: putting my name/ID somewhere in your 'about info'.


PASTEBIN LINK - v1.3 (May 28 2016)



version 1.2 (Feb 20 2016)
version 1.1 (Jan 6 2016)



As is, you will have to set it up to use it.

- Change line 4 to include your API key.
- Change line 7 to your channels.
The rest can be left as default, but if you wanted to customize it a lil bit, there are additional options as well.

This is similar to what it should display when set up and working. (and yes, my bot's name owns)
[image: i.imgur.com]
(screenshot is of 1.0, later versions have more functionality)



For developers:



If you're wanting to extract it for your own scripts, a few line numbers are of note (v1.3 - May 28 2016):

Lines 137-148 = the !info command parser. It determines the ID to read and stores it (as well as the output channel) into a variable, then opens the socket. You will have to put whichever functions needed to retrieve the requested ID (whether you read from a database or external source) and set it in place BEFORE you call the sockopen.

Line 171 = HTML strip regex. You need this for non anonymous mugs/hosps since the API includes an HTML link which makes things messy.

Lines 177-260 = profile string builder. It's a bit expanded and probably could be squished quite a bit, but it makes it easier for me to read/edit like this. This basically cleans and formats the data, puts it together in a single string, and returns it to be displayed.

Lines 264-271 = sockopen. Opens the socket at the URL and sends data requesting the relevant information. You will have to modify line 240 to grab the pieces of information that it needs. (%prof.find = ID to get, $prof.apikey = API key)

Lines 273-300 = socket reader. Every time a line of data is sent back from Torn, it calls this. This function pulls the needed data in order and places it into set variables for the string builder. If you wanted, you could condense these vars quite a bit as well; I prefer it expanded for easier reading/editing.

Line 298 calls the "sockclose alias" and closes the socket locally if it reads the end of the API string.

Line 302 = sockclose. Now just calls the "sockclose alias" in case it's called before it's finished reading the end of string (or if it's never read for some reason). This change avoids the ~30 second "lag" between calling !info and for the server to close the socket remotely.

Lines 306-316 = "sockclose alias". This is called after Torn's server is finished sending data. It first checks for errors and displays it if there is any. Otherwise, it calls the string builder, displays it, closes the socket if requested, then cleans up after itself.



If you're wanting to build on it to add your own code while using this script as a base, the following functions will help:

To get an ID from the database: $prof.getid(%name)
- Replace %name with whichever name var to search for
- This alias will simply return the ID stored under %name.
- If not found, it will return $null


To get a name from the database: $prof.getname(%ID)
- Replace %ID with whichever ID var to search for
- This alias will search the preferred stored name table first (set by !setmain), returns that if found.
- Otherwise, it will search the main ID table and return the first result found.
- If not found, it will return $null
PMV [1577993]

Added some additional notes for developers. :) Hopefully this helps people to start their own custom bots without needing to cut away a few thousand lines of code from UTA.
PMV [1577993]
updated to fix the API changes released today. Link on first post.

More specifically, all integers that were 'strings', are actual integers now.
PMV [1577993]

updated to fix all the api changes since last release, including fixing the status display to read both sections. Link is updated on first post.

Also added a few general improvements. Too lazy to list every change, use a text comparison tool to see all the changes.



PMV [1577993]

The forced https change to the site now requires mirc to work over ssl. To remedy this, you need to install openssl, then change (line 143 on the pastebin link):

sockopen profile api.torn.com 80

to:

sockopen -e profile api.torn.com 443

The first time you connect will pop up a certificate, check on always allow and accept it, then you should be up and running.
PMV [1577993]
updated to 1.3 and added notes above.

- rewrote how the socket is closed to avoid the ~30 second "lag"
- added SSL support
- added a few fixes for weird faction names.

This lag is caused by the server no longer closing the connection for 30 seconds or so. The script will now read what it needs and close the connection locally so it can be used again.
PMV [1577993]

up we go.

If anyone wants to start learning how to make an IRC bot of their own, this gives you a basic ID system + !info script that you can build off of. :)
PMV [1577993]

This script is legal as per new scripting rules, it only calls from the API. There are no changes needed.
Hopslam [795412]

^ Is this for getting info on your own profile id only? or others' profile id?

I'd rather not have people being able to run a profile id check on me (to see life and travel/hospital status) without me offering up my api


saeed [1826888]

Anyone. Mine and a few other people's IRC bots do the same.

I actually had a python script (before it was illegal) that did exactly what you don't want. :P



Your status is available to anyone with the API key. There are only a few things not gathered. Most things public here are public there.



http://pastebin.com/raw/RAd57iBR



this is raw output on your ID with no other selections. health and status etc included



edit:
Hopslam [795412] [On] Level: 92, Rank: Elite Tycoon, Life: 6712/6712
11:55 AM Last action: 1 minute ago, Friends: 370, Enemies: 76, Awards: 368, Karma: 2763, Faction: Member of estructive Anomaly
11:55 AM Married to: Malfurion [796969], Status: Okay, Traveling back to Torn, Profile link: https://www.torn.com/profiles.php?XID=795412

This is the output of A bot, one of many. Not this bot in particular, because it's being special and doesn't want to work for me.

Mentions: Hopslam [795412] · Malfurion [796969]

PMV [1577993]

It displays the publicly available information that the api offers in a similar fashion to what saeed showed up above.
Hopslam [795412]

Ok, so it's not a problem that there is a script for this

It's more of a problem of what data is available

Still kind of confused a little.... how does saeed get my profile details like that without having my api? or you saying that Torn's api (wherever that data is...) has a complete listing of public data available for script usage?



Well this certainly explains how some "travel stalkers" can claim to be "so good"

Mug/attack/other victims certainly have a right to be upset with this kind of stuff over the years, but placing blame on scripters is probably not the right place for that.
PMV [1577993]

It's the same information that is available if I went to your profile page right now. Private information (such as your personal stats) are only available to yourself if the api key provided matches the ID requested.

[03/13-13:36:04] !info
[03/13-13:36:07] PMV [1577993] [On] * (Male, Level: 91, Title: Legendary Damage Dealer, Age: 5y 207d (2032), Spouse: Rayne (for 786d), Prop: PI, Fac: Member of JFK, Life: 6,968/6,968 (100%), A:320/F:50/E:11, Seen: 0 mins ago, Status: Okay)
[03/13-13:36:07] Link: http://www.torn.com/profiles.php?XID=1577993

is what this particular script outputs.

Mentions: PMV [1577993]