Skip to content

Commit

Permalink
format messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Glup3 committed Jan 21, 2021
1 parent b2479fd commit e2aae8f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/commands/match/getMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export default class GetMatchCommand extends Command {

const hasScreenshot = match.screenshotPath != null;

let message = `Match ${match.id} - ${match.getOutcome()}${!hasScreenshot ? ` (no screenshot provided)` : ''}\n`;
let message = `\`Team ${match.team1.teamName}\` vs \`Team ${match.team2.teamName}\`\n`;
message += `${match.getOutcome()} | Match ID: ${matchId} `;
message += !hasScreenshot ? `(no screenshot provided)\n` : '\n';
message += printTeam(match.team1);
message += printTeam(match.team2);

Expand Down
8 changes: 5 additions & 3 deletions src/commands/match/storeMatchImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export default class StoreImageCommand extends Command {
return end;
}

const oldScreenshot = match.screenshotPath;
match.matchResult = matchResult;
match.screenshotPath = msg.attachments.first().url;
match.save();

msg.say(
`Added \`${match.screenshotPath}\` to Match with ID \`${match.id}\`, and set result as\`${match.matchResult}\``,
);
let message = `Changed Screenshot from ${oldScreenshot} to ${match.screenshotPath}\n`;
message += `for Match ID ${match.id} and set result to ${matchResult}`;

msg.say(message);
return end;
}
}
2 changes: 1 addition & 1 deletion src/commands/match/updateMatchResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class UpdateMatchResultCommand extends Command {
async run(msg: CommandoMessage, { matchId, matchResult }: PromptArgs) {
const end = new Message(null, null, msg.channel);

const match = await Match.findOne({ where: { id: matchId } });
const match = await Match.findOne({ where: { id: matchId }, include: [{ all: true }] });

if (match == null) {
msg.say(`Match with ID ${matchId} was not found!`);
Expand Down
9 changes: 8 additions & 1 deletion src/core/print.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Team } from '../db/models';

export function printTeam(team: Team): string {
const skillTotal =
team.player1.skillLevel +
team.player2.skillLevel +
team.player3.skillLevel +
team.player4.skillLevel +
team.player5.skillLevel;

let res = '```\n';
res += `Team ${team.teamName} (ID: ${team.id})`;
res += `Team ${team.teamName} (Total Skill: ${skillTotal} | ID: ${team.id})`;
res += `\n\tLevel ${team.player1.skillLevel}\t${team.player1.userTag}`;
res += `\n\tLevel ${team.player2.skillLevel}\t${team.player2.userTag}`;
res += `\n\tLevel ${team.player3.skillLevel}\t${team.player3.userTag}`;
Expand Down
4 changes: 2 additions & 2 deletions src/db/models/Match.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export default class Match extends Model {

getOutcome(): string {
if (this.matchResult == 1) {
return 'Team 1 won';
return `Team ${this.team1.teamName} won`;
} else if (this.matchResult == 2) {
return 'Team 2 won';
return `Team ${this.team2.teamName} won`;
}

return 'Draw';
Expand Down

0 comments on commit e2aae8f

Please sign in to comment.