From e23acc4994f5d2267c43810ce9d4b2ec6e28a866 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 3 Mar 2021 00:07:01 -0600 Subject: [PATCH] Add cross-server leaderboard Give the people what they want, eh? --- .gitignore | 1 + bot/awesomescibo.mjs | 22 +++++++++++++++++++++- bot/package.json | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ae68fa6..129c10f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules round.html round.md round.pdf +bot/README.md diff --git a/bot/awesomescibo.mjs b/bot/awesomescibo.mjs index 5da2e18..875d3a3 100755 --- a/bot/awesomescibo.mjs +++ b/bot/awesomescibo.mjs @@ -5,6 +5,7 @@ import { execSync } from 'child_process'; const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] }); import fetch from 'node-fetch'; import * as fs from 'fs'; +import * as path from 'path'; var hits = 0; @@ -30,7 +31,6 @@ client.on('guildCreate', guild => { }); client.on('message', async message => { - if (message.content.startsWith("do be announcing") && message.author.id === process.argv[3]) { var announcement = message.content.substring(17); 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)); diff --git a/bot/package.json b/bot/package.json index 16e50f5..f1e4bc1 100644 --- a/bot/package.json +++ b/bot/package.json @@ -5,7 +5,7 @@ "node-fetch": "^2.6.1" }, "name": "awscibo", - "version": "0.3.4", + "version": "0.4.0", "main": "awesomescibo.mjs", "bin": { "awscibo": "./awesomescibo.mjs"