Skip to content

Commit

Permalink
feat: switch to undici (#64)
Browse files Browse the repository at this point in the history
* feat: switch to `undici`

* chore(deps): update

* fix: wrong filename

* docs: use https://contrib.rocks for the contributors image
  • Loading branch information
Tomio committed Jan 28, 2023
1 parent 8d772ac commit ca45be8
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 191 deletions.
30 changes: 0 additions & 30 deletions .all-contributorsrc

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/check-botlists.yml
@@ -0,0 +1,27 @@
name: Check Botlists

on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
check-botlists:
name: Check Botlists
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- name: Use Node.js v18
uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3
with:
node-version: 18
cache: yarn
registry-url: https://registry.npmjs.org/
- name: Install Dependencies
run: yarn --immutable
- name: Check botlists
run: yarn check-botlists
107 changes: 46 additions & 61 deletions README.md
Expand Up @@ -15,16 +15,16 @@ This plugin enables the integration of many bot lists such as Top.gg, Discord La

## Features

- Fully ready for TypeScript!
- Includes ESM ready entrypoint
- Easy to use
- Auto-detection of enabled sites
- Fully ready for TypeScript!
- Includes ESM ready entrypoint
- Easy to use
- Auto-detection of enabled sites

## Installation

`@devtomio/plugin-botlist` depends on the following packages. Be sure to install these along with this package!

- [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
- [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)

You can use the following command to install this package, or replace `npm install` with your package manager of choice.

Expand All @@ -48,19 +48,19 @@ require('@devtomio/plugin-botlist/register');
require('@devtomio/plugin-botlist/register');

const client = new SapphireClient({
/* your bot options */
/* your bot options */
botList: {
clientId: 'YOUR_CLIENT_ID', // Optional; by default it is the bot's id
debug: false, // (Optional), shows debug messages; by default it is false
shard: false, // (Optional), enable sharding support; by default it is false
autoPost: {
enabled: true, // (Optional); by default it is enabled
interval: 3_600_000, // (Optional); by default it is set to 1 hour
},
keys: {
topGG: 'YOUR_AWESOME_TOP_GG_API_KEY' // Your top.gg API key (a list will be found below)
}
}
autoPost: {
enabled: true, // (Optional); by default it is enabled
interval: 3_600_000 // (Optional); by default it is set to 1 hour
},
keys: {
topGG: 'YOUR_AWESOME_TOP_GG_API_KEY' // Your top.gg API key (a list will be found below)
}
}
});

async function main() {
Expand All @@ -82,19 +82,19 @@ import '@devtomio/plugin-botlist/register';
import '@devtomio/plugin-botlist/register';

const client = new SapphireClient({
/* your bot options */
/* your bot options */
botList: {
clientId: 'YOUR_CLIENT_ID', // Optional; by default it is the bot's id
debug: false, // (Optional), shows debug messages; by default it is false
clientId: 'YOUR_CLIENT_ID', // Optional; by default it is the bot's id
debug: false, // (Optional), shows debug messages; by default it is false
shard: false, // (Optional), enable sharding support; by default it is false
autoPost: {
enabled: true, // (Optional); by default it is enabled
interval: 3_600_000, // (Optional); by default it is set to 1 hour
},
keys: {
topGG: 'YOUR_AWESOME_TOP_GG_API_KEY' // Your top.gg API key (a list will be found below)
}
}
autoPost: {
enabled: true, // (Optional); by default it is enabled
interval: 3_600_000 // (Optional); by default it is set to 1 hour
},
keys: {
topGG: 'YOUR_AWESOME_TOP_GG_API_KEY' // Your top.gg API key (a list will be found below)
}
}
});

async function main() {
Expand All @@ -108,39 +108,24 @@ If you enable the `autoPost` option, the plugin will automatically publish the d

## List of Supported Sites

- [Top.gg](https://top.gg) | `topGG`
- [Discord Bot List](https://discordbotlist.com) | `discordBotList`
- [Bots on Discord](https://bots.ondiscord.xyz) | `botsOnDiscord`
- [Discords](https://discords.com) | `discords`
- [Discord Labs](https://bots.discordlabs.org) | `discordLabs`
- [BladeList](https://bladelist.gg) | `bladeListGG`
- [BotList.me](https://botlist.me) | `botListMe`
- [Discord List](https://discordlist.space) | `discordListSpace`
- [Discord Bots](https://discord.bots.gg) | `discordBotsGG`
- [Discord Extreme List](https://discordextremelist.xyz) | `discordExtremeList`
- [Blist](https://blist.xyz) | `blist`
- [Discord Services](https://discordservices.net) | `discordServices`
- [Disforge](https://disforge.com) | `disforge`
- [Fates List](https://fateslist.xyz) | `fatesList`
- [Infinity Bot List](https://infinitybots.gg) | `infinityBots`
- [Void Bots](https://voidbots.net) | `voidBots`

## 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="https://tomio.codes/"><img src="https://avatars.githubusercontent.com/u/75403863?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tomio</b></sub></a><br /><a href="https://github.com/devtomio/sapphire-plugin-botlist/commits?author=devtomio" title="Code">💻</a> <a href="https://github.com/devtomio/sapphire-plugin-botlist/commits?author=devtomio" title="Documentation">📖</a> <a href="#ideas-devtomio" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-devtomio" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#plugin-devtomio" title="Plugin/utility libraries">🔌</a> <a href="#maintenance-devtomio" title="Maintenance">🚧</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
<!-- 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!
- [Top.gg](https://top.gg) | `topGG`
- [Discord Bot List](https://discordbotlist.com) | `discordBotList`
- [Bots on Discord](https://bots.ondiscord.xyz) | `botsOnDiscord`
- [Discords](https://discords.com) | `discords`
- [Discord Labs](https://bots.discordlabs.org) | `discordLabs`
- [BotList.me](https://botlist.me) | `botListMe`
- [Discord Bots](https://discord.bots.gg) | `discordBotsGG`
- [Discord Extreme List](https://discordextremelist.xyz) | `discordExtremeList`
- [Blist](https://blist.xyz) | `blist`
- [Discord Services](https://discordservices.net) | `discordServices`
- [Disforge](https://disforge.com) | `disforge`
- [Infinity Bot List](https://infinitybots.gg) | `infinityBots`
- [Void Bots](https://voidbots.net) | `voidBots`

## Contributors

Thank you to all the people who already contributed to this project!

<a href="https://github.com/devtomio/sapphire-plugin-botlist/graphs/contributors">
<img src="https://contrib.rocks/image?repo=devtomio/sapphire-plugin-botlist" />
</a>
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -25,7 +25,7 @@
],
"scripts": {
"lint": "eslint src --ext ts --fix",
"format": "prettier --write src/**/*.ts",
"format": "prettier --write src/**/*.ts README.md package.json scripts/**/*",
"docs": "typedoc",
"update": "yarn upgrade-interactive",
"build": "tsc -b src && yarn esm:register && yarn esm:default",
Expand All @@ -35,6 +35,7 @@
"watch": "tsc -b src -w",
"bump": "cliff-jumper",
"check-update": "cliff-jumper --dry-run",
"check-botlists": "node scripts/check.mjs",
"sversion": "standard-version",
"commit": "git-cz",
"cz": "git-cz",
Expand All @@ -43,9 +44,9 @@
"postpack": "pinst --enable"
},
"dependencies": {
"@sapphire/fetch": "^2.4.1",
"tiny-typed-emitter": "^2.1.0",
"tslib": "^2.5.0"
"tslib": "^2.5.0",
"undici": "^5.16.0"
},
"devDependencies": {
"@commitlint/cli": "^17.4.2",
Expand All @@ -59,6 +60,7 @@
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"colorette": "^2.0.19",
"cz-conventional-changelog": "^3.3.0",
"discord.js": "^14.7.1",
"eslint": "^8.32.0",
Expand Down
55 changes: 55 additions & 0 deletions scripts/check.mjs
@@ -0,0 +1,55 @@
import { fetch } from 'undici';
import { bold, green, red } from 'colorette';

/** @type {[string, number | undefined, string | undefined][]} */
const sites = [
['https://top.gg'],
['https://top.gg/api', 418 /* I'm a teapot */],
['https://discordbotlist.com'],
['https://bots.ondiscord.xyz'],
['https://discords.com'],
['https://discords.com/bots/api'],
['https://bots.discordlabs.org'],
['https://botlist.me'],
['https://discord.bots.gg'],
['https://discord.bots.gg/api/v1', undefined, 'GET'],
['https://discordextremelist.xyz'],
['https://api.discordextremelist.xyz/v2/health'],
['https://blist.xyz'],
['https://blist.xyz/api/v2'],
['https://discordservices.net'],
['https://api.discordservices.net'],
['https://disforge.com'],
['https://disforge.com/api'],
['https://infinitybots.gg'],
['https://api.infinitybots.gg'],
['https://voidbots.net'],
['https://discordlist.gg'],
['https://api.discordlist.gg/developers']
];

/** @type {[Promise<import('undici').Response>, string, number][]} */
const responses = sites.map(([url, expectedStatusCode, method]) => {
expectedStatusCode ??= 200;
method ??= 'GET';

return [fetch(url, { method }), url, expectedStatusCode];
});

let hasFailure = false;

for (let [response, url, expectedStatusCode] of responses) {
response = await response;

if (!response || expectedStatusCode !== response.status) {
hasFailure = true;

console.log(`${bold(url)} ${bold(red('failed.'))}`);
continue;
}

console.log(`${bold(url)} ${bold(green('ok.'))}`);
}

if (hasFailure) process.exit(1);
else process.exit(0);
4 changes: 2 additions & 2 deletions src/index.ts
@@ -1,6 +1,6 @@
import { BotList } from './lib/BotList';
import { BotList } from './lib/botlist';

export * from './lib/Post';
export * from './lib/post';
export { BotList };

declare module 'discord.js' {
Expand Down
30 changes: 5 additions & 25 deletions src/lib/BotList.ts
@@ -1,9 +1,7 @@
// eslint-disable-next-line spaced-comment
/// <reference lib="dom" />

import { TypedEmitter } from 'tiny-typed-emitter';
import { container } from '@sapphire/framework';
import { Post } from './Post';
import { Post } from './post';
import type { Response } from 'undici';

/**
* The BotList class.
Expand Down Expand Up @@ -32,7 +30,7 @@ export class BotList extends TypedEmitter<BotList.Events> {
* @since 1.0.0
*/
public async postStats() {
const enabledSites = Object.keys(this.keys).filter((k) => typeof k !== 'undefined');
const enabledSites = Object.keys(this.keys).filter((k) => !k);

for (const site of enabledSites) {
await this.post[site as keyof BotList.Keys]();
Expand Down Expand Up @@ -111,7 +109,7 @@ export namespace BotList {

/**
* The interval in milliseconds.
* @default 3.6e6
* @default 3.6e6 // One hour
* @since 1.0.0
*/
interval?: number;
Expand Down Expand Up @@ -155,24 +153,12 @@ export namespace BotList {
*/
discordLabs?: string;

/**
* @see https://bladelist.gg
* @since 1.0.0
*/
bladeListGG?: string;

/**
* @see https://botlist.me
* @since 1.0.0
*/
botListMe?: string;

/**
* @see https://discordlist.space
* @since 1.0.0
*/
discordListSpace?: string;

/**
* @see https://discord.bots.gg
* @since 1.0.0
Expand Down Expand Up @@ -203,12 +189,6 @@ export namespace BotList {
*/
disforge?: string;

/**
* @see https://fateslist.xyz
* @since 1.2.0
*/
fatesList?: string;

/**
* @see https://infinitybots.gg
* @since 1.2.0
Expand All @@ -223,7 +203,7 @@ export namespace BotList {

/**
* @see https://discordlist.gg
* @since 1.2.1
* @since 1.3.0
*/
discordListGG?: string;
}
Expand Down

0 comments on commit ca45be8

Please sign in to comment.