clashofclans.js Documentation

website·Indexed 30 days ago

https://clashofclans.js.org/

A JavaScript library for interacting with the Clash of Clans API. It provides a Client for API requests, a PollingClient for event-based data, and a RESTManager for accessing raw data. Features include internal caching, request overrides, and support for authentication via API keys or email.

Tokens
37.9K
Snippets
267
Records
413
Agent score
50%

What's inside clashofclans.js

  1. Overview of the clashofclans.js Node.js module

    clashofclans.js is a Node.js module designed to simplify interactions with the Clash of Clans API. It provides 100% coverage of the API and is built using an object-oriented, Promise-based architecture to ensure flexibility and ease of use for developers.
  2. Retrieve clan information using RESTManager

    The RESTManager provides several methods to fetch clan-related data from the API:

    • getClan(clanTag, options?): Retrieves detailed information about a specific clan using its tag.
    • getClans(query, options?): Searches for clans based on a query and optional filters.
    • getClanMembers(clanTag, options?): Retrieves the list of members for a specific clan.
    • getClanWarLog(clanTag, options?): Retrieves the war log for a specific clan.
  3. Core clashofclans.js API Classes

    The library provides several core classes for managing API interactions, including Client for general requests, PollingClient for polling, RESTManager for REST operations, and RequestHandler for processing requests. It also includes utility classes like QueueThrottler, BatchThrottler, and CacheStore.
  4. Retrieve Gold Pass season info using PollingClient.getGoldPassSeason

    The getGoldPassSeason method retrieves information about the current Gold Pass season. It accepts optional OverrideOptions and returns a promise that resolves to a GoldPassSeason object.
    const seasonInfo = await client.getGoldPassSeason(options?);
  5. Reference the RawSuperUnits type structure

    The RawSuperUnits type is an array of objects representing Super Units in Clash of Clans. Each object contains details about the unit's identity, requirements, and costs.
    interface RawSuperUnits {
      name: string;           // e.g., "Super Barbarian"
      id: number;             // e.g., 26
      original: string;       // The base unit, e.g., "Barbarian"
      minOriginalLevel: number; // Minimum level of base unit required, e.g., 8
      village: string;        // Village type, e.g., "home"
      duration: number;        // Duration in seconds, e.g., 259200
      cooldown: number;       // Cooldown in seconds, e.g., 259200
      resource: string;       // Resource type, e.g., "Dark Elixir"
      resourceCost: number;   // Cost of the unit, e.g., 25000
      housingSpace: number;    // Housing space required, e.g., 5
    }
    
    type RawSuperUnitsArray = RawSuperUnits[];
  6. Fetch current or historical clan wars

    Use getCurrentWar to get information about the currently running war. You can pass a string tag or an object to specify a specific round (PreviousRound, CurrentRound, or NextRound).
    // Current war
    await client.getCurrentWar('#8QU8J9LP');
    
    // Previous round war
    await client.getCurrentWar({ clanTag: '#8QU8J9LP', round: 'PREVIOUS_ROUND' });
  7. Reference APICapitalRaidSeasonDefenseLog properties

    The APICapitalRaidSeasonDefenseLog interface provides data about a clan's defense performance during a Capital Raid season. It includes the following properties:

    • attacker: The clan that performed the attack, represented as an APICapitalRaidSeasonClan object.
    • attackCount: The total number of attacks performed (number).
    • districtCount: The total number of districts available (number).
    • districtsDestroyed: The number of districts successfully destroyed (number).
    • districts: A list of specific districts involved in the defense, represented as an array of APICapitalRaidSeasonDistrict objects.
    interface APICapitalRaidSeasonDefenseLog {
      attacker: APICapitalRaidSeasonClan;
      attackCount: number;
      districtCount: number;
      districtsDestroyed: number;
      districts: APICapitalRaidSeasonDistrict[];
    }
  8. Initialize and use the RequestHandler class

    The RequestHandler class is used to manage handlers for endpoints and execute REST requests. It extends EventEmitter, allowing you to listen for events like error, rateLimited, and debug.
    const handler = new RequestHandler(options);
  9. APICapitalRaidSeason Interface Reference

    The APICapitalRaidSeason interface provides data about a specific Capital Raid season, including its current state, timing, loot, and logs of attacks and defenses.
    interface APICapitalRaidSeason {
      state: "ended" | "ongoing";
      startTime: string;
      endTime: string;
      capitalTotalLoot: number;
      raidsCompleted: number;
      totalAttacks: number;
      enemyDistrictsDestroyed: number;
      offensiveReward: number;
      defensiveReward: number;
      members?: APICapitalRaidSeasonMember[];
      attackLog: APICapitalRaidSeasonAttackLog[];
      defenseLog: APICapitalRaidSeasonDefenseLog[];
    }
  10. Retrieve Clan War League round information

    Use getClanWarLeagueRound to get details about a CWL round. The warTag parameter can be a simple string or an object containing both warTag and an optional clanTag.
    // Using a string tag
    const round = await client.getClanWarLeagueRound('warTag');
    
    // Using an object
    const round = await client.getClanWarLeagueRound({ warTag: 'warTag', clanTag: 'clanTag' });
  11. Access Player properties and clan status

    The Player class provides several properties and getters to retrieve a player's status, equipment, and clan roles:

    • heroEquipment: An array of Equipment objects.
    • playerHouse: Optional details about the player's clan capital house (APIPlayerHouse or null).
    • inClan: Boolean indicating if the player is currently in a clan.
    • isMember, isLeader, isCoLeader, isElder: Boolean or null indicators for the player's specific rank within a clan.
    • shareLink: A formatted string link used to open the player's profile in-game.
  12. Retrieve CWL round information by WarTag

    Use the getClanWarLeagueRound method to get details about a specific Clan War League round using the warTag.
    // Returns Promise<Result<APIClanWar>>
    await restManager.getClanWarLeagueRound(warTag, options?);