Skip to content

Commit

Permalink
Remove Discord discriminator, use bold score (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
taahamahdi authored Mar 7, 2022
1 parent 8ca7c7b commit 514400c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 63 deletions.
14 changes: 2 additions & 12 deletions src/commands/game_commands/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ export default class JoinCommand implements BaseCommand {
if (!teamScoreboard.hasTeam(teamName)) {
teamScoreboard.addTeam(
teamName,
new Player(
getUserTag(message.author),
message.author.id,
message.author.avatarURL,
0
)
Player.fromUserID(message.author.id)
);
const teamNameWithCleanEmojis = teamName.replace(
/(<a?)(:[a-zA-Z0-9]+:)([0-9]+>)/gm,
Expand Down Expand Up @@ -188,12 +183,7 @@ export default class JoinCommand implements BaseCommand {

teamScoreboard.addTeamPlayer(
team.id,
new Player(
getUserTag(message.author),
message.author.id,
message.author.avatarURL,
0
)
Player.fromUserID(message.author.id)
);

sendInfoMessage(MessageContext.fromMessage(message), {
Expand Down
22 changes: 12 additions & 10 deletions src/structures/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {
ExpBonusModifier,
ExpBonusModifierValues,
} from "../commands/game_commands/exp";
import { getUserTag, getMention } from "../helpers/discord_utils";
import { getMention } from "../helpers/discord_utils";
import { bold } from "../helpers/utils";
import { state } from "../kmq_worker";

export default class Player {
/** The Discord tag of the player, of the format "Player#1234" */
/** The Discord username of the player sans discriminator,
* i.e. "Player" when the player's user tag is "Player#1234"
*/
public readonly name: string;

/** The Discord user ID of the player */
Expand All @@ -32,13 +34,13 @@ export default class Player {
private previousRoundRanking: number;

constructor(
tag: string,
name: string,
id: string,
avatarURL: string,
points: number,
firstGameOfTheDay = false
) {
this.name = tag;
this.name = name;
this.id = id;
this.inVC = true;
this.score = points;
Expand All @@ -56,7 +58,7 @@ export default class Player {
const user = state.client.users.get(userID);

return new Player(
getUserTag(user),
user.username,
user.id,
user.avatarURL,
score,
Expand All @@ -65,8 +67,8 @@ export default class Player {
}

/**
* Prints the tag (including the discriminator) in the smaller scoreboard, but only
* the username in the larger scoreboard
* Formats the player's name depending on whether they won the round, if they guessed first,
* and if their name should be a Discord mention
* @param first - Whether the player won the previous round
* @param wonRound - Whether the player guessed correctly in the previous round
* @param mention - Whether the displayed name should be a clickable mention
Expand Down Expand Up @@ -105,9 +107,9 @@ export default class Player {
/** @returns what to display as the score in the scoreboard for the player */
getDisplayedScore(): string {
const rounded = Number(this.getScore().toFixed(1));
return Number.isInteger(rounded)
? rounded.toFixed()
: rounded.toFixed(1);
return bold(
Number.isInteger(rounded) ? rounded.toFixed() : rounded.toFixed(1)
);
}

/** @returns the player's EXP gain */
Expand Down
2 changes: 1 addition & 1 deletion src/structures/scoreboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default class Scoreboard {
}

/**
* @returns whether the use the scoreboard designed for more players
* @returns whether to use the scoreboard designed for more players
*/
shouldUseLargerScoreboard(): boolean {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/structures/team_scoreboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default class TeamScoreboard extends Scoreboard {
}

/**
* @returns whether the use the scoreboard designed for more players
* @returns whether to use the scoreboard designed for more players
*/
shouldUseLargerScoreboard(): boolean {
return this.getNumTeams() > SCOREBOARD_FIELD_CUTOFF;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ci/player.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Player from "../../structures/player";

let player: Player;
beforeEach(() => {
player = new Player("miyeon#7489", "12345", "someurl", 0);
player = new Player("miyeon", "12345", "someurl", 0);
});

describe("increment score", () => {
Expand Down Expand Up @@ -39,7 +39,7 @@ describe("increment EXP", () => {

describe("first game of the day", () => {
beforeEach(() => {
player = new Player("miyeon#7489", "12345", "someurl", 0, true);
player = new Player("miyeon", "12345", "someurl", 0, true);
});

describe("player's exp is incremented multiple times", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/test/ci/team.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ let subparPlayer: Player;
let firstOnLeaderboardPlayer: Player;

beforeEach(() => {
goodPlayer = new Player("ohmi#7183", "12345", "ohmipic", 0);
subparPlayer = new Player("Cool#0001", "12", "url", 0);
firstOnLeaderboardPlayer = new Player("kpop#1234", "121212", "kpop_pfp", 0);
goodPlayer = new Player("ohmi", "12345", "ohmipic", 0);
subparPlayer = new Player("Cool", "12", "url", 0);
firstOnLeaderboardPlayer = new Player("kpop", "121212", "kpop_pfp", 0);
team = new Team("kmq", goodPlayer);
});

Expand Down
53 changes: 19 additions & 34 deletions src/test/ci/team_scoreboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const SECOND_TEAM_NAME = "not kmqer";

const USER_IDS = ["12345", "23456", "252525", "1000000"];

const USER_TAG = null;
const USERNAME = null;
const AVATAR_URL = null;

let scoreboard: TeamScoreboard;
Expand All @@ -20,18 +20,13 @@ beforeEach(() => {
scoreboard = new TeamScoreboard();
firstTeam = scoreboard.addTeam(
FIRST_TEAM_NAME,
new Player("user#0101", USER_IDS[0], AVATAR_URL, 0)
new Player("user", USER_IDS[0], AVATAR_URL, 0)
);
});

describe("add a team", () => {
it("should add the team to the scoreboard", () => {
const player = new Player(
"second_user#1010",
USER_IDS[1],
AVATAR_URL,
0
);
const player = new Player("second_user", USER_IDS[1], AVATAR_URL, 0);

assert.strictEqual(scoreboard.hasTeam(SECOND_TEAM_NAME), false);
const secondTeam = scoreboard.addTeam(SECOND_TEAM_NAME, player);
Expand All @@ -55,12 +50,7 @@ describe("get team of player", () => {
);
assert.strictEqual(scoreboard.getTeamOfPlayer(USER_IDS[1]), null);

const player = new Player(
"second_user#1010",
USER_IDS[1],
AVATAR_URL,
0
);
const player = new Player("second_user", USER_IDS[1], AVATAR_URL, 0);

const secondTeam = scoreboard.addTeam(SECOND_TEAM_NAME, player);
assert.deepStrictEqual(
Expand All @@ -72,17 +62,12 @@ describe("get team of player", () => {

describe("team deletion", () => {
it("should delete a team when it has no players in it", () => {
const player = new Player(
"second_user#1010",
USER_IDS[1],
AVATAR_URL,
0
);
const player = new Player("second_user", USER_IDS[1], AVATAR_URL, 0);

const secondTeam = scoreboard.addTeam(SECOND_TEAM_NAME, player);
const anotherPlayer = new Player(USER_TAG, USER_IDS[2], AVATAR_URL, 0);
const anotherPlayer = new Player(USERNAME, USER_IDS[2], AVATAR_URL, 0);
scoreboard.addTeamPlayer(SECOND_TEAM_NAME, anotherPlayer);
const bestPlayer = new Player(USER_TAG, USER_IDS[3], AVATAR_URL, 0);
const bestPlayer = new Player(USERNAME, USER_IDS[3], AVATAR_URL, 0);
scoreboard.addTeamPlayer(FIRST_TEAM_NAME, bestPlayer);
scoreboard.removePlayer(bestPlayer.id);
scoreboard.removePlayer(player.id);
Expand Down Expand Up @@ -129,7 +114,7 @@ describe("score/exp updating", () => {
beforeEach(() => {
scoreboard.addTeamPlayer(
FIRST_TEAM_NAME,
new Player("second_user#1010", USER_IDS[1], AVATAR_URL, 0)
new Player("second_user", USER_IDS[1], AVATAR_URL, 0)
);
});

Expand Down Expand Up @@ -180,17 +165,17 @@ describe("score/exp updating", () => {
beforeEach(() => {
scoreboard.addTeamPlayer(
FIRST_TEAM_NAME,
new Player("second_user#1010", USER_IDS[1], AVATAR_URL, 0)
new Player("second_user", USER_IDS[1], AVATAR_URL, 0)
);

secondTeam = scoreboard.addTeam(
SECOND_TEAM_NAME,
new Player("jennie#2325", USER_IDS[2], AVATAR_URL, 0)
new Player("jennie", USER_IDS[2], AVATAR_URL, 0)
);

scoreboard.addTeamPlayer(
SECOND_TEAM_NAME,
new Player("g-dragon#9999", USER_IDS[3], AVATAR_URL, 0)
new Player("g-dragon", USER_IDS[3], AVATAR_URL, 0)
);
});

Expand Down Expand Up @@ -263,17 +248,17 @@ describe("score/exp updating", () => {
beforeEach(async () => {
scoreboard.addTeamPlayer(
FIRST_TEAM_NAME,
new Player("sakura#5478", USER_IDS[1], AVATAR_URL, 0)
new Player("sakura", USER_IDS[1], AVATAR_URL, 0)
);

secondTeam = scoreboard.addTeam(
SECOND_TEAM_NAME,
new Player("jennie#2325", USER_IDS[2], AVATAR_URL, 0)
new Player("jennie", USER_IDS[2], AVATAR_URL, 0)
);

scoreboard.addTeamPlayer(
SECOND_TEAM_NAME,
new Player("g-dragon#9999", USER_IDS[3], AVATAR_URL, 0)
new Player("g-dragon", USER_IDS[3], AVATAR_URL, 0)
);

await scoreboard.updateScoreboard([
Expand Down Expand Up @@ -308,17 +293,17 @@ describe("winner detection", () => {
beforeEach(() => {
scoreboard.addTeamPlayer(
FIRST_TEAM_NAME,
new Player("sakura#5478", USER_IDS[1], AVATAR_URL, 0)
new Player("sakura", USER_IDS[1], AVATAR_URL, 0)
);

secondTeam = scoreboard.addTeam(
SECOND_TEAM_NAME,
new Player("jennie#2325", USER_IDS[2], AVATAR_URL, 0)
new Player("jennie", USER_IDS[2], AVATAR_URL, 0)
);

scoreboard.addTeamPlayer(
SECOND_TEAM_NAME,
new Player("g-dragon#9999", USER_IDS[3], AVATAR_URL, 0)
new Player("g-dragon", USER_IDS[3], AVATAR_URL, 0)
);
});

Expand Down Expand Up @@ -432,12 +417,12 @@ describe("game finished", () => {
guildPreference.setGoal(5);
scoreboard.addTeam(
FIRST_TEAM_NAME,
new Player("user#0101", USER_IDS[0], AVATAR_URL, 0)
new Player("user", USER_IDS[0], AVATAR_URL, 0)
);

scoreboard.addTeam(
SECOND_TEAM_NAME,
new Player("second_user#1010", USER_IDS[1], AVATAR_URL, 0)
new Player("second_user", USER_IDS[1], AVATAR_URL, 0)
);
});

Expand Down

0 comments on commit 514400c

Please sign in to comment.