From 0ae54bbbcab42fb1c6ac00451b017e1a61d09ab6 Mon Sep 17 00:00:00 2001
From: Supositware <sup@libtar.de>
Date: Mon, 10 Oct 2022 20:18:14 +0200
Subject: [PATCH] Script to update bots.gg stats

---
 .env.example                  |  4 +++-
 scripts/updateBots.ggStats.js | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 scripts/updateBots.ggStats.js

diff --git a/.env.example b/.env.example
index e5336bc..dbe3dce 100644
--- a/.env.example
+++ b/.env.example
@@ -10,4 +10,6 @@ twiConsumerSecret=TwitterConsumerSecretToken
 twiToken=TwitterToken
 twiTokenSecret=TwitterSecretToken
 twiChannel=ChannelWhereJustTheTwitterLinkAreSent   
-twiLogChannel=ChannelWhereTheDetailedInfoOfTheCommandIsSent
\ No newline at end of file
+twiLogChannel=ChannelWhereTheDetailedInfoOfTheCommandIsSent
+botsggToken=APITokenForBots.gg
+botsggEndpoint=https://discord.bots.gg/api/v1
\ No newline at end of file
diff --git a/scripts/updateBots.ggStats.js b/scripts/updateBots.ggStats.js
new file mode 100644
index 0000000..b2455dd
--- /dev/null
+++ b/scripts/updateBots.ggStats.js
@@ -0,0 +1,30 @@
+import dotenv from 'dotenv';
+import fetch from 'node-fetch';
+import { Client, GatewayIntentBits } from 'discord.js';
+
+
+dotenv.config();
+const { botsggToken, botsggEndpoint, token } = process.env;
+
+const client = new Client({
+	intents: [GatewayIntentBits.Guilds],
+});
+await client.login(token);
+
+const body = {
+	guildCount: client.guilds.cache.size,
+};
+
+console.log(body);
+
+const response = await fetch(`${botsggEndpoint}/bots/${client.user.id}/stats`, {
+	method: 'post',
+	body: JSON.stringify(body),
+	headers: { 'Authorization': botsggToken, 'Content-Type': 'application/json' },
+});
+
+const data = await response.json();
+
+console.log(data);
+
+process.exit();
\ No newline at end of file