Skip to content

ryancundiff/clash.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

A simple Node.js module designed to streamline interactions with the Clash of Clans API.

  • Promise-based for asynchronous handling
  • Fully object-oriented for intuitive usage
  • Predictable abstractions for ease of development
  • Fully typed with JSDoc specifications for improved code quality and developer experience
  • Automatic token creation and deletion for if you don't have a static IP address.

Getting Started

Prerequisites

  • Node.js 20.13.1 or higher (previous versions may work but are not tested)

Installation

Install package via NPM:

  npm i clash.js

Usage Example

Here's a basic example demonstrating how to use clash.js to fetch a player and their clan:

import { Client } from 'clash.js'

You can import by destructuring or by default import (eg: import Client from 'clash.js').

(async () => {
  const client = new Client({
    email: 'your@gmail.com',
    password: '*'
  })

Replace your@gmail.com with your email, and * with your password for your Clash of Clans API developer account.

  const player = await client.getPlayer('#ABCDEFG')

Replace #ABCDEFG with your player tag of choice. You could even provide a tag without a hashtag and lower-case characters (eg: ab1d23e) and it would resolve (eg: #AB1D23E).

  if (player) {
    const barbarianKing = player.getHero('Barbarian King')

Look up a player's hero from their class object (parameter fully typed), or you could view a whole array of their heroes with the heroes data member of Player.

    const playerClan = await player.getClan()

You can even retrieve a player's full clan from their class object without passing a tag as a parameter.

    const capital = playerClan?.capital

    const golemQuarry = capital.getDistrict('Golem Quarry')

Look up a capital's district from it's class object (parameter fully typed).

  }

  const clan = await client.getClan('#ABCDEFG')

You can also get a clan by providing a clan tag to the getClan member function of Client.

  const war = await client.getWar('#ABCDEFG')

You can get a clan's current war by providing a clan tag to the getWar member function of Client.

  if (war) {
    const ally = war.ally
    const allyMembers = ally.members
    const enemy = war.enemy
    const enemyMembers = enemy.members
    const firstAllyMember = allyMembers[0]
    const bestEnemyAttack = firstAllyMember.bestEnemyAttack

You can access members, attacks, and more with the War object.

  }
})()

And there's even more...

Use clash.js in your Clash of Clan's project workflow and let your intellisense thank you later!

About

A simple Node module that allows you to easily interact with the Clash of Clans API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published