Working fine! (but ugly)

This commit is contained in:
RoyaLProg 2022-02-17 16:32:45 +01:00
parent e19bb4f64d
commit 4340d0814d
4 changed files with 29 additions and 29 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
.vscode .vscode
node_modules
node_modules/npm/node_modules/pacote/lib/util

37
bot.js
View File

@ -1,13 +1,18 @@
const { REST } = require('@discordjs/rest'); const { Client, Intents, Util } = require('discord.js');
const { Routes } = require('discord-api-types/v9');
const { Client, Intents} = require('discord.js');
const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] }); const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] });
const https = require('https'); const https = require('https');
const GUILD = '42ctf'; const D_TOKEN = process.env.DISCORD_TOKEN;
const TOKEN = "OTQzNTA2NTgxMjkzNzc2OTQ3.Yg0C-g.XOjFinUc-Gt1gwtrSILPb0Mlspo"; const O_TOKEN = process.env.AUTH_TOKEN;
function rank(token = "test"){ async function get_guildID()
{
let Guilds = CLIENT.guilds;
let v = (await Guilds.fetch()).keyAt(0);
return v;
}
function rank(token = O_TOKEN){
var url = `https://preprod.42ctf.org/api/bot/discord?token=${token}`; var url = `https://preprod.42ctf.org/api/bot/discord?token=${token}`;
https.get(url,(res) => { https.get(url,(res) => {
let body = ""; let body = "";
@ -20,16 +25,14 @@ function rank(token = "test"){
let json = JSON.parse(body); let json = JSON.parse(body);
let v = new Map(Object.entries(json)) let v = new Map(Object.entries(json))
v.forEach(async (key, value) => { v.forEach(async (key, value) => {
console.log(key, value) let guild = CLIENT.guilds.resolve(await get_guildID());
let guild = CLIENT.guilds.fetch('943459216901955604'); let user = guild.members.fetch(value);
let user = (await guild).members.fetch(value);
let rank = parseInt(key); let rank = parseInt(key);
const roles = new Map([ const roles = new Map([
['top1', (await guild).roles.cache.get("943545814758854686")], ['top1', guild.roles.cache.get("798638767359524875")],
['top10', (await guild).roles.cache.get("943545892030517278")], ['top10', guild.roles.cache.get("801787467064672286")],
['top50', (await guild).roles.cache.get("943545946309029958")] ['top50', guild.roles.cache.get("803729539145924649")]
]); ]);
console.log((await user).user.tag);
if(rank == 1) if(rank == 1)
{ {
await (await user).roles.add(roles.get('top1')); await (await user).roles.add(roles.get('top1'));
@ -65,10 +68,4 @@ CLIENT.on('ready', () => {
console.log('started rank() interval !'); console.log('started rank() interval !');
}); });
CLIENT.on('interactionCreate', async interaction => { CLIENT.login(D_TOKEN);
if (!interaction.isCommand()) return;
});
CLIENT.login(TOKEN);

14
package-lock.json generated
View File

@ -6,7 +6,7 @@
"": { "": {
"dependencies": { "dependencies": {
"@discordjs/rest": "^0.3.0", "@discordjs/rest": "^0.3.0",
"discord-api-types": "^0.27.1", "discord-api-types": "^0.27.2",
"discord.js": "^13.6.0", "discord.js": "^13.6.0",
"npm": "^8.5.0" "npm": "^8.5.0"
} }
@ -160,9 +160,9 @@
} }
}, },
"node_modules/discord-api-types": { "node_modules/discord-api-types": {
"version": "0.27.1", "version": "0.27.2",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.27.1.tgz", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.27.2.tgz",
"integrity": "sha512-NhOrRs3TDx/p/e7+VCzcvtVz/Wkqa/olS82HJb2aM/oI0CLcnB+lJMXWa8wjn57XviFBcMMR0poqUMXx0IqTkQ==" "integrity": "sha512-70Uy283dXKpphwuVQIhQJCBAMIxLwCywdyjTKAjjrzFONZZIRQr9oupj3K1rS+hGnI6cp6y7eStRQvTbeSC+Zw=="
}, },
"node_modules/discord.js": { "node_modules/discord.js": {
"version": "13.6.0", "version": "13.6.0",
@ -2756,9 +2756,9 @@
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
}, },
"discord-api-types": { "discord-api-types": {
"version": "0.27.1", "version": "0.27.2",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.27.1.tgz", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.27.2.tgz",
"integrity": "sha512-NhOrRs3TDx/p/e7+VCzcvtVz/Wkqa/olS82HJb2aM/oI0CLcnB+lJMXWa8wjn57XviFBcMMR0poqUMXx0IqTkQ==" "integrity": "sha512-70Uy283dXKpphwuVQIhQJCBAMIxLwCywdyjTKAjjrzFONZZIRQr9oupj3K1rS+hGnI6cp6y7eStRQvTbeSC+Zw=="
}, },
"discord.js": { "discord.js": {
"version": "13.6.0", "version": "13.6.0",

View File

@ -1,7 +1,7 @@
{ {
"dependencies": { "dependencies": {
"@discordjs/rest": "^0.3.0", "@discordjs/rest": "^0.3.0",
"discord-api-types": "^0.27.1", "discord-api-types": "^0.27.2",
"discord.js": "^13.6.0", "discord.js": "^13.6.0",
"npm": "^8.5.0" "npm": "^8.5.0"
} }