Browse Source

Add cross-server leaderboard

Give the people what they want, eh?
pull/4/head
Abheek Dhawan 4 years ago
parent
commit
e23acc4994
  1. 1
      .gitignore
  2. 22
      bot/awesomescibo.mjs
  3. 2
      bot/package.json

1
.gitignore

@ -4,3 +4,4 @@ node_modules
round.html round.html
round.md round.md
round.pdf round.pdf
bot/README.md

22
bot/awesomescibo.mjs

@ -5,6 +5,7 @@ import { execSync } from 'child_process';
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] }); const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path';
var hits = 0; var hits = 0;
@ -30,7 +31,6 @@ client.on('guildCreate', guild => {
}); });
client.on('message', async message => { client.on('message', async message => {
if (message.content.startsWith("do be announcing") && message.author.id === process.argv[3]) { if (message.content.startsWith("do be announcing") && message.author.id === process.argv[3]) {
var announcement = message.content.substring(17); var announcement = message.content.substring(17);
client.guilds.cache.forEach((guild) => { client.guilds.cache.forEach((guild) => {
@ -406,6 +406,26 @@ client.on('message', async message => {
}) })
} }
} }
if (message.content.toLowerCase() === "do be top") {
let messageContent = '';
let scores = [];
const directoryPath = path.join('userScore');
fs.readdir(directoryPath, function (err, files) {
if (err) {
return console.log('Unable to scan directory: ' + err);
}
files.forEach(function (file) {
scores.push(`${fs.readFileSync('userScore/' + file, 'utf8')}|<@${file}>`)
});
var scoresFormatted = scores.sort(function(a, b){return b.split('|')[0] - a.split('|')[0]});
for (var i = 0; i < 10; i++) {
var currentScore = scoresFormatted[i].split('|');
messageContent += `${currentScore[1]}: ${currentScore[0]}\n\n`;
}
message.channel.send(new Discord.MessageEmbed().setTitle('Top Ten!').setDescription(messageContent));
});
}
}); });
client.login(process.argv[2]).catch(error => console.log(error)); client.login(process.argv[2]).catch(error => console.log(error));

2
bot/package.json

@ -5,7 +5,7 @@
"node-fetch": "^2.6.1" "node-fetch": "^2.6.1"
}, },
"name": "awscibo", "name": "awscibo",
"version": "0.3.4", "version": "0.4.0",
"main": "awesomescibo.mjs", "main": "awesomescibo.mjs",
"bin": { "bin": {
"awscibo": "./awesomescibo.mjs" "awscibo": "./awesomescibo.mjs"

Loading…
Cancel
Save