Message Extraction

holatuwol

Developer
There's two new functions I've added to ASH to help out people who have been attempting to write kmail parsers (these are getting more popular).  They'll be available in the next release, which is more or less ready.

int extract_meat( string text )
int [item] extract_items( string text )

The first is self-explanatory.  The second takes the text you have provided and parses it for any items that KoLmafia would have found normally.  This means you have access to the built-in pluralization handler as well as the ability to NOT have to lookup description IDs or whatever other loops you had to use to access that information.

For example, the following statement will give you all the items that have been sent to you; of course, it doesn't tell you who sent it, but it should give you a basic idea of what's going on, or where you can go from there:

Code:
string response_text = visit_url( "messages.php?box=Inbox&begin=1" );

int mailed_meat = extract_meat( response_text );
int [item] mailed_items = extract_items( response_text );

foreach received_item in mailed_items
    print( received_item + ": " + mailed_items[received_item] + " received in total" );

print( "You gained " + mailed_meat + " meat." );
 

Nightmist

Member
Yay no more using
Code:
int MeatGain( string Message)
{
 if( contains_text( Message, "<td valign=center>You gain "))
 {
 int MeatGainStart = index_of( Message, "<td valign=center>You gain ")+27;
 int MeatGainEnd = index_of( Message, " Meat.", MeatGainStart);
 int MeatGain = string_to_int( substring( Message, MeatGainStart, MeatGainEnd));
 return( MeatGain);
 }
 return( 0);
}
And the item description number map is no longer needed for kmail parsing eh. =D Good news for me I guess.
Although I'll still need to maintain it for my trade parser (Unless this works in trade messages aswell... although I guess trade messages can just be done using direct string to item matching since they dont use the weird plurals...)... Actually *Goes edit trade parser to just use direct string to item*.
 
Top