Feature - Implemented ash my_clan()

StDoodle

Minion
More and more, we're getting cool new clan items in KoL. However, since a player can change clans at any time, keeping track of what's available in a script can be a bit messy; especially since quite a few clans out there contain characters that make saving your clan name a bit more difficult.

If, and only if, mafia is currently able to track when a player changes clans, it would be awesome if an ash function could be added to get the name of your current clan. If mafia currently has problems detecting all clan-hops (which would be understandable), please just let me know this is the case & I'll fuggedaboudit.
 

Bale

Minion
My bafh and clanhop script have a short function to get this info from the profile page, but it would be nice to get the info without needing a server hit each time.
 

slyz

Developer
My guess would be that Mafia would use a server hit to get that info each time you clanhop, anyway. Maybe bafh.ash and clanhop.ash can share some sort of data file with the name of the clans and its goodies?

Edit: I meant clans, so you would have a data file with the goodies of all the clans you visited. Of course, they would need to be updated from time to time, with a user requested server hit or a once a X days refresh.
 
Last edited:

StDoodle

Minion
Yeah, I already have a way of getting the info; as mentioned (by others as well), the problem is doing so without a server hit each time. Unfortunately, it isn't something one can really "save," as it would bork things if the person runs a script that uses clan info, clan-hops, then runs said script again. If KoLmafia would have to do the same server-hitting-each-time action, then there's no real gain from having a built-in function. But if it wouldn't have to, it would be nice to get such a function.
 

lostcalpolydude

Developer
Staff member
Every time you switch clans, there's something on the page that gives the name of the clan that mafia could theoretically parse. It might not be worth the time to implement, though.
 

Bale

Minion
So, if this was implemented, should it return an int or string? The clan ID is an int that is necessary for any operations involving clans, but the string of the clan's name is more useful for human readable output. If implemented, it seems to me that it would require two functions.
 

lostcalpolydude

Developer
Staff member
In the main pane: "You have now changed your allegiance." In chat: "Now pledging your allegiance to [name of clan]." Mafia can get the name, but KoL doesn't give mafia any way of getting the clan ID from that exchange.
 

StDoodle

Minion
See, this could still save server hits. Right now, I have to hit the server every time I check the current clan allegiance. Since mafia at least knows when a clan-hop has happened, a my_clan() function could save a server hit if no changes have happened since the last time it was checked.

Edit to add:

Perhaps, instead of a function to get the clan name / ID, we could just have user preferences currentClanName & currentClanID that get blanked when KoLmafia sees a change in clan allegiance. That way, no extra server hits are required; if I need to get the clan name or ID and the preference are blanked, then and only then do I hit the server to do so. But if the information isn't required, the server hit never happens.
 
Last edited:

Theraze

Active member
Return Clan Name to scripts?

On the slime tube script thread, it was mentioned that there isn't currently a way to check what clan you're a part of without doing another server hit. Looked and while there's commands to display it, none of them were easily accessible to the user. Put getClanName() from session/ClanManager in as get_clan_name() to textui/RuntimeLibrary so that as long as KoLmafia knows your clan name, you can display it without needing another server hit. It's as accurate as KoLmafia is...

Edit: New patch attached to post 8, which includes a clan id lookup.
 
Last edited:

Theraze

Active member
Well, I logged in a character and told it to return clan name without having done anything else and it did give me Empyrion. Not sure how well mafia tracks the multi-clan jumping... I know you can force the cache to clear, but really, it should detect when clan change happens and update the variable internally then... If it doesn't, that should be a bug report.
 

Grotfang

Developer
Well, I applied this and flicked between a few clans and it did quite happily pick up on changing. What mafia does not do is spot which clan the whitelist shift was to, so this function led to a server hit each time I called it after changing.

Basically, it was 100% accurate for me, but I'm not convinced it saved any server hits. I would be happier in adding this if we had a more reliable way to spot changing clans instead of acknowledging the change, but not logging the clan.
 

Theraze

Active member
Well, if you use the /clan channel, this uses the same lookup, so it saves a server hit there... If you look at clan stash, same lookup, so saves a server hit there... I suppose the only real way to check would be login, change clans, pull (or block) your internet, and see if it returns the proper clan name?

Anyways, I can't think of any times this should be less efficient than the manual script doing a lookup and return, and if you do any clan actions, such as checking their slime tube or anything similar, the clan id should be updated with the right information already, thereby saving the server hit...
 

Grotfang

Developer
Well, I'm willing to support it as an idea. However, I don't fully understand the ins and outs of how the clan manager is set up, so I'm going to bow out of the discussion at this point. If it does get implemented, may I suggest an ID return is added too (since that can be added direct to urls if needed?). Same code, but ClanManager.getClanId() instead of Name().
 

Theraze

Active member
Sure... I'll tear that out and make that get_clan_id(). Uses the same check, so even if you have a server hit for one, you won't have for the other, and you're saving a possible future hit if you do clan chatting or stash or any other clan features. Possible not because it might not save the second hit, but because if KoLmafia already knows about the clanid, it doesn't do the first hit when you call the function the first time...
 

Attachments

  • GetClanName.patch
    1.1 KB · Views: 34
Last edited:

lostcalpolydude

Developer
Staff member
Don't forget that there are two ways to change clans just within the game interface (Clan Recruiter and chat commands), for any testing. If mafia tracks well enough to know when you've changed clans and only hits the server in that case, then it seems useful.
 

slyz

Developer
Another way to save server hits would be to recognize and update the clan name when the player visits any page that displays it (charsheet.php, clan_*.php...).

What happens when you are booted from a clan?
 
Top