MakeBot.ash

suship

New member
So I'm writing a Craftbot script for my clan to use and I've run into a few problems.

I've been trying to find a way to have Mafia automatically run my script every X minutes or whenever a new Kmail is received. I haven't seem any mention of such a feature anywhere either. How could I go about doing so?

I also need to find a way to check if a request is valid instead of having the script crash every time it encounters "boring spagehtti" or "lucky suprise egg". A friend told me to try contains_text(to_string($item[]), "boring spagehtti") but that doesn't seem to be working. Any help would be greatly appreciated!
 

Grotfang

Developer
It would be relatively simple to avoid action on the event of a mis-type by only making the script act on valid item names. Essentially, if you convert their input string to an item, then you can check that validity (eg. item number will not exist for it).

Code:
> ash to_item( "boring spaghetti" );

Returned: boring spaghetti

> ash to_item( "boring spagetti" );

Returned: none

You can see the simplicity of that check, I hope.

If to_item() returns none, then you return the function as null, or something similar (or even exit the script).

As for mafia automagically running this script... I'm afraid I can't help you there :(
 

zarqon

Well-known member
Mafia won't automatically run a script every X minutes, but you can make your script loop and run a routine every X minutes using the wait(int) command, which will wait a certain number of seconds.

Code:
void main()
   while(true) {
      parse_mail();   // your bot's routine
      wait(300);   // wait 5 minutes
   }
}

Downside: if you run the script directly, any CLI commands you issue will be queued, unless it's your login script! (Mafia has some inconsistencies about when it queues commands and when it doesn't.) You can still accomplish stuff in the relay browser while the script is doing its waiting, just be careful not to be in combat when your script goes to parse your kmail.
 

suship

New member
It would be relatively simple to avoid action on the event of a mis-type by only making the script act on valid item names. Essentially, if you convert their input string to an item, then you can check that validity (eg. item number will not exist for it).

Code:
> ash to_item( "boring spaghetti" );

Returned: boring spaghetti

> ash to_item( "boring spagetti" );

Returned: none

You can see the simplicity of that check, I hope.

If to_item() returns none, then you return the function as null, or something similar (or even exit the script).

As for mafia automagically running this script... I'm afraid I can't help you there :(

For some reason I was convinced that when Mafia encountered an erraneous to_item() conversion it aborted the script, apparently I was wrong. Thanks for pointing that out. ^^

I hadn't thought about just looping the script, that's much simpler than any number of other approaches I attempted to use.
 

mredge73

Member
I would also recommend you take a look at my clan admin and function libraries. You don't have to use the scripts but you can reuse the functions that are useful for your purposes.

When looping your bot script you need to make sure you have an exit condition or you will have to restart mafia manually everyday after rollover. I included some time functions in my libraries (by Alhifar) that are helpful in determining when to auto exit mafia.

Good Luck!
 

slyz

Developer
You might also consider executing your script only when your bot receives a private message. The script could then parse new kmails etc. To set the script to be executed when receiving a pm :
Code:
set chatbotScript = MyScript.ash

Maybe you can check other threads to find out more about chatbotScripts.
 

Grotfang

Developer
Only problem with that is it won't respond to a kmail sent with ingrediants. So a user would have to a) send a kmail and b) send a chat PM to get it to act, which could be annoying. Something that acts upon receipt of a kmail seems ideal, but I haven't a clue about that sort of code.
 

mredge73

Member
The only way I know how to do that is to loop the parse_mail every x minutes. Mafia does not always respond to emails quickly and without an inventory refresh it does not always know you have items received from emails. I don't think that there is a "kmailbot" option like there is with a chatbot, buybot, recovery, buffbot, or counter bot. Maybe that could be a request to the devs to add a script that would execute upon recieving kmail.
 
Top