Skip to content

Commit

Permalink
feat: Updated formatting in various places of the PS2-Verify registra…
Browse files Browse the repository at this point in the history
…tion flow.
  • Loading branch information
Matt Cavanagh committed Sep 2, 2023
1 parent c4f1a07 commit 98c9c51
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/ps2/commands/verify.command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ describe('PS2VerifyCommand', () => {

it('should return a message if the character could not be found', async () => {
censusApiService.getCharacter = jest.fn().mockImplementation(() => {
throw new Error(`Character "${dto.character}" does not exist. Please ensure you have supplied your exact name.`);
throw new Error(`Character \`${dto.character}\` does not exist. Please ensure you have supplied your exact name.`);
});

const response = await command.onPS2VerifyCommand(dto, mockInteraction);

expect(response).toBe(`Character "${dto.character}" does not exist. Please ensure you have supplied your exact name.`);
expect(response).toBe(`Character \`${dto.character}\` does not exist. Please ensure you have supplied your exact name.`);
});

it('should correctly prevent characters outside of the outfit from registering', async () => {
Expand All @@ -175,7 +175,7 @@ describe('PS2VerifyCommand', () => {

const response = await command.onPS2VerifyCommand(dto, mockInteraction);

expect(response).toBe('Your character "Maelstrome26" has not been detected in the [DIG] outfit. If you are in the outfit, please log out and in again, or wait 24 hours and try again as Census (the game\'s API) can be slow to update sometimes.');
expect(response).toBe('Your character **Maelstrome26** has not been detected in the [DIG]. If you are in the outfit, please log out and in again, or wait 24 hours and try again as Census (the game\'s API) can be slow to update sometimes.');
});

it('should return any errors presented by the verification service', async () => {
Expand All @@ -192,7 +192,7 @@ describe('PS2VerifyCommand', () => {

const response = await command.onPS2VerifyCommand(dto, mockInteraction);

expect(response).toBe(`Your character "${dto.character}" has been detected as a member of DIG. However, to fully verify you, you now need follow the above steps.`);
expect(response).toBe(`Your character **${dto.character}** has been detected in [DIG]. However, to ensure the character belongs to you, you now need follow the below steps.`);
});

it('should correctly handle edge case character', async () => {
Expand All @@ -217,6 +217,6 @@ describe('PS2VerifyCommand', () => {

const response = await command.onPS2VerifyCommand(dto, mockInteraction);

expect(response).toBe('Your character "HARRYPOUSINI" has been detected as a member of DIG. However, to fully verify you, you now need follow the above steps.');
expect(response).toBe('Your character **HARRYPOUSINI** has been detected in [DIG]. However, to ensure the character belongs to you, you now need follow the below steps.');
});
});
4 changes: 2 additions & 2 deletions src/ps2/commands/verify.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class PS2VerifyCommand {

// Check if the character is in the PS2 Outfit
if (!character?.outfit_info || character?.outfit_info.outfit_id !== outfitId) {
return `Your character "${character.name.first}" has not been detected in the [DIG] outfit. If you are in the outfit, please log out and in again, or wait 24 hours and try again as Census (the game's API) can be slow to update sometimes.`;
return `Your character **${character.name.first}** has not been detected in the [DIG]. If you are in the outfit, please log out and in again, or wait 24 hours and try again as Census (the game's API) can be slow to update sometimes.`;
}

// Get the Discord guild member to be able to edit things about them
Expand All @@ -69,6 +69,6 @@ export class PS2VerifyCommand {
await this.ps2GameVerificationService.watch(character, guildMember);

// Successful!
return `Your character "${character.name.first}" has been detected as a member of DIG. However, to fully verify you, you now need follow the above steps.`;
return `Your character **${character.name.first}** has been detected in [DIG]. However, to ensure the character belongs to you, you now need follow the below steps.`;
}
}
2 changes: 1 addition & 1 deletion src/ps2/service/census.api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('CensusApiService', () => {

test('should throw an error if a character doesn\'t exist', async () => {
const name = 'IDoNotExist101010101010101';
await expect(service.getCharacter(name)).rejects.toThrowError(`Character **${name}** does not exist.`);
await expect(service.getCharacter(name)).rejects.toThrowError(`Character \`${name}\` does not exist. Please ensure you have spelt it correctly.`);
}, 10000);

test('should return a character, and also returns outfit details (by ID)', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/ps2/service/census.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class CensusApiService implements OnModuleInit {
const response: CensusCharacterResponseInterface = await this.requestWithRetries(url);

if (response.returned === 0 || !response.character_list || response.character_list.length === 0) {
throw new Error(`Character **${characterName}** does not exist.`);
throw new Error(`Character \`${characterName}\` does not exist. Please ensure you have spelt it correctly.`);
}

return response.character_list[0];
Expand Down
24 changes: 15 additions & 9 deletions src/ps2/service/ps2.game.verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ export class PS2GameVerificationService implements OnApplicationBootstrap {
this.monitoringCharacters.set(character.character_id, character);
this.logger.debug(`Added character ${character.name.first} to watch list`);

const message = await this.sendMessage(`Verification status for ${character.name.first}: ⏳Setting up watcher for ${character.name.first} for verification...`);
const timeMessage = await this.sendMessage(`Time remaining: ⏳**${this.calculateTimeRemaining(deadline)}**`);
const message = await this.sendMessage(`Verification status for \`${character.name.first}\`: ⏳Setting up watcher for ${character.name.first} for verification...`);
const timeMessage = await this.sendMessage(`Time remaining for \`${character.name.first}\`: **${this.calculateTimeRemaining(deadline)}**`);

// Tell the websocket service to start monitoring the character for deaths
this.censusWebsocketService.watchCharacter(character);

await this.editMessage(`## Verification status for ${character.name.first}: ⏳__Pending__\n\n⏳Deploy to a continent and to a base outside of Warpgates / Flotillas. Then type **/suicide** in the in-game chat for character "${character.name.first}". `, message);
await this.editMessage(`## Verification status for \`${character.name.first}\`: ⏳__Pending__\n
\n➡️ Deploy to a continent and to a base __outside__ of Warpgates / Flotillas. Then type **/suicide** in the in-game chat for character \`${character.name.first}\`. `, message);

// Store the messages to reference for later so we can edit the message and also reply to it etc.
this.messagesMap.set(character.character_id, message);
Expand Down Expand Up @@ -168,7 +169,7 @@ export class PS2GameVerificationService implements OnApplicationBootstrap {
const isSuicide = deathEvent.attacker_character_id === deathEvent.character_id;

if (!isSuicide) {
await this.editMessage(`## Verification status for ${character.name.first}: ⏳__Pending__\n\n⚠️ Death for character "${character.name.first}" detected, but it wasn't a suicide. Type **/suicide** in the game chat for the quickest way to do this.`, message);
await this.editMessage(`## Verification status for \`${character.name.first}\`: ⏳__Pending__\n\n⚠️ Death for character "${character.name.first}" detected, but it wasn't a suicide. Type **/suicide** in the game chat for the quickest way to do this.`, message);
return;
}

Expand All @@ -180,7 +181,7 @@ export class PS2GameVerificationService implements OnApplicationBootstrap {
this.logger.debug('Handling failed verification');
const message = this.messagesMap.get(character.character_id);
message.channel.sendTyping();
await this.editMessage(`## Verification status for ${character.name.first}: ❌ __FAILED__\n\nReason: ${failureReason}`, message);
await this.editMessage(`## Verification status for \`${character.name.first}\`: ❌ __FAILED__\n\nReason: ${failureReason}`, message);

if (isError) {
message.channel.send(failureReason);
Expand All @@ -200,7 +201,7 @@ export class PS2GameVerificationService implements OnApplicationBootstrap {
}
}

message.channel.send(`<@${guildMember.id}> your in game character "${character.name.first}" could not be verified! Please read the reason as to why above. Feel free to contact the PS2 Leaders for assistance.`);
message.channel.send(`😔 <@${guildMember.id}> your in game character "${character.name.first}" could not be verified! Please read the reason as to why above. Feel free to contact the PS2 Leaders for assistance.`);
}

private async handleSuccessfulVerification(character: CensusCharacterWithOutfitInterface) {
Expand Down Expand Up @@ -258,10 +259,13 @@ export class PS2GameVerificationService implements OnApplicationBootstrap {
await this.handleFailedVerification(character, `${errorMessage} Pinging <@${this.config.get('discord.devUserId')}>! Error: ${err.message}`, guildMember, true);
}

await this.editMessage(`## Verification status for ${character.name.first}: ✅ __Successful__`, message);
await this.editMessage(`## Verification status for \`${character.name.first}\`: ✅ __Successful__`, message);

await this.unwatch(character);
message.channel.send(`<@${guildMember.id}> your in game character "${character.name.first}" has been successfully verified! Welcome to the [DIG] outfit! 🎉 \nYou can now see our private section <#${this.config.get('discord.channels.ps2Private')}>.\nInfo on how to be promoted to Zealot to use our Armory assets, visit <#${this.config.get('discord.channels.ps2HowToRankUp')}>.`);
message.channel.send(`🎉 <@${guildMember.id}> your in game character "${character.name.first}" has been successfully verified! Welcome to the [DIG] outfit!
\n🔓 You can now see our private section <#${this.config.get('discord.channels.ps2Private')}>. Should you leave the outfit, you will automatically lose this access.
\nℹ️ Info on how to be promoted to Zealot to use our Armory assets, visit <#${this.config.get('discord.channels.ps2HowToRankUp')}>.
\n=================`);
}

private checkMonitoredCharacters() {
Expand All @@ -282,7 +286,9 @@ export class PS2GameVerificationService implements OnApplicationBootstrap {
return;
}
const timeRemaining = this.calculateTimeRemaining(deadline);
if (timeMessage) {await this.editMessage(`Time remaining: ⏳ **${timeRemaining}**`, timeMessage);}
if (timeMessage) {
await this.editMessage(`⏳ Time remaining for \`${character.name.first}\`: **${timeRemaining}**`, timeMessage);
}
this.logger.debug(`${character.name.first} still pending verification (${timeRemaining} remaining)`);
});
}
Expand Down

0 comments on commit 98c9c51

Please sign in to comment.