Skip to content

Commit

Permalink
refactor: switch to fetch for topgg stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Jun 28, 2024
1 parent 883fb6d commit 98e279e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .env.vault
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#/--------------------------------------------------/

# development
DOTENV_VAULT_DEVELOPMENT="XybdHz3XXzgW93jK9+Xe0PNCpUAmURKe7FfGfywPrEPC3FKuTdE6gXMYrHlph0oUZGsIoI/Me8uI+UH9cu8eSo7Hn4cLWhayjfLkFCnf4Q33BvuuF8Y0DPL1AQsFWSt7xbccNTTJW253W/x2JbQjyaHnM1NQLLQP6VyzMSw6Pgbyb+iOZ5zzfvj/iKmATwU3eToQ+wgdDCuBf8rYJH3ZGyX+Vm1Fa7NxmgDUyE14KYGwt3TLB1hGZ74wbN+kxRW9FaMvS03AZExY7zZnp/skarPkClEfbUDUy2TFmporeen/63ylvkxhylaGqrvmyDQwA9hoB+IVYe91GYmEu/ectj0+9Ku5kU4UMXPCcU34n04/+3kV1bhYYHHCY3DMjI5sJnwI/rLjWfiEeIpIJtlmIKJpgL5DWrWzcgqY79cIhF+HLRVI/LTGNCNEHbaSmKFcngnU3s1WsxzFPvsjRoRBiJIsUDqkff5XPCibn6qw6TS9qB+Mxp4CQiv8qYto9t/elyq8bgxO6m/XjbyUlNO28ysI5sywWqZ8kbVNAHwPHvRc/DbCwKp+QdJ9/IcNBotZ1cEIoZke/EQZmR/EfRGtEqchFVCR381uOmlh8p1XRSIIZvYNPIr9NLn0MKzSTWQG7gBnIX1qwmOofmYIEgsWoj1SaKtODYjSrvZxYXE="
DOTENV_VAULT_DEVELOPMENT="C0wMAXip45clNHJkkooSgcMJ7c7YkPNI0DYQMZWblNyEXP0lTObU4eYgOpPrDzMHgSPRUqH2b+k8O5Pm70DXMfkbh+tojcM4In5WH8gJIiepmYqU/O8XdocoGV2CPJO6rRTqhv1Z5Bb1ZM67ECc10SKDdzl7ZqugOL/1/oPeWjfNKz8AyaHsrz4w09F3rpZBviFsc2sYNdq7td0j/Hcr9F1SfS4nsl7r9Gz3zrTuhP05qZcLuI+nGGMLWssr68ZHMM6ax9FsNG96tnMpEDLabbaBDZeZVaAa/U25+jy2K5nS0tx6APHVHcYGcQuptWChepznFkDfCj4hHV+2AcYYpp4u0z282xf0nDARExFQwZSrfrcml049PU20g9h0Rbti3YiSGCoe8Qq2QKUG2LMWhMp94tk7/Im12IlvuRtY8eXVffIG56uCfbeKkXAiUZHg5sj+WeA="

# production
DOTENV_VAULT_PRODUCTION="V6zn8Lp1kc1BSyB/qKrmUyNWasYIv+nkQn/HjDyhhTISWcRdqU8rWuGuv4D1JW1cWmPlR58anIFCmbGVxVTP0tSAbBfhCNGPl5Gooh0KkDfEhHXJab/3iAp59YzJ1dvWeVomcxQ3kX6yXNwH2iwjtf+G23HGNvUM+xSDKzxEKULrGeHTJg+WKW53uLSGkQZYz3sHOZvjKE3acR3qpauchnaRnQLVhIJffUEWp1gOzHtWqwTgKrpqr7WzUJxy2IMg+t62iGv0jwT/HDxq+7aq1DKFhkB9lEMZjJUHzfAihsp0nnPc/tqKAiHIjKoMr/JvHP6au24jeMXQ0EcsDMtvJYa8w87RqATksSq5+7eeQKYcjqYJbO6UMd/6mAaljFaDZgMuzU3meBE0cuysj2Lw9x3sgHcSlyLRTlkFKz3VapsChk0n0ebNQ5YAehwhbx7GzdSKGc+g2YJnwlZFknRaAnCU4C3uQz5WA/7B0jXg7POf1feQbIRDUJwtPHgV4BF6xTJfFkvjUtlzFlmd+1hu+5poo3Gvd+wHB6xqgdvQfd+pYPXBMeNcEqiZrKCAze1al/q3OKTvonyVXH4HSW/VxHiDpZxYb5W0bYCvCkMYMAjiHCbdK7xRhHoEtGV2CRSxUdMlZJFL6KJQL62Vrsjb4fCqfP+pHxz/IRkp0JI="
Expand Down
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,13 @@
"imports": {
"#*": "./dist/*/index.js"
},
"repository": {
"url": "https://github.com/h-projects/gasbot"
},
"keywords": [],
"author": "Aytch Software",
"license": "GPL-2.0-or-later",
"dependencies": {
"@prisma/client": "^5.16.1",
"bufferutil": "^4.0.8",
"dedent": "^1.5.3",
"discord.js": "^14.15.3",
"g-detector": "^0.1.6",
"neon-env": "^0.2.1",
"topgg-autoposter": "^2.0.2",
"yoctocolors": "^2.0.2",
"zlib-sync": "^0.1.9"
},
Expand Down
95 changes: 0 additions & 95 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/classes/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
Partials,
PresenceUpdateStatus
} from 'discord.js';
import { DJSPoster } from 'topgg-autoposter';
import { blue, bold, magenta } from 'yoctocolors';

export class Application<Ready extends boolean = boolean> extends Client<Ready> {
Expand Down Expand Up @@ -75,10 +74,6 @@ export class Application<Ready extends boolean = boolean> extends Client<Ready>

await this.login();

if (env.NODE_ENV === 'production' && process.platform === 'linux') {
new DJSPoster(env.TOPGG_TOKEN, this);
}

for (const signal of ['SIGINT', 'SIGTERM']) {
process.on(signal, () => {
logger.log(`Received ${blue(signal)}, shutting down...`);
Expand Down
3 changes: 2 additions & 1 deletion src/env/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import process from 'node:process';
import { createEnv } from 'neon-env';

export const env = createEnv({
DISCORD_TOKEN: { type: 'string' },
TOPGG_TOKEN: { type: 'string' },
TOPGG_TOKEN: { type: 'string', optional: process.env.NODE_ENV === 'production' },

GUILD_LOGS: { type: 'string' },
GLOBAL_DETECTOR_LOGS: { type: 'string' },
Expand Down
19 changes: 18 additions & 1 deletion src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import process from 'node:process';
import type { Application } from '#classes';
import { env } from '#env';
import { logger } from '#util';

export async function run(client: Application) {
export async function run(client: Application<true>) {
if (process.argv.includes('--deploy')) {
await client.deployCommands();
process.exit(0);
}

logger.log('Ready!');

if (env.NODE_ENV === 'production' && env.TOPGG_TOKEN) {
setInterval(
() =>
fetch(`https://top.gg/api/bots/${client.user.id}/stats`, {
method: 'POST',
headers: {
Authorization: env.TOPGG_TOKEN ?? '',
'Content-Type': 'application/json'
},
body: JSON.stringify({ server_count: client.guilds.cache.size })
}),
30 * 60 * 1000
);
}
}

0 comments on commit 98e279e

Please sign in to comment.