|
@@ -1,5 +1,6 @@
|
|
|
import db from './database.js';
|
|
|
import Config from './util/config.js';
|
|
|
+import {update_the_one_discord_role} from './discord_updates.js';
|
|
|
|
|
|
|
|
|
const the_ones = [];
|
|
@@ -22,7 +23,7 @@ const divisions = [
|
|
|
'The One',
|
|
|
];
|
|
|
|
|
|
-function update_the_one(user_id, elo, mode) {
|
|
|
+async function update_the_one(user_id, elo, mode) {
|
|
|
// Check that "The One" is not deranking after a loss
|
|
|
if (user_id == the_ones[mode].user_id) {
|
|
|
const the_one = db.prepare('SELECT user_id, elo FROM rating WHERE s3_scores >= ? AND mode = ? ORDER BY elo DESC LIMIT 1').get(Config.games_needed_for_rank, mode);
|
|
@@ -32,19 +33,24 @@ function update_the_one(user_id, elo, mode) {
|
|
|
elo: the_one.elo,
|
|
|
};
|
|
|
|
|
|
- // TODO: update discord role
|
|
|
+ if (the_one.user_id != user_id) {
|
|
|
+ await update_the_one_discord_role(user_id, false);
|
|
|
+ await update_the_one_discord_role(the_one.user_id, true);
|
|
|
+ }
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (elo > the_ones[mode].elo) {
|
|
|
+ const the_previous_one = the_ones[mode].user_id;
|
|
|
division_floors[mode][divisions.length - 1] = elo;
|
|
|
the_ones[mode] = {
|
|
|
user_id: user_id,
|
|
|
elo: elo,
|
|
|
};
|
|
|
|
|
|
- // TODO: update discord role
|
|
|
+ await update_the_one_discord_role(the_previous_one, false);
|
|
|
+ await update_the_one_discord_role(user_id, true);
|
|
|
}
|
|
|
}
|
|
|
|