npm package: @fdgt/api
Description: [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=trezy-studios/fdgt)](https://dependabot.com) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> [![All Contributors](https://img.shields.io/badge/all
Latest version: 1.0.2

# fdgt
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=trezy-studios/fdgt)](https://dependabot.com)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

`fdgt` is a mock API for the Twitch Messaging Interface (`tmi`). Via `fdgt`, you can connect and test your Twitch bots and other tools with simulated events *without* having to connect to the real API!

## How does it work?

Using `fdgt` is pretty simple. Instead of pointing to the `irc-ws.chat.twitch.tv`, you point to to `tmi.fdgt.dev`. DONE.

### Wait seriously?

Yup.

### It can't be that simple!

It is, tho. Check out this example with [`tmi.js`][tmi.js].

#### Connecting to the real `tmi`

```js
const tmi = require('tmi.js')
const client = new tmi.Client()

client.connect()
```

#### Connecting to the `fdgt` mock `tmi`

```js
const tmi = require('tmi.js')
const client = new tmi.Client({
	connection: { server: 'tmi.fdgt.dev' },
})

client.connect()
```

### Simulating events

One of the hardest parts of working with the Twitch chat API is that to test your tool with different payloads, you have to perform the real action that would trigger that event.

**Need to trigger a message with bits?** You're going to be cheering a lot.

**Need to simulate a subscription?** I hope you've got deep pockets.

**Need to simulate a `submysterygift` with 10 Tier 3 subscriptions?** God help you.

Instead of blowing the wads of cash that you probably don't have, use `fdgt`! With `fdgt`, you just have to send the right message to the chat service, and it'll trigger the appropriate event! Here's an example of triggering a message with bits in it, again using `tmi.js`:

```js
client.say('#TrezyCodes', 'bits')
```

And just like that, `fdgt` will fire a simulated message with bits attached!

### Getting a specific response

Sometimes, the randomized events that `fdgt` generates just aren't specific enough. Fortunately, `fdgt`'s interface is controlled just like a CLI! If you want to change the username of the person that "triggered" the event, you can pass it with the `--username` flag!

```js
client.say('#TrezyCodes', 'bits --username alca')
```

...or, say you want to simulate that 10x Tier 3 `submysterygift` we mentioned earlier:

```js
client.say('#TrezyCodes', 'submysterygift.tier3 --username alca --giftcount 10')
```

For more information on what events are available and what parameters they support, check out the [events][events] section.

## Help & Support

Need some help using `fdgt`? No problem! Hop on to the [Trezy Studios Discord][discord] and we'll be happy to help! ❤️

## API

### Events

#### Globally supported parameters

The following table describes the parameters that are supported by *almost* every message. There are exceptions (namely the mode triggers, like `emoteonly`, `slowmode`, and `subsonly`), noted under the respective events.

| Parameter   | Description                                                     | Default Value                           |
| ----------- | --------------------------------------------------------------- | --------------------------------------- |
| `channel`   | The name of the channel (no `#`)                                | the channel that the event was sent to  |
| `channelid` | The ID of the channel                                           | randomly UUID                           |
| `color`     | The user's display color                                        | randomly generated hex color            |
| `messageid` | The ID of the message                                           | randomly UUID                           |
| `timestamp` | The timestamp (in milliseconds) of the message                  | the current timestamp                   |
| `userid`    | The ID of the user sending the message or triggering the event  | randomly UUID                           |
| `username`  | The username of the user that triggered the event               | randomly generated by [`faker`][faker]  |
| `host`      | The host of the Twitch server                                   | `tmi.twitch.tv`                         |

#### `bits`

This event is normally triggered when a user does X.

##### Supported parameters

| Parameter   | Description                                 | Default Value                                 |
| ----------- | ------------------------------------------- | --------------------------------------------- |
| `bitscount` | the total number of bits that were cheered  | `100`                                         |
| `message`   | the message body that was sent              | the message body, i.e. `bits --bitscount 50`  |

##### Examples

```js
client.say('#csharpfritz', 'bits --bitscount 50')
```

#### `emoteonly.off`

This event is normally triggered when the room is set to emote-only mode, then emote-only mode is turned off.

##### Supported parameters

This event **does not support all global parameters**. The table below is an exhaustive list of the supported parameters for this event.

| Parameter   | Description                       | Default Value                       |
| ----------- | --------------------------------- | ----------------------------------- |
| `channel`   | the name of the channel (no `#`)  | a random channel that you've joined |
| `host`      | the host of the Twitch server     | `tmi.twitch.tv`                     |

##### Examples

```js
client.say('#chaelcodes', 'emoteonly.off --channel timbeaudet')
```

#### `emoteonly.on`

This event is normally triggered when the room is set to emote-only mode.

##### Supported parameters

This event **does not support all global parameters**. The table below is an exhaustive list of the supported parameters for this event.

| Parameter   | Description                       | Default Value                       |
| ----------- | --------------------------------- | ----------------------------------- |
| `channel`   | the name of the channel (no `#`)  | a random channel that you've joined |
| `host`      | the host of the Twitch server     | `tmi.twitch.tv`                     |

##### Examples

```js
client.say('#stuyksoft', 'emoteonly.on --channel tutorexilius')
```

#### `extendsub.tier1`

This event is normally triggered when a user extends their Tier 1 subscription.

##### Supported parameters

| Parameter | Description                                                   | Default Value |
| --------- | ------------------------------------------------------------- | ------------- |
| `months`  | the number of months that the subscription is being extended  | `3`           |

##### Examples

```js
client.say('#howtocodewell', 'extendsub.tier1 --months 6')
```

`fdgt` will automatically calculate and name the correct month, so if you want the month in the message to be in the future (or the past!), make sure to set the `timestamp`. To represent an extension from January 2015 to June 2015, you could do the following:

```js
client.say('#chefbrent', 'extendsub.tier1 --months 6 --timestamp 1420092000000')
```

#### `extendsub.tier2`

This event is normally triggered when a user extends their Tier 2 subscription.

##### Supported parameters

| Parameter | Description                                                   | Default Value |
| --------- | ------------------------------------------------------------- | ------------- |
| `months`  | the number of months that the subscription is being extended  | `3`           |

##### Examples

```js
client.say('#jeffblankenburg', 'extendsub.tier2 --months 6')
```

`fdgt` will automatically calculate and name the correct month, so if you want the month in the message to be in the future (or the past!), make sure to set the `timestamp`. To represent an extension from January 2015 to June 2015, you could do the following:

```js
client.say('#latteandmia', 'extendsub.tier2 --months 6 --timestamp 1420092000000')
```

#### `extendsub.tier3`

This event is normally triggered when a user extends their Tier 3 subscription.

##### Supported parameters

| Parameter | Description                                                   | Default Value |
| --------- | ------------------------------------------------------------- | ------------- |
| `months`  | the number of months that the subscription is being extended  | `3`           |

##### Examples

```js
client.say('#mbcrump', 'extendsub.tier3 --months 6')
```

`fdgt` will automatically calculate and name the correct month, so if you want the month in the message to be in the future (or the past!), make sure to set the `timestamp`. To represent an extension from January 2015 to June 2015, you could do the following:

```js
client.say('#itslittany', 'extendsub.tier3 --months 6 --timestamp 1420092000000')
```

#### `giftpaidupgrade`

This event is normally triggered when a user upgrades from a gifted subscription.

##### Supported parameters

| Parameter   | Description                                                             | Default Value                                   |
| ----------- | ----------------------------------------------------------------------- | ----------------------------------------------- |
| `username2` | the username of the user that last gifted a sub to the triggering user  | a random username generated by [`faker`][faker] |

##### Examples

```js
client.say('#themessycoder', 'giftpaidupgrade --username2 MrDemonWolf')
```

#### `primepaidupgrade.tier1`

This event is normally triggered when a user upgrades from a Prime subscription to a Tier 1 subscription.

##### Supported parameters

This event **only** supports the global parameters.

##### Examples

```js
client.say('#shadesofpixie', 'primepaidupgrade.tier1')
```

#### `primepaidupgrade.tier2`

This event is normally triggered when a user upgrades from a Prime subscription to a Tier 2 subscription.

##### Supported parameters

This event **only** supports the global parameters.

##### Examples

```js
client.say('#edcharbeneau', 'primepaidupgrade.tier2')
```

#### `primepaidupgrade.tier3`

This event is normally triggered when a user upgrades from a Prime subscription to a Tier 3 subscription.

##### Supported parameters

This event **only** supports the global parameters.

##### Examples

```js
client.say('#ramblinggeek', 'primepaidupgrade.tier3')
```

#### `raid`

This event is normally triggered when a channel is raided by another stream.

##### Supported parameters

| Parameter     | Description                                 | Default Value |
| ------------- | ------------------------------------------- | ------------- |
| `viewerCount` | the number of viewers that joined the raid  | `10`          |

##### Examples

```js
client.say('#narebabr', 'raid --viewerCount 100')
```

#### `resubscription.prime`

This event is normally triggered when a user continues their Prime subscription.

##### Supported parameters

| Parameter | Description                                                   | Default Value |
| --------- | ------------------------------------------------------------- | ------------- |
| `months`  | the number of months for which the user has been a subscriber | `3`           |

##### Examples

```js
client.say('#developersgarage', 'resubscription.prime --months 6')
```

#### `resubscription.tier1`

This event is normally triggered when a user continues their Tier 1 subscription.

##### Supported parameters

| Parameter | Description                                                   | Default Value |
| --------- | ------------------------------------------------------------- | ------------- |
| `months`  | the number of months for which the user has been a subscriber | `3`           |

##### Examples

```js
client.say('#relevantjesse', 'resubscription.tier1 --months 6')
```

#### `resubscription.tier2`

This event is normally triggered when a user continues their Tier 2 subscription.

##### Supported parameters

| Parameter | Description                                                   | Default Value |
| --------- | ------------------------------------------------------------- | ------------- |
| `months`  | the number of months for which the user has been a subscriber | `3`           |

##### Examples

```js
client.say('#roberttables', 'resubscription.tier2 --months 6')
```

#### `resubscription.tier3`

This event is normally triggered when a user continues their Tier 3 subscription.

##### Supported parameters

| Parameter | Description                                                   | Default Value |
| --------- | ------------------------------------------------------------- | ------------- |
| `months`  | the number of months for which the user has been a subscriber | `3`           |

##### Examples

```js
client.say('#timvanmonero', 'resubscription.tier3 --months 6')
```

#### `slowmode.off`

This event is normally triggered when the room is set to slow mode, then slow mode is turned off.

##### Supported parameters

This event **does not support all global parameters**. The table below is an exhaustive list of the supported parameters for this event.

| Parameter   | Description                       | Default Value                       |
| ----------- | --------------------------------- | ----------------------------------- |
| `channel`   | the name of the channel (no `#`)  | a random channel that you've joined |
| `host`      | the host of the Twitch server     | `tmi.twitch.tv`                     |

##### Examples

```js
client.say('#rosuav', 'slowmode.off --channel fiercekittenz')
```

#### `slowmode.on`

This event is normally triggered when the room is set to slow mode.

##### Supported parameters

This event **does not support all global parameters**. The table below is an exhaustive list of the supported parameters for this event.

| Parameter   | Description                       | Default Value                       |
| ----------- | --------------------------------- | ----------------------------------- |
| `channel`   | the name of the channel (no `#`)  | a random channel that you've joined |
| `host`      | the host of the Twitch server     | `tmi.twitch.tv`                     |

##### Examples

```js
client.say('#lannonbr', 'slowmode.on --channel sudokid')
```

#### `subgift.tier1`

This event is normally triggered when a user gifts a Tier 1 subscription to another user in the channel.

##### Supported parameters

| Parameter   | Description                                                       | Default Value                                   |
| ----------- | ----------------------------------------------------------------- | ----------------------------------------------- |
| `userid2`   | the username of the user that is receiving the subscription gift  | a random username generated by [`faker`][faker] |
| `username2` | the id of the user that is receiving the subscription gift        | a random UUID                                   |

##### Examples

```js
client.say('#chiefcll', 'subgift.tier1 --username2 jitterted')
```

#### `subgift.tier2`

This event is normally triggered when a user gifts a Tier 2 subscription to another user in the channel.

##### Supported parameters

| Parameter   | Description                                                       | Default Value                                   |
| ----------- | ----------------------------------------------------------------- | ----------------------------------------------- |
| `userid2`   | the username of the user that is receiving the subscription gift  | a random username generated by [`faker`][faker] |
| `username2` | the id of the user that is receiving the subscription gift        | a random UUID                                   |

##### Examples

```js
client.say('#davidortinau', 'subgift.tier2 --username2 syropian')
```

#### `subgift.tier3`

This event is normally triggered when a user gifts a Tier 3 subscription to another user in the channel.

##### Supported parameters

| Parameter   | Description                                                       | Default Value                                   |
| ----------- | ----------------------------------------------------------------- | ----------------------------------------------- |
| `userid2`   | the username of the user that is receiving the subscription gift  | a random username generated by [`faker`][faker] |
| `username2` | the id of the user that is receiving the subscription gift        | a random UUID                                   |

##### Examples

```js
client.say('#cldubya', 'subgift.tier3 --username2 drmikachu')
```


#### `submysterygift.tier1`

This event is normally triggered when a user gives Tier 1 mystery subscription gifts.

##### Supported parameters

| Parameter         | Description                                                     | Default Value |
| ----------------- | --------------------------------------------------------------- | ------------- |
| `giftcount`       | the number of gifts the user is currently giving in the channel | `5`           |
| `totalgiftcount`  | the total number of gifts the user has given in the channel     | `giftcount`   |

##### Examples

```js
client.say('#jumpystick', 'submysterygift.tier1 --giftcount 10')
```

#### `submysterygift.tier2`

This event is normally triggered when a user gives Tier 2 mystery subscription gifts.

##### Supported parameters

| Parameter         | Description                                                     | Default Value |
| ----------------- | --------------------------------------------------------------- | ------------- |
| `giftcount`       | the number of gifts the user is currently giving in the channel | `5`           |
| `totalgiftcount`  | the total number of gifts the user has given in the channel     | `giftcount`   |

##### Examples

```js
client.say('#lizelive', 'submysterygift.tier2 --giftcount 10')
```

#### `submysterygift.tier3`

This event is normally triggered when a user gives Tier 3 mystery subscription gifts.

##### Supported parameters

| Parameter         | Description                                                     | Default Value |
| ----------------- | --------------------------------------------------------------- | ------------- |
| `giftcount`       | the number of gifts the user is currently giving in the channel | `5`           |
| `totalgiftcount`  | the total number of gifts the user has given in the channel     | `giftcount`   |

##### Examples

```js
client.say('#fullstacklive', 'submysterygift.tier3 --giftcount 10')
```

#### `subscription.prime`

This event is normally triggered when a user subscribes to a channel for the first time with Prime.

##### Supported parameters

This event **only** supports the global parameters.

##### Examples

```js
client.say('#talk2megooseman', 'subscription.prime --channel funfunfunction')
```

#### `subscription.tier1`

This event is normally triggered when a user purchases a Tier 1 subscription to a channel for the first time.

##### Supported parameters

This event **only** supports the global parameters.

##### Examples

```js
client.say('#lana_lux', 'subscription.tier1 --channel jamesmontemagno')
```

#### `subscription.tier2`

This event is normally triggered when a user purchases a Tier 2 subscription to a channel for the first time.

##### Supported parameters

This event **only** supports the global parameters.

##### Examples

```js
client.say('#coderushed', 'subscription.tier2 --channel codingbandit')
```

#### `subscription.tier3`

This event is normally triggered when a user purchases a Tier 3 subscription to a channel for the first time.

##### Supported parameters

This event **only** supports the global parameters.

##### Examples

```js
client.say('#clarkio', 'subscription.tier3 --channel kasuken')
```

#### `subsonly.off`

This event is normally triggered when the room is set to subscribers-only mode, then subscribers-only mode is turned off.

##### Supported parameters

This event **does not support all global parameters**. The table below is an exhaustive list of the supported parameters for this event.

| Parameter   | Description                       | Default Value                       |
| ----------- | --------------------------------- | ----------------------------------- |
| `channel`   | the name of the channel (no `#`)  | a random channel that you've joined |
| `host`      | the host of the Twitch server     | `tmi.twitch.tv`                     |

##### Examples

```js
client.say('#alca', 'subsonly.off --channel atomikjaye')
```

#### `subsonly.on`

This event is normally triggered when the room is set to subscribers-only mode.

##### Supported parameters

This event **does not support all global parameters**. The table below is an exhaustive list of the supported parameters for this event.

| Parameter   | Description                       | Default Value                       |
| ----------- | --------------------------------- | ----------------------------------- |
| `channel`   | the name of the channel (no `#`)  | a random channel that you've joined |
| `host`      | the host of the Twitch server     | `tmi.twitch.tv`                     |

##### Examples

```js
client.say('#devchatter', 'subsonly.on --channel brandonsatrom')
```





[discord]: https://discord.gg/k3bth3f "Trezy Studios Discord"
[events]: #events
[faker]: https://github.com/Marak/Faker.js#readme "Faker.js on Github"
[tmi.js]: https://tmijs.com/ "tmi.js website"

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
	<tr>
		<td align="center"><a href="http://trezy.com"><img src="https://avatars2.githubusercontent.com/u/442980?v=4" width="100px;" alt=""/><br /><sub><b>Trezy</b></sub></a><br /><a href="https://github.com/trezy-studios/fdgt/commits?author=trezy" title="Code">💻</a> <a href="#business-trezy" title="Business development">💼</a> <a href="https://github.com/trezy-studios/fdgt/commits?author=trezy" title="Documentation">📖</a> <a href="#example-trezy" title="Examples">💡</a> <a href="#infra-trezy" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-trezy" title="Maintenance">🚧</a></td>
	</tr>
</table>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!