rage quit

This commit is contained in:
RoyaLProg 2022-02-18 12:25:28 +01:00
parent 4340d0814d
commit 283fbf76ec
1 changed files with 30 additions and 22 deletions

52
bot.js
View File

@ -1,4 +1,4 @@
const { Client, Intents, Util } = require('discord.js');
const { Client, Intents } = require('discord.js');
const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] });
const https = require('https');
@ -12,47 +12,54 @@ async function get_guildID()
return v;
}
function rank(token = O_TOKEN){
var url = `https://preprod.42ctf.org/api/bot/discord?token=${token}`;
async function rank(token = O_TOKEN){
let url = `https://preprod.42ctf.org/api/bot/discord?token=${token}`;
let guild = CLIENT.guilds.resolve(await get_guildID());
const rolesCollection = new Map([
['top1', guild.roles.cache.get("943545814758854686")],
['top10', guild.roles.cache.get("943545892030517278")],
['top50', guild.roles.cache.get("943545946309029958")]
]);
https.get(url,(res) => {
let body = "";
var body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
let json = JSON.parse(body);
var json = JSON.parse(body);
let v = new Map(Object.entries(json))
v.forEach(async (key, value) => {
let guild = CLIENT.guilds.resolve(await get_guildID());
let user = guild.members.fetch(value);
let rank = parseInt(key);
const roles = new Map([
['top1', guild.roles.cache.get("798638767359524875")],
['top10', guild.roles.cache.get("801787467064672286")],
['top50', guild.roles.cache.get("803729539145924649")]
]);
if(rank == 1)
{
await (await user).roles.add(roles.get('top1'));
await (await user).roles.remove(roles.get('top10'));
await (await user).roles.remove(roles.get('top50'));
await (await user).roles.add(rolesCollection.get('top1'));
await (await user).roles.remove(rolesCollection.get('top10'));
await (await user).roles.remove(rolesCollection.get('top50'));
}
else if(rank <= 10)
{
await (await user).roles.remove(roles.get('top1'));
await (await user).roles.add(roles.get('top10'));
await (await user).roles.remove(roles.get('top50'));
await (await user).roles.remove(rolesCollection.get('top1'));
await (await user).roles.add(rolesCollection.get('top10'));
await (await user).roles.remove(rolesCollection.get('top50'));
}
else if(rank <= 50)
{
await (await user).roles.remove(roles.get('top1'));
await (await user).roles.remove(roles.get('top10'));
await (await user).roles.add(roles.get('top50'));
await (await user).roles.remove(rolesCollection.get('top1'));
await (await user).roles.remove(rolesCollection.get('top10'));
await (await user).roles.add(rolesCollection.get('top50'));
}
else
{
await (await user).roles.remove(rolesCollection.get('top1'));
await (await user).roles.remove(rolesCollection.get('top10'));
await (await user).roles.remove(rolesCollection.get('top50'));
}
})
console.log("done");
} catch (error) {
console.error(error.message);
};
@ -64,7 +71,8 @@ function rank(token = O_TOKEN){
CLIENT.on('ready', () => {
console.log(`Logged in as ${CLIENT.user.tag}!`);
setInterval(rank, 900000);
setInterval(rank, 5000);
setInterval(remove_notlogged, 5000);
console.log('started rank() interval !');
});