Feature - Implemented ash my_clan()

Arakasi

New member
Did this feature ever get implemented? I'm looking to retrieve the current clan name. I'm ok with doing a server roundtrip but can't find a function that will retrieve it. I'll keep poking around because this post suggests one exists. Thanks!
 

Alhifar

Member
I'm currently using this function in slime.ash
Code:
string get_clan()
{
	string page_text = visit_url( "clan_hall.php" );
	matcher m = create_matcher( "whichclan\=\\d+\">([^<]+)" , visit_url( "showplayer.php?who=" + my_id().to_string() ) );
	if( m.find() )
	{
		return m.group( 1 );
	}
	return "Error! Clan not found!";
}
 

Grotfang

Developer
And if you want the id:

Code:
int clan_id()
{
	matcher mat = create_matcher( "whichclan\=(\\d+)" , visit_url( "showplayer.php?who=" + my_id().to_string() ) );
	return ( ( find( mat ) ) ? to_int( group( mat , 1 ) ) : 0 );
}
 

Veracity

Developer
Staff member
Merging duplicates.

I'm all for (somebody) taking on this project. ;)

There is at least one more Bug Report that could be addressed if we, at least, detected that you had switched clans:

http://kolmafia.us/showthread.php?4435 - Can clan stash refresh after whitelisting between clans
(well, if not "refresh", at least get cleared and marked as "not retrieved")
 

Veracity

Developer
Staff member
I did a little investigation.

KoLmafia currently stores neither clan name nor ID. It detects whether you are in a clan or not by seeing there is a link to "clan_hall.php" in the topmenu. Presumably, if you leave a clan, the topmenu refreshes, and we mark you as not in a clan, and vice versa if you join a clan.

As described above by Alhifar & Grotfang, we can visit

showplayer.php?who=XXX

To find out the clan name and clan ID

If you visit clan_hall.php, you will be told the name of your current clan: it's the title of the frame, in bold. I see no clan ID on that page.

You can visit the clan recruiter and get a list of clan names and clan IDs that you are whitelisted to:

PHP:
<form action=showclan.php method=get>
  <input type=hidden name=recruiter value=1>
  Whitelist List:
  <select name=whichclan>
    <option value=90485>Bonus Adventures from Hell</option>
    <option value=6993>Grrl Power!</option>
    <option value=41543>Hardcore Nation</option>
    <option value=38808>Hardcore Oxygenation</option>
    ...
  </select>
  <input type=submit class=button value='Go to Clan'>
  <br>You are currently whitelisted by XX clans.
</form>

Visiting a clan from the recruiter:

showclan.php?recruiter=1&whichclan=6993

Applying to a clan from the recruiter:

showclan.php?pwd&whichclan=6993&action=joinclan&confirm=on
-> redirects to clan_hall.php

Joining a clan via /whitelist xxx

showclan.php?action=joinclan&pwd&whichclan=38808&ajax=1&confirm=1
-> You have now changed your allegiance.

(and presumably the "You are not cool enough" message for a clan you are not whitelisted to)

So, basically, we can track clan hopping easily enough and automatically detect the clan ID. The result of joining a clan - either via the recruiter or via /whitelist - does not tell you the clan name. We could presumably follow up with a quick "showclan.php?whichclan=xxx" or "showplayer.php?who=yyy" and parse the clan name from there.

I did not test applying to a clan I am not whitelisted to and being told later that I have been accepted. Do you have to leave your current clan to do that? Or are you auto-booted into having "no clan" while you are in that state? If so, the topmenu refresh will tell us that we are not in a clan, and, later, when it refreshes again and says we are in a clan, we could look at showplayer.php
 

lostcalpolydude

Developer
Staff member
If you use icons instead of links for the topmenu, the icon (and link) for clan_hall.php is in the topmenu (or not) based on your settings and is unrelated to whether you are in a clan.
 

Theraze

Active member
Bump on this. Attached the same patch as 2010/09/14 updated to use the current RuntimeLibrary. That means it needed ( Interpreter interpreter ) instead of (), but otherwise functionally the same.
> ashref get_clan

string get_clan_id( )
string get_clan_name( )
string to_json( null )

> ash get_clan_id()

Determining clan id...
Retrieving clan member list...
Returned: 2046994455

> ash get_clan_name()

Returned: Empyrion
Note that this took one server hit, just like mafia does, and until/unless I leave my clan, it won't take any more server hits. While it does take a server hit when first checked, it won't if you're actually in clan chat, or have checked your clan stash, or have done... anything else. It also resets your clan information when you leave or change clans, so it should be functionally/hit superior to currently available scripts in every way...

Also weird? to_json currently matches EVERY ashref check. :)
 

Attachments

  • GetClanName&Id.patch
    1.1 KB · Views: 25

StDoodle

Minion
Oh man, I missed a good chunk of this thread... if Veracity, or anyone else, wants an on-again off-again whitelist for testing purposes, feel free to get a hold of me and I can arrange that for HCN easily enough, if that helps at all.
 

lostcalpolydude

Developer
Staff member
Added these functions in r11208. I also made it so looking up the clan name/id actually takes 1 server hit instead of 2 (a second one to look up clan members). It would probably be useful to parse clan name/id from other pages where possible; if it is parsed, then it's being stored somewhere that isn't useful to these functions. The next step would be to clean up some redundancy (I found three separate places where clanId is defined without looking to clean that up).
 

lostcalpolydude

Developer
Staff member
I just realized that clanId is currently being parsed from the clan where you have your PvP Allegiance, so only get_clan_name() is properly working for the moment.
 

Theraze

Active member
They return different IDs? That's odd... they both get populated together in ClanManager, in the retrieveClanId() function.
Code:
	public static final int getClanId()
	{
		ClanManager.retrieveClanId();
		return ClanManager.clanId;
	}

	public static final String getClanName()
	{
		ClanManager.retrieveClanId();
		return ClanManager.clanName;
	}
Code:
	private static final void retrieveClanId()
	{
		if ( ClanManager.clanId != 0 )
		{
			return;
		}

		ProfileRequest clanIdLookup = new ProfileRequest( KoLCharacter.getUserName() );
		clanIdLookup.run();

		ClanManager.clanId = clanIdLookup.getClanId();
		ClanManager.clanName = clanIdLookup.getClanName();
	}
Don't see how that would give different info... unless clanIdLookup is currently broken. That's found in ClanMembersRequest, and matches CLANID_PATTERN to decide which clan you're in...
 

lostcalpolydude

Developer
Staff member
All fixed in 11213. If get_clan_id() returns 0 it means you aren't in a clan.

I switched ClanManager over to using ProfileRequest to update the clan, since that's what ClanMembersRequest was using anyway and there was no real reason for it to be that complicated. This meant that my fix to parsing clan id in ClanMembersRequest didn't actually help, and that parsing has been removed from there now.
 
Top