Skip to content

Commit

Permalink
Added total to dailies
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Jun 6, 2021
1 parent 30e3afd commit ba5c41d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 24 deletions.
6 changes: 1 addition & 5 deletions commands/newlb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ exports.newlb = async function newlb(param, game, type) {
return channel.send('<@' + message.author.id + '>\n' + `No results found for **${game}**.`);
}
let subcategories = [];
let levels = [];
let sublevels = [];

/**
Expand Down Expand Up @@ -279,10 +278,6 @@ exports.newlb = async function newlb(param, game, type) {
.setThumbnail(`https://www.speedrun.com/themes/${game}/cover-256.png`)
.setFooter(date)
for(player of playerList) {
if(player[2] == "user") {
let temp = await commands.Player.getPlayer(player[0]);
player[0] = temp.data.names.international;
}
embed.addField('#' + place + ' ' + player[0].replace(/[*_~]/g, "\\$&"), `WRs:${player[1]}`, true)
countPlayer++;
if(playerList[iterator + 1] && playerList[iterator + 1][1] != playerList[iterator][1]) {
Expand All @@ -295,6 +290,7 @@ exports.newlb = async function newlb(param, game, type) {
}
if(type == 'Channel') {
await msg.edit(embed);
return playerList;
} else {
await msg.edit('<@' + message.author.id + `>\n`, embed);
}
Expand Down
107 changes: 88 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ client.on('message', async message => {
case 'ping':
await commands.Ping.ping(client, message);
break;
case 'randomcommand':
if(message.author.id == '168420049462362112') {
grouplb(client.channels.cache.get(args[0]), args.slice(1));
} else {
message.channel.send('No permission.');
}
break;
}
} catch(err) {
message.channel.send("An unexpected error occurred.");
Expand All @@ -97,34 +104,92 @@ client.login(token).then(() => {
// Schedules the automatic daily leaderboards (Time in GMT)
cron.schedule("15 0 4 * * *", async function() {
const daily = [
['792473904391651369', 'hypixel_sb'],
['792473904391651369', 'hypixel_sbce'],
['782073727881183304', 'hypixel_ce'],
['782073727881183304', 'hypixel_bw'],
['782073727881183304', 'hypixel_sw'],
['782073727881183304', 'hypixel_ag'],
['782073727881183304', 'hypixel_cg'],
['782073727881183304', 'tkr'],
['782073727881183304', 'mcm_za'],
['782073727881183304', 'mcm_wotf'],
['782073727881183304', 'mcm_hr'],
['782073727881183304', 'mcm_sw'],
['782073727881183304', 'mcm_hm'],
['782073727881183304', 'mcm_cd']
'hypixel_sb',
'hypixel_sbce'
];
const daily2 = [
'hypixel_ce',
'hypixel_bw',
'hypixel_sw',
'hypixel_ag',
'hypixel_cg',
'tkr',
'mcm_za',
'mcm_wotf',
'mcm_hr',
'mcm_sw',
'mcm_hm',
'mcm_cd'
];
for(lb of daily) {
await dailyLB(lb[0], lb[1]);
await commands.NewLeaderboard.grouplb(client.channels.cache.get('792473904391651369'), daily);
await commands.NewLeaderboard.grouplb(client.channels.cache.get('782073727881183304'), daily2);
});

grouplb = async function grouplb(channel, games) {
let topPlayers = [];
let totalScores = [];
let scores;
for(game of games) {
await dailyLB(channel, game).then(function(data) {
scores = data;
});
if(topPlayers.indexOf(scores[0][0]) == -1) {
topPlayers.push(scores[0][0]);
}
k:
for(player of scores) {
for(score of totalScores) {
if(player[0] == score[0]) {
score[1] += player[1];
continue k;
}
}
totalScores.push(player);
}
await wait(60000);
}
});
let date = new Date().toISOString().slice(0, 10);
let embed = new MessageEmbed()
.setColor('118855')
.setTitle('Top Players for Group:')
.setFooter(date)
for(player of topPlayers) {
embed.addField(player.replace(/[*_~]/g, "\\$&"), '\u200b', true);
}
await channel.send(embed);
embed = new MessageEmbed()
.setColor('118855')
.setTitle('Top WRs for Group:')
.setFooter(date)
totalScores.sort(function(a, b) {
return b[1] - a[1];
});
let place = 1;
let iterator = 0;
let countPlayer = 0;
for(player of totalScores) {
embed.addField('#' + place + ' ' + player[0].replace(/[*_~]/g, "\\$&"), `WRs:${player[1]}`, true)
countPlayer++;
if(totalScores[iterator + 1] && totalScores[iterator + 1][1] != totalScores[iterator][1]) {
place++;
}
if(countPlayer > 30) {
break;
}
iterator++;
}
await channel.send(embed);
}

function dailyLB(channel, game) {
return new Promise((resolve) => {
queue.enqueue(async () => {
await commands.NewLeaderboard.newlb(client.channels.cache.get(channel), game, 'Channel');
resolve();
let data = await commands.NewLeaderboard.newlb(channel, game, 'Channel');
resolve(data);
});
});
}

function wait(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
Expand Down Expand Up @@ -191,3 +256,7 @@ exports.tokens = token;
exports.limit = function getLimit() {
return limiter;
}

exports.queue = function getQueue() {
return queue;
}

0 comments on commit ba5c41d

Please sign in to comment.