Script request for welcome packages

Liguinetta

New member
I run a clan account that provides welcome packages to new members. We are a small clan but nonetheless it is a very repetitive and time consuming task and I think it is one that could be made easier with a script.

We currently have an inventory which we keep in the DC because its easy to see what we have in stock if it is there. We send out 7 different basic packages which are determined by class, level and number of ascensions.
3 are used for real newbies to the game who are <= lvl 5. The food/booze they contain is based on the primary stat.
3 are used for lvl 6 - 15 accounts who are on their first run. The contents are also based on the primary stat.
1 package is used for > lvl 15 or multiply ascended types and is the same for all 3 classes.

I'd quite like to keep some basic level of stock as sometimes I need to do these packages when I don't have access to mafia and having to buy stuff in just makes it all take a bit longer.

So...what I need (if its at all possible) are 2 scripts:
One which will make 5 SHC each day and keep the stock in the DC topped up and one that will pull a set list of items together and attach them to a kolmafia message which can be sent to a named individual. Examining the account details so it can determine which package it needs would be a bonus!

I think the first script should be quite easy (even if it is beyond me!) but I'm not sure if it is actually possible to write a script that will do the second part.
If it is then are there any takers?

Thanks
Lig
 

fronobulax

Developer
Staff member
I'm not volunteering to do this yet, just because Real Life is taking some serious bites out of the time I have to do Interesting Things. Nevertheless...

I am especially dense at the moment but what is SHC?

To paraphrase part 1 - you have a list of items and amounts. For each item in the list you compare the quantity listed to the quantity in the display case. If the display case is lacking then obtain the appropriate number of items and move them to the display case. Extra credit for error checking to notice that item acquisition failed. This should be pretty easy since the CLI function acquire and/or the ash function retrieve_items() will do all of the heavy lifting and (more importantly) won't try and pull from the DC.

To paraphrase part 2, is looks as if zlib has support to send a kmail with a list of items to a user so writing a script to do just that should be fairly easy as well. The harder part would just be defining what the list of items is, pulling them from the DC and doing the appropriate error checking. Testing could also be interesting since it could look like multi-abuse.

Examining profiles to determine which set of items to send seems like it would be the hardest because ash is somewhat lacking in information it provides about other players and people have, so far, been somewhat protective of their clan management scripts which presumably obtain some player information.

Bottom line is that a restocking script is feasible and relatively easy. A "send a predefined package" script is also feasible although I would consider it slightly harder. Query a player and determine which package to send is probably difficult enough that a Mr. A or two would need to be on the table. (If that sounds outrageous, consider the post here). I'll tackle the first two, for my own intellectual curiosity if no one else has done so before I find the spare time. "Intellectual curiosity" means "for free" as long as the project continues to teach and amuse me ;)
 

slyz

Developer
I am especially dense at the moment but what is SHC?

SuperHuman Cocktails

Examining profiles to determine which set of items to send seems like it would be the hardest because ash is somewhat lacking in information it provides about other players and people have, so far, been somewhat protective of their clan management scripts which presumably obtain some player information.

This shouldn't be too hard either. It's just a matter of parsing /showplayer.php?who= + playerID. Maybe the complicated part would be getting the playerID in the first place, but asking the script input to be the player ID instead of the player name doesn't seem too much to ask.

Query a player and determine which package to send is probably difficult enough that a Mr. A or two would need to be on the table.

I find the request interesting enough to write it just for the sake of writing it, but that's just me (with maybe too much free time on my hands right now). And it was asked politely. And of course, "thank you" gifts are always welcome =)
 

mredge73

Member
What I am most curious about is what your item lists are?
I have already written most of the structure for this project in one of my clan management scripts. Mine works by allowing one package a day to be sent to any clan member upon request (still experimental). They request what they want through chat and receive it through Kmail.
This is actually slightly more difficult than your request but the customization that you are asking for would definitely qualify for a Mr. A purchase.

For a start on the second part you guys can check out my function BuildRoster() in MrEdge73's Support Script -- ClanAdministrator(LITE).ash script or here for parsing the clan roster into a map so you can analyze player information quickly and easily. After that you just have to decide what criteria you will use to send packages out to your clanies.
 
Last edited:

fronobulax

Developer
Staff member
Thank you. My main doesn't ascend so doesn't have the skill (but does have a TPS) and my ascending multi has been immersed in a series of oxycore runs so I had just forgotten.

I had time at lunch and threw together a stocking script. I should get a chance to debug it and post later this evening. As a heads up there will be a series of lines like
Code:
stock[to_item("stuffed spooky mushroom")] = 1;
and you (the eventual user) will have to edit the script so that there is one line for each item you wish to stock that contains the correct name and the desired number of items to stock.
 

slyz

Developer
I got started on this, and it's a very good exercise to play with regular expressions. I ended up concentrating on the remote chance that the player has a custom title that would make the level parsing fail. I'm trying to load /showclan.php, but I can't get pages other than the first one.

Here is a bit of test code:
Code:
string clanList0 = visit_url("/showclan.php?whichclan=67356");

int page = 1;
string clanurl = "/showclan.php?whichclan=67356&page=" + page;
string clanList1 = visit_url( clanurl );

string[int] temp;
temp[0] = clanList0;
temp[1] = clanList1;
map_to_file(temp, "clanLists.txt");
This will return page 0 twice. url_encode() didn't help, neither did adding &pwd at the end of clanurl.

I obviously don't know anything about visit_url(), so i think I'll wait for someone to explain what is happening here =)

I'm dropping this solution because it is true that multiple server hits is not good, I'll simple steal some of MrEdge's code as usual! Or rather, I'll just hope that no new player receiving welcome packages has a custom title.
 

fronobulax

Developer
Staff member
Attached is an attempt at Part 1. Edit the script so that the entries in "stock" are for the items you want and the amount you want. Then run. For various reasons my test cases only obtained items from the Mall, but that worked. I am counting on retrieve_item() to "do the right thing". If I had any logic errors please consider fixing them and posting the results or letting me know what went wrong.
 

Attachments

  • StockDC.ash
    1.4 KB · Views: 49

StDoodle

Minion
I got started on this, and it's a very good exercise to play with regular expressions. I ended up concentrating on the remote chance that the player has a custom title that would make the level parsing fail. I'm trying to load /showclan.php, but I can't get pages other than the first one.
...
This will return page 0 twice. url_encode() didn't help, neither did adding &pwd at the end of clanurl.

I obviously don't know anything about visit_url(), so i think I'll wait for someone to explain what is happening here =)

I'm dropping this solution because it is true that multiple server hits is not good, I'll simple steal some of MrEdge's code as usual! Or rather, I'll just hope that no new player receiving welcome packages has a custom title.

It's looking to me like visit_url() doesn't allow you to access clan hall info at all (much as happens with certain parts of the mall). It may be necessary to re-write with the assumption (or a check for) the clan being looked at being the same as the clan the character running the script is in.
 

slyz

Developer
visit_url("/showclan.php?whichclan=67356") works fine, the problem is that visit_url("/showclan.php?whichclan=67356&page=1") returns exactly the same string instead of returning the next page.

A debug log didn't show me why this is happening.
 

jasonharper

Developer
You may need to give visit_url() a second parameter with a value of false, to perform a GET request instead of a POST. Notice that the next/previous controls on that page are simple links (which always result in a GET), not form submit buttons (which can do either GET or POST).
 

slyz

Developer
Thanks for the clarification. I saw in the debug log that it was a GET, but I didn't figure out what the boolean in buffer visit_url( string, boolean ) was for. I'll update the wiki when I have some time, although I don't even know the difference between POST and GET =)

@Liguinetta : here is a script that will take care of almost everything you asked for. It is kind of a pain to configure, since you have to enter all the packages and DC stocks manually (I started a couple so you can see the format). It's possible to derive the stock to keep in the DC from the list of packages though, for example by making sure you have enough stock to be able to send n of each packages at any time.

Instructions are in the file, but the gist of it is :
- use call WelcomePackage.ash to do DC stock maintenance
- use call WelcomePackage.ash <playername> to send a package, where <playername> has to be the name of a player in your current clan.

If you have any questions/requests (a confirmation box for example), feel free to post them.

One which will make 5 SHC each day
There are several scripts that will make SHCs for you at login/logout, choosing what to craft depending on current mall prices. See this one for example.
 

Attachments

  • WelcomePackage.ash
    9.2 KB · Views: 57
Last edited:

Liguinetta

New member
Wow - thank you :)
I'm just adding the stock and packages to the file but have a really silly question. How do I enter Newbiesport^TM tent?

Once I've tried it I'll get back with any more questions I have - and any other requests if I may be so bold!

Thanks again

Lig
 
Last edited:

slyz

Developer
Sure, no problem.
For the tent, instead of doing WelcomePackages[1].itemList[$item[Newbiesport^TM]] = 1;, try WelcomePackages[1].itemList[69.to_item()] = 1;. Mafia will understand =)

The script should run fine (I'm in HC and couldn't test the DC/item getting part) , but I guess you should turn on mall purchase in Mafia for retrieve_item() to work in every case.
 

Liguinetta

New member
It took some time and then RL intervened so apologies for the wait for feedback.

- I can't tell if the inventory update is working because using call WelcomePackage.ash without a parameter brings up a box asking for a value of a string. So I've left that for the moment.

- I then tried out the second part with existing clannies of all lvls and number of ascensions/classes (about a dozen different ones) sending each one the same token item in a package.

About half the time it just stopped with the message:
Sending welcome package to bigcalm
Name: bigcalm Level: 13 Runs: 1 Mainstat: Mysticality
Something happened, no package was found for bigcalm.

I think the trouble is in the part which parses the data as in Runs: x the number in all the failed ones and some of the successful ones is much lower than the true number of ascensions. (Bigcalm in the example above has done 115 ascensions!) However I can't see a pattern to the ones it reads properly and the ones it doesn't.

If you want me to run a successful one and an unsuccessful one with the debug log running I can do that if it helps.

Lig
 

slyz

Developer
I can't tell if the inventory update is working because using call WelcomePackage.ash without a parameter brings up a box asking for a value of a string. So I've left that for the moment.

I hadn't thought of that! All you needed to do is press enter without entering everything, but I attached here a version where you must use call WelcomPackage.ash update. The only (small) downside is that a user named 'update' will never get a package (if you ever have one, you can change the "update" on line 271 to ">update" and use that as input).

Be careful not to overwrite the version where you configured the DC stock & packages! The only change is in the main() at the end, so you can just copy that in the old file.

- I then tried out the second part with existing clannies of all lvls and number of ascensions/classes (about a dozen different ones) sending each one the same token item in a package.

About half the time it just stopped with the message:
Sending welcome package to bigcalm
Name: bigcalm Level: 13 Runs: 1 Mainstat: Mysticality
Something happened, no package was found for bigcalm.

I think the trouble is in the part which parses the data as in Runs: x the number in all the failed ones and some of the successful ones is much lower than the true number of ascensions. (Bigcalm in the example above has done 115 ascensions!) However I can't see a pattern to the ones it reads properly and the ones it doesn't.

No amount of testing in my own clan unveiled this. Try it out with the slightly different regex (although I don't think it will change anything). I don't know much about the clan roster, but it's possible that the info it shows in configurable, and my clan doesn't have the same number of columns as yours. Mine has:
Name Class Mus Mys Mox Total Asc (HC) PvP Rank Karma

If we have the same number of columns, then the best way for me to debug this would be to have a whitelist in Not Dead Yet until this works.
 
Last edited:

Winterbay

Active member
That's the same as I have in my clan and I can't find a setting to make them increase or decrease them anywhere. Just as a sort of data point here :)
 

Liguinetta

New member
I attached here a version ....

Err - I can't see a new version....

No amount of testing in my own clan unveiled this. Try it out with the slightly different regex (although I don't think it will change anything). I don't know much about the clan roster, but it's possible that the info it shows in configurable, and my clan doesn't have the same number of columns as yours. Mine has:
Name Class Mus Mys Mox Total Asc (HC) PvP Rank Karma

If we have the same number of columns, then the best way for me to debug this would be to have a whitelist in Not Dead Yet until this works.

Ours looks the same. I've Whitelisted you as a Visitor - if you need target accounts then try Liguinetta or Torellina (both mine) or let me know when you will be around so I can be in chat to help find trusted 'guines-pigs'.

And thanks for the time you are putting into this. I'm sure we can find a suitable 'thank-you' gift at the end :)

Lig
 

slyz

Developer
I just like when things that SHOULD be working actually work. I'm guessing that's the n°1 motivation behind most programmers' carrier choice (although I'm not one myself).

Apparently I messed up the uploading of the file, I'll just wait until I find out what's the problem to upload a fixed one then. For the DC stocking, you can just hit 'OK' on the box that pops up and the script should (there it is again) work.

Thanks for the WL, I'll hop over to see if I can get this to work.

EDIT: turns out 'Asc' in the clan roster is not the total number of ascensions, just the non HC ones. Here's the fix.

EDIT2 : to break lines in messages, the message string should look like this:
Code:
string message = "this\nis\na\nbreaked-up\nmessage\n\nwith a double linebreak";
 

Attachments

  • WelcomePackage.ash
    9.3 KB · Views: 40
Last edited:

Liguinetta

New member
Thanks for the visit - it was most helpful :)

I've now got the WelcomePackage script working as I need to for the DC restocking but I still have trouble with the package sending.

I think I can see where the problem is.
The user inputs for max/min runs should both be 0 for a package for a non-ascended account.
But in package findPackage a target with 0 runs would fail the condition as (0<0 & 0>0) would be false.

Similarly I also think the level part needs to be adjusted as someone who is level 5 (for example) should get a lower level package. The way this is written atm they would fail the condition here as 5<5 would be false.

My hack would be <= or >= as required - but then I'm a mathematician and not a script writer!!

I would also like to know how to add meat to the package for unascended newbies <= lvl15. I was going to use DMS but my clan leader would prefer meat as he thinks n00bs might not realise they could autosell DMS.

Thanks

Lig/Tor
 
Last edited:

slyz

Developer
Here is a new version, with a few changes:

  • You are going to need Zarquon's zlib. Simply put it in your kolmafia/scripts folder.
  • You can now input a comma separated list of player names, instead of a single name. Don't worry about putting spaces after or before the names.
  • I switched to keeping the data in text files. You will have to do all your configuration over again, but it's going to be much better in the long run. The script will look for WelcomeDCstock.txt or WelcomePackages.txt in the kolmafia/data folder. Check the examples I attached, or the instructions in the script.
  • I fixed the > / >= issue, sorry about that.
  • I added an attribute to each package so you can send meat along with it.

This ended up being a bigger project than I thought, and I got to play with regex, visit_url(), zlib...

I couldn't test the actual item getting and package sending parts, because I'm in HC for now, but I hope everything is going to run fine.
 

Attachments

  • WelcomePackage.ash
    10 KB · Views: 51
  • WelcomeDCstock.txt
    66 bytes · Views: 58
  • WelcomePackages.txt
    611 bytes · Views: 50
Top