Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
Camille CAMBIUM | 9a03802bb2 | |
Camille CAMBIUM | a341a33f85 | |
Camille CAMBIUM | 78a8c5b834 | |
Camille CAMBIUM | 99206049b4 |
57
src/bot.js
57
src/bot.js
|
@ -1,9 +1,20 @@
|
|||
const { Client, Intents } = require('discord.js');
|
||||
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 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=${O_TOKEN}`;
|
||||
|
||||
const D_TOKEN = process.env.DISCORD_TOKEN;
|
||||
const O_TOKEN = process.env.AUTH_TOKEN;
|
||||
|
||||
async function get_guildID()
|
||||
{
|
||||
|
@ -15,7 +26,6 @@ async function get_guildID()
|
|||
async function remove_notlogged(){
|
||||
let guild = CLIENT.guilds.resolve(await get_guildID());
|
||||
let token = O_TOKEN;
|
||||
let url = `https://www.42ctf.local/api/bot/discord?token=${token}`;
|
||||
|
||||
await (guild.members.fetch()).then(() => {
|
||||
console.log("Cache reloaded !");
|
||||
|
@ -27,15 +37,7 @@ async function remove_notlogged(){
|
|||
['top50', guild.roles.cache.get("803729539145924649")]
|
||||
]);
|
||||
|
||||
const options = {
|
||||
path: '/',
|
||||
method: 'GET',
|
||||
rejectUnauthorized: false,
|
||||
requestCert: true,
|
||||
agent: false
|
||||
};
|
||||
|
||||
https.get(url, options, (res) => {
|
||||
https.get(url, (res) => {
|
||||
let body = "";
|
||||
|
||||
res.on("data", (chunk) => {
|
||||
|
@ -73,7 +75,6 @@ async function remove_notlogged(){
|
|||
}
|
||||
|
||||
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());
|
||||
|
||||
const rolesCollection = new Map([
|
||||
|
@ -82,15 +83,7 @@ async function rank(token = O_TOKEN){
|
|||
['top50', guild.roles.cache.get("803729539145924649")]
|
||||
]);
|
||||
|
||||
const options = {
|
||||
path: '/',
|
||||
method: 'GET',
|
||||
rejectUnauthorized: false,
|
||||
requestCert: true,
|
||||
agent: false
|
||||
};
|
||||
|
||||
https.get(url,options,(res) => {
|
||||
https.get(url, (res) => {
|
||||
var body = "";
|
||||
|
||||
res.on("data", (chunk) => {
|
||||
|
@ -137,11 +130,25 @@ async function rank(token = O_TOKEN){
|
|||
});
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
async function routine() {
|
||||
while (1) {
|
||||
rank();
|
||||
remove_notlogged();
|
||||
await sleep(900000)
|
||||
// await sleep(1000 * 120)
|
||||
}
|
||||
}
|
||||
|
||||
CLIENT.on('ready', () => {
|
||||
console.log(`Logged in as ${CLIENT.user.tag}!`);
|
||||
setInterval(rank, 900000);
|
||||
setInterval(remove_notlogged, 900000);
|
||||
console.log('started rank() interval !');
|
||||
routine();
|
||||
});
|
||||
|
||||
CLIENT.login(D_TOKEN);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "test",
|
||||
"name": "src",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
|
@ -15,6 +15,7 @@
|
|||
"version": "0.13.0",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz",
|
||||
"integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==",
|
||||
"deprecated": "no longer supported",
|
||||
"dependencies": {
|
||||
"@sapphire/shapeshift": "^2.0.0",
|
||||
"@sindresorhus/is": "^4.6.0",
|
||||
|
@ -36,6 +37,7 @@
|
|||
"version": "0.7.0-dev.1653480253-68d5169",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0-dev.1653480253-68d5169.tgz",
|
||||
"integrity": "sha512-s8z+4G82yrIbS0OxqVyitkS72mvE6lxYW8zjsKfpqPAIG6fKQ9n41c9HEsCG1VlWNeQ6F23fKf2hT3bGIdRGsQ==",
|
||||
"deprecated": "no longer supported",
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
}
|
||||
|
@ -44,6 +46,7 @@
|
|||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-0.4.1.tgz",
|
||||
"integrity": "sha512-rtWy+AIfNlfjGkAgA2TJLASdqli07aTNQceVGT6RQQiQaEqV0nsfBO4WtDlDzk7PmO3w+InP3dpwEolJI5jz0A==",
|
||||
"deprecated": "no longer supported",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "^0.7.0-dev",
|
||||
"@sapphire/async-queue": "^1.3.1",
|
||||
|
@ -169,6 +172,7 @@
|
|||
"version": "13.7.0",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.7.0.tgz",
|
||||
"integrity": "sha512-iV/An3FEB/CiBGdjWHRtgskM4UuWPq5vjhjKsrQhdVU16dbKrBxA+eIV2HWA07B3tXUGM6eco1wkr42gxxV1BA==",
|
||||
"deprecated": "Hard crashes on interactions with a channel in the payload, use 13.14.0 and up",
|
||||
"dependencies": {
|
||||
"@discordjs/builders": "^0.13.0",
|
||||
"@discordjs/collection": "^0.6.0",
|
||||
|
@ -189,6 +193,7 @@
|
|||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.6.0.tgz",
|
||||
"integrity": "sha512-Ieaetb36l0nmAS5X9Upqk4W7euAO6FdXPxn3I8vBAKEcoIzEZI1mcVcPfCfagGJZSgBKpENnAnKkP4GAn+MV8w==",
|
||||
"deprecated": "no longer supported",
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue