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