A bit of help - Or better yet, A crash-course on-the-job some-thing-or-another

Guacanator

New member
Howdy, World!

Now then, I've had a long-time interest in a clanbot for my clan, but for the longest time was absolutely clueless. I've tried several mediums... including Pearl and Python, but none of those quite worked.

So here I am, at mafia.

Now, I have a few goals for my bot.
-Chefbot: cook/cocktailcraft for clanmates
-Buffbot: Self-explanatory

So, I decided to tackle chefbot first.

So, I don't have any experience with Mafia (besides a simple script that bought me cheaply priced items during breakfast) And, if this script is to turn out, I'm going to need YOUR help!

Now, this shouldn't be too involved, should it?

Basically, it should need 4 things:
-Kmail parsing
-Recipe recognization
-crafting
-Return item to Sender

I can get the crafting down, I just think I'll need some help with the first two...

Now, I know Zlib supports Kmail parsing, I just Don't know how to use it.

Also, is there a library out there that has recipe support?

I'm a quick learner, so I don't think this is impossible at all.
 

zarqon

Well-known member
Three of the four parts are easy. Check out my Registry script for kmail parsing (link in sig). Crafting is as easy as a single command. Returning item to sender is as easy as importing ZLib and calling kmail().

That leaves recipe recognization, which would be a pain in the butt to script. I'd recommend requiring people to specify the item(s) they want in the text of the kmail, that takes a huge load off you as far as scripting goes.
 

Grotfang

Developer
Yeah... I have actually attempted to make a form of this before, and gave up because I found it too much of a headache. Sorry :(

With the recipe idea, I was trying to optimize on returns, and that is very, very hard. As zarqon says, your best bet is for them to specify the end result - you confirm they sent the relevant items (also hard, as a good bot will allow multiple steps, so they may expect a couple of crafts - as well as allowing more than one recipe to be asked for, or multiples of the same recipe), then you make it.
 

Guacanator

New member
Hmm... I think that idea will do for now.

I dug up an old script off these forums that's a modified version of the registry script. http://kolmafia.us/attachment.php?attachmentid=1862&d=1250559988

So I ran it, and it gave me these results:

Checking mail...
1 messages queued.
checked mail
Guacanator
Monday%2C+January+11%2C+2010%2C+04%3A42PM
95179040
Test123<center><table class="item" style="float: none" rel="id=583&s=61&q=0&d=1&g=0&t=1&n=1&m=0&u=e"><tr><td><img src="http://images.kingdomofloathing.com/itemimages/bowl.gif" alt="fettucini Inconnu" title="fettucini Inconnu" class=hand onClick='descitem(517296500)'></td><td valign=center class=effect>You acquire an item: <b>fettucini Inconnu</b></td></tr></table></center><center><table class="item" style="float: none" rel="id=787&s=35&q=0&d=1&g=0&t=1&n=3&m=0&u=b"><tr><td><img src="http://images.kingdomofloathing.com/itemimages/bottle.gif" alt="bottle of rum" title="bottle of rum" class=hand onClick='descitem(124295227)'></td><td valign=center class=effect>You acquire <b>3 bottles of rum</b></td></tr></table></center><center><table><tr><td><img src="http://images.kingdomofloathing.com/itemimages/meat.gif" height=30 width=30 alt="Meat"></td><td valign=center>You gain 5,000 Meat.</td></tr></table></center>
5000
3 bottle of rum
1 fettucini Inconnu

Any way, This will give me values for the items, but the text is the HTML of the message. Is there a way to further parse it into the body text?
 

heeheehee

Developer
Staff member
Isn't there an extract_items command or something built into ASH for this very purpose?

Edit: Wait, I think I'm misunderstanding the question. What do you want parsed, exactly?
 
Last edited:

Grotfang

Developer
Any way, This will give me values for the items, but the text is the HTML of the message. Is there a way to further parse it into the body text?

In the example above, the html code printed comes from a string called:

Code:
mail[0].meat

Where the 0 represents the kmail identifier. I would suggest further string handling of that, using:

Code:
string substring( string source, int start, int end )

Remember, you can use:

Code:
int index_of( string source, string search )

int index_of( string source, string search, int start )

int last_index_of( string source, string search )

To get the index (int) of the relevant bits.
 

Guacanator

New member
Isn't there an extract_items command or something built into ASH for this very purpose?

Edit: Wait, I think I'm misunderstanding the question. What do you want parsed, exactly?

I've already got the Items parsed, I want to parse for the body text (In the case of the example, "test123")

I've updated the script abit, but I'm returning the error:

Expected ), found (test3.ash, line 53)

Here's the code:

message[int] mail = parse_mail();
print ("checked mail");
if (count(mail) > 0)
{

print (mail[0].sender);
print (mail[0].date);
print (mail[0].id);
print (mail[0].text);
print (mail[0].meat);
string bodytext = subtstring(mail[0].meat,"",<center>);
print (bodytext);
foreach i in mail[0].things
print (mail[0].things+ " "+i);
}


Now, I'm warning you: I'm not that great at strings. Which is why I'm asking for help. =P
 
Last edited:

zarqon

Well-known member
This will reduce the text field to purely text. Be sure to do this after parsing items/meat.

PHP:
if (contains_text(mail[0].text,"<center><table ")) mail[0].text = substring(mail[0].text,0,index_of(mail[0].text,"<center><table "));
 
Top