making hot-fix change (very late yeah) to js bot (hope it works better)

This commit is contained in:
Camille CAMBIUM 2023-05-06 03:44:20 +02:00
parent 99206049b4
commit 78a8c5b834
2 changed files with 24 additions and 25 deletions

View File

@ -1,9 +1,20 @@
const { Client, Intents } = require('discord.js'); const { Client, Intents } = require('discord.js');
const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] }); const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] });
const https = require('https'); let https;
try {
https = require('node:https');
} catch (err) {
console.error('https support is disabled!');
}
// const D_TOKEN = process.env.DISCORD_TOKEN;
// const O_TOKEN = process.env.AUTH_TOKEN;
const D_TOKEN = process.env.DISCORD_TOKEN; const D_TOKEN = process.env.DISCORD_TOKEN;
const O_TOKEN = process.env.AUTH_TOKEN; const O_TOKEN = process.env.AUTH_TOKEN;
// const url = `https://preprod.42ctf.org/api/bot/discord?token=${O_TOKEN}`;
const url = `https://www.42ctf.local/api/bot/discord?token=${token}`;
async function get_guildID() async function get_guildID()
{ {
@ -15,7 +26,6 @@ async function get_guildID()
async function remove_notlogged(){ async function remove_notlogged(){
let guild = CLIENT.guilds.resolve(await get_guildID()); let guild = CLIENT.guilds.resolve(await get_guildID());
let token = O_TOKEN; let token = O_TOKEN;
let url = `https://www.42ctf.local/api/bot/discord?token=${token}`;
await (guild.members.fetch()).then(() => { await (guild.members.fetch()).then(() => {
console.log("Cache reloaded !"); console.log("Cache reloaded !");
@ -27,15 +37,7 @@ async function remove_notlogged(){
['top50', guild.roles.cache.get("803729539145924649")] ['top50', guild.roles.cache.get("803729539145924649")]
]); ]);
const options = { https.get(url, (res) => {
path: '/',
method: 'GET',
rejectUnauthorized: false,
requestCert: true,
agent: false
};
https.get(url, options, (res) => {
let body = ""; let body = "";
res.on("data", (chunk) => { res.on("data", (chunk) => {
@ -73,7 +75,6 @@ async function remove_notlogged(){
} }
async function rank(token = O_TOKEN){ async function rank(token = O_TOKEN){
let url = `https://www.42ctf.local/api/bot/discord?token=${token}`;
let guild = CLIENT.guilds.resolve(await get_guildID()); let guild = CLIENT.guilds.resolve(await get_guildID());
const rolesCollection = new Map([ const rolesCollection = new Map([
@ -82,15 +83,7 @@ async function rank(token = O_TOKEN){
['top50', guild.roles.cache.get("803729539145924649")] ['top50', guild.roles.cache.get("803729539145924649")]
]); ]);
const options = { https.get(url, (res) => {
path: '/',
method: 'GET',
rejectUnauthorized: false,
requestCert: true,
agent: false
};
https.get(url,options,(res) => {
var body = ""; var body = "";
res.on("data", (chunk) => { res.on("data", (chunk) => {
@ -147,7 +140,8 @@ async function routine() {
while (1) { while (1) {
rank(); rank();
remove_notlogged(); remove_notlogged();
await sleep(900000) // await sleep(900000)
await sleep(1000 * 120)
} }
} }

7
src/package-lock.json generated
View File

@ -1,5 +1,5 @@
{ {
"name": "test", "name": "src",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
@ -15,6 +15,7 @@
"version": "0.13.0", "version": "0.13.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz",
"integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==", "integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==",
"deprecated": "no longer supported",
"dependencies": { "dependencies": {
"@sapphire/shapeshift": "^2.0.0", "@sapphire/shapeshift": "^2.0.0",
"@sindresorhus/is": "^4.6.0", "@sindresorhus/is": "^4.6.0",
@ -36,6 +37,7 @@
"version": "0.7.0-dev.1653480253-68d5169", "version": "0.7.0-dev.1653480253-68d5169",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0-dev.1653480253-68d5169.tgz", "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0-dev.1653480253-68d5169.tgz",
"integrity": "sha512-s8z+4G82yrIbS0OxqVyitkS72mvE6lxYW8zjsKfpqPAIG6fKQ9n41c9HEsCG1VlWNeQ6F23fKf2hT3bGIdRGsQ==", "integrity": "sha512-s8z+4G82yrIbS0OxqVyitkS72mvE6lxYW8zjsKfpqPAIG6fKQ9n41c9HEsCG1VlWNeQ6F23fKf2hT3bGIdRGsQ==",
"deprecated": "no longer supported",
"engines": { "engines": {
"node": ">=16.9.0" "node": ">=16.9.0"
} }
@ -44,6 +46,7 @@
"version": "0.4.1", "version": "0.4.1",
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-0.4.1.tgz", "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-0.4.1.tgz",
"integrity": "sha512-rtWy+AIfNlfjGkAgA2TJLASdqli07aTNQceVGT6RQQiQaEqV0nsfBO4WtDlDzk7PmO3w+InP3dpwEolJI5jz0A==", "integrity": "sha512-rtWy+AIfNlfjGkAgA2TJLASdqli07aTNQceVGT6RQQiQaEqV0nsfBO4WtDlDzk7PmO3w+InP3dpwEolJI5jz0A==",
"deprecated": "no longer supported",
"dependencies": { "dependencies": {
"@discordjs/collection": "^0.7.0-dev", "@discordjs/collection": "^0.7.0-dev",
"@sapphire/async-queue": "^1.3.1", "@sapphire/async-queue": "^1.3.1",
@ -169,6 +172,7 @@
"version": "13.7.0", "version": "13.7.0",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.7.0.tgz", "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.7.0.tgz",
"integrity": "sha512-iV/An3FEB/CiBGdjWHRtgskM4UuWPq5vjhjKsrQhdVU16dbKrBxA+eIV2HWA07B3tXUGM6eco1wkr42gxxV1BA==", "integrity": "sha512-iV/An3FEB/CiBGdjWHRtgskM4UuWPq5vjhjKsrQhdVU16dbKrBxA+eIV2HWA07B3tXUGM6eco1wkr42gxxV1BA==",
"deprecated": "Hard crashes on interactions with a channel in the payload, use 13.14.0 and up",
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.13.0", "@discordjs/builders": "^0.13.0",
"@discordjs/collection": "^0.6.0", "@discordjs/collection": "^0.6.0",
@ -189,6 +193,7 @@
"version": "0.6.0", "version": "0.6.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.6.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.6.0.tgz",
"integrity": "sha512-Ieaetb36l0nmAS5X9Upqk4W7euAO6FdXPxn3I8vBAKEcoIzEZI1mcVcPfCfagGJZSgBKpENnAnKkP4GAn+MV8w==", "integrity": "sha512-Ieaetb36l0nmAS5X9Upqk4W7euAO6FdXPxn3I8vBAKEcoIzEZI1mcVcPfCfagGJZSgBKpENnAnKkP4GAn+MV8w==",
"deprecated": "no longer supported",
"engines": { "engines": {
"node": ">=16.9.0" "node": ">=16.9.0"
} }