# Radarcord-js

### Features

* Easy to use
* Supports `discord.js` and will support `eris` soon.
* Supports TypeScript
* May come with Webhook support soon.

### Installation

{% tabs %}
{% tab title="npm" %}
{% code fullWidth="true" %}

```bash
npm install @yoshiboi18303/radarcord-js
```

{% endcode %}
{% endtab %}

{% tab title="yarn" %}
{% code fullWidth="true" %}

```bash
yarn add @yoshiboi18303/radarcord-js
```

{% endcode %}
{% endtab %}

{% tab title="pnpm" %}
{% code fullWidth="true" %}

```bash
pnpm add @yoshiboi18303/radarcord-js
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Basic `discord.js` Usage

{% tabs %}
{% tab title="JavaScript" %}
{% code fullWidth="true" %}

```javascript
const Discord = require("discord.js");
const { Client: Radar } = require("@yoshiboi18303/radarcord-js");

const client = new Discord.Client({
    intents: new Discord.IntentsBitField(["Guilds"]),
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.

client.on("ready", async () => {
    console.log("The client is ready!")
    await radar.postStats(); // Send a stats post to the Radarcord API.
});

client.login("YOUR_TOKEN_HERE"); // Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token.
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code fullWidth="true" %}

```typescript
import Discord from "discord.js";
import { Client as Radar } from "@yoshiboi18303/radarcord-js";

const client = new Discord.Client({
    intents: new Discord.IntentsBitField(["Guilds"]),
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.

client.on("ready", async () => {
    console.log("The client is ready!");
    await radar.postStats(); // Send a stats post to the Radarcord API.
});

client.login("YOUR_TOKEN_HERE"); // Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token.
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Basic `eris` Usage

{% hint style="success" %}
This usage also works for classes that extend the `Eris.Client` class (e.g. `Eris.CommandClient`) so don't worry about having to rewrite your whole codebase!
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript" data-full-width="true"><code class="lang-javascript">const Eris = require("eris");
// Note that we're importing ErisClient here rather than Client.
<strong>const { ErisClient: Radar } = require("@yoshiboi18303/radarcord-js");
</strong>
const client = Eris("YOUR_TOKEN_HERE", /* Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token. */ {
    intents: ["guilds"],
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.

client.on("ready", async () => {
    console.log("The client is ready!");
    await radar.postStats(); // Send a stats post to the Radarcord API.
});

client.connect();
</code></pre>

{% endtab %}

{% tab title="TypeScript" %}
{% code fullWidth="true" %}

```typescript
import Eris from "eris";
// Note that we're importing ErisClient here rather than Client.
import { ErisClient as Radar } from "@yoshiboi18303/radarcord-js";

const client = Eris("YOUR_TOKEN_HERE", /* Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token. */ {
    intents: ["guilds"],
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.

client.on("ready", async () => {
    console.log("The client is ready!");
    await radar.postStats(); // Send a stats post to the Radarcord API.
});

client.connect();
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
These next methods are the same for `discord.js` and `eris` if you're using `eris`, use the class in the [Basic Eris Usage](#basic-eris-usage) section.
{% endhint %}

### Autoposting Usage

{% tabs %}
{% tab title="JavaScript" %}
{% code fullWidth="true" %}

```javascript
const Discord = require("discord.js");
const { Client: Radar } = require("@yoshiboi18303/radarcord-js");
const { IntervalPreset } = require("@yoshiboi18303/radarcord-js/dist/utils");

const client = new Discord.Client({
    intents: new Discord.IntentsBitField(["Guilds"]),
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.

client.on("ready", async () => {
    console.log("The client is ready!")
    // The timeoutInterval argument defaults to IntervalPreset.Default (120 seconds) if not passed in.
    await radar.autopostStats();
    // You can also pass in your own time interval!
    await radar.autopostStats(1 /* shardCount */, IntervalPreset.Safe /* timeoutInterval */);
});

client.login("YOUR_TOKEN_HERE"); // Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token.
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code fullWidth="true" %}

```typescript
import Discord from "discord.js";
import { Client as Radar } from "@yoshiboi18303/radarcord-js";
import { TimeoutInterval } from "@yoshiboi18303/radarcord-js/dist/utils";

const client = new Discord.Client({
    intents: new Discord.IntentsBitField(["Guilds"]),
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.

client.on("ready", async () => {
    console.log("The client is ready!");
    // The timeoutInterval argument defaults to IntervalPreset.Default (120 seconds) if not passed in.
    await radar.autopostStats();
    // You can also pass in your own time interval!
    await radar.autopostStats(1 /* shardCount */, TimeoutInterval.Safe /* timeoutInterval */);
});

client.login("YOUR_TOKEN_HERE"); // Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token.
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Basic Callback Usage

{% tabs %}
{% tab title="JavaScript" %}
{% code fullWidth="true" %}

```javascript
const Discord = require("discord.js");
const { Client: Radar } = require("@yoshiboi18303/radarcord-js");

const client = new Discord.Client({
    intents: new Discord.IntentsBitField(["Guilds"]),
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.
const callback = async (result) => {
    // You can also send messages to Discord if you prefer!
    console.log(result);
}

client.on("ready", async () => {
    console.log("The client is ready!");
    await radar.postWithCallback(callback);
});

client.login("YOUR_TOKEN_HERE"); // Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token.
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code lineNumbers="true" fullWidth="true" %}

```typescript
import Discord from "discord.js";
import { Client as Radar } from "@yoshiboi18303/radarcord-js";
import { StatsPostCallback } from "@yoshiboi18303/radarcord-js/utils";

const client = new Discord.Client({
    intents: new Discord.IntentsBitField(["Guilds"]),
});
const radar = new Radar(client, "myradarcordauthtoken"); // Make sure to replace myradarcordauthtoken with your actual Radarcord auth token.
const callback: StatsPostCallback = async (result) => {
    // You can also send messages to Discord if you prefer!
    console.log(result);
}

client.on("ready", async () => {
    console.log("The client is ready!");
    await radar.postWithCallback(callback);
});

client.login("YOUR_TOKEN_HERE"); // Make sure to replace YOUR_TOKEN_HERE with your Discord bot's token.
```

{% endcode %}
{% endtab %}
{% endtabs %}
