Skip to content

Commit

Permalink
resolve workaround FINALLY
Browse files Browse the repository at this point in the history
  • Loading branch information
Glup3 committed Feb 7, 2021
1 parent 142e14f commit 5a03268
Show file tree
Hide file tree
Showing 24 changed files with 107 additions and 187 deletions.
19 changes: 17 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "valo-builder",
"version": "1.0.0",
"version": "2.2.0",
"description": "",
"main": "src/index.js",
"scripts": {
Expand All @@ -13,7 +13,7 @@
"license": "ISC",
"dependencies": {
"discord.js": "^12.5.1",
"discord.js-commando": "github:discordjs/commando#3cd5f8c",
"discord.js-commando": "^0.12.2",
"dotenv": "^8.2.0",
"node-cron": "^2.0.3",
"path": "^0.12.7",
Expand Down
14 changes: 5 additions & 9 deletions src/commands/match/addMatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Match, Team } from '../../db/models';
Expand Down Expand Up @@ -33,20 +32,16 @@ export default class AddMatchCommand extends Command {
}

async run(msg: CommandoMessage, { teamId1, teamId2 }: PromptArgs) {
const end = new Message(null, null, msg.channel);

const team1 = await Team.findOne({ where: { id: teamId1 } });

if (team1 == null) {
msg.say(`Couldn't find team 1 with ID ${teamId1}`);
return end;
return msg.say(`Couldn't find team 1 with ID ${teamId1}`);
}

const team2 = await Team.findOne({ where: { id: teamId2 } });

if (team2 == null) {
msg.say(`Couldn't find team 2 with ID ${teamId2}`);
return end;
return msg.say(`Couldn't find team 2 with ID ${teamId2}`);
}

const match = new Match({
Expand All @@ -56,7 +51,8 @@ export default class AddMatchCommand extends Command {

await match.save();

msg.say(`Successfully created Match (ID: ${match.id}) with Team1 (ID: ${team1.id}) and Team2 (ID: ${team2.id})`);
return end;
return msg.say(
`Successfully created Match (ID: ${match.id}) with Team1 (ID: ${team1.id}) and Team2 (ID: ${team2.id})`,
);
}
}
9 changes: 2 additions & 7 deletions src/commands/match/deleteMatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Match } from '../../db/models';
Expand Down Expand Up @@ -27,18 +26,14 @@ export default class DeleteMatchCommand extends Command {
}

async run(msg: CommandoMessage, { matchId }: PromptArgs) {
const end = new Message(null, null, msg.channel);

const match = await Match.findOne({ where: { id: matchId } });

if (match == null) {
msg.say(`Match with ID \`${matchId}\` is not in the database...`);
return end;
return msg.say(`Match with ID \`${matchId}\` is not in the database...`);
}

await match.destroy();

msg.say(`Match \`${matchId}\` was successfully removed from the database!`);
return end;
return msg.say(`Match \`${matchId}\` was successfully removed from the database!`);
}
}
7 changes: 2 additions & 5 deletions src/commands/match/getMatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';
import { printTeam } from '../../core/print';

Expand Down Expand Up @@ -31,8 +30,7 @@ export default class GetMatchCommand extends Command {
const match = await Match.findOne({ where: { id: matchId }, include: [{ all: true, include: [{ all: true }] }] });

if (match == null) {
msg.say(`Match with ID ${matchId} was not found!`);
return new Message(null, null, msg.channel);
return msg.say(`Match with ID ${matchId} was not found!`);
}

const hasScreenshot = match.screenshotPath != null;
Expand All @@ -45,7 +43,6 @@ export default class GetMatchCommand extends Command {

const embed = { embed: { image: { url: `${match.screenshotPath}` } } };

msg.say(message, hasScreenshot ? embed : {});
return new Message(null, null, msg.channel);
return msg.say(message, hasScreenshot ? embed : {});
}
}
14 changes: 4 additions & 10 deletions src/commands/match/storeMatchImage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Match } from '../../db/models';
Expand Down Expand Up @@ -27,24 +26,20 @@ export default class StoreImageCommand extends Command {
key: 'matchResult',
prompt: 'Who won? Team1 = 1, Team2 = 2, Draw = 0',
type: 'integer',
oneOf: [0, 1, 2],
oneOf: ['0', '1', '2'],
},
],
});
}

async run(msg: CommandoMessage, { matchId, matchResult }: PromptArgs) {
const end = new Message(null, null, msg.channel);

const match = await Match.findOne({ where: { id: matchId } });
if (match == null) {
msg.say(`Match with ID ${matchId} was not found!`);
return end;
return msg.say(`Match with ID ${matchId} was not found!`);
}

if (msg.attachments.size == 0) {
msg.say(`No attached image detected. Write command as comment when uploading image.`);
return end;
return msg.say(`No attached image detected. Write command as comment when uploading image.`);
}

const oldScreenshot = match.screenshotPath;
Expand All @@ -55,7 +50,6 @@ export default class StoreImageCommand extends Command {
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;
return msg.say(message);
}
}
11 changes: 3 additions & 8 deletions src/commands/match/updateMatchResult.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Match } from '../../db/models';
Expand Down Expand Up @@ -27,30 +26,26 @@ export default class UpdateMatchResultCommand extends Command {
key: 'matchResult',
prompt: 'Who won? Team1 = 1, Team2 = 2, Draw = 0',
type: 'integer',
oneOf: [0, 1, 2],
oneOf: ['0', '1', '2'],
},
],
});
}

async run(msg: CommandoMessage, { matchId, matchResult }: PromptArgs) {
const end = new Message(null, null, msg.channel);

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

if (match == null) {
msg.say(`Match with ID ${matchId} was not found!`);
return end;
return msg.say(`Match with ID ${matchId} was not found!`);
}

const oldMatchResult = match.getOutcome();

match.matchResult = matchResult;
match.save();

msg.say(
return msg.say(
`Match Result was changed from \`${oldMatchResult}\` to \`${match.getOutcome()}\` for Match ID ${match.id}`,
);
return end;
}
}
8 changes: 3 additions & 5 deletions src/commands/player/addPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, User } from 'discord.js';
import { User } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Player } from '../../db/models';
Expand Down Expand Up @@ -39,8 +39,7 @@ export default class AddPlayerCommand extends Command {
});

if (foundPlayer != null) {
msg.say(`Player \`${user.tag}\` was already added!`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${user.tag}\` was already added!`);
}

const player = new Player({
Expand All @@ -50,7 +49,6 @@ export default class AddPlayerCommand extends Command {
});
await player.save();

msg.say(`Player \`${player.userTag}\` has the skill level ${player.skillLevel} and was added successfully!`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${player.userTag}\` has the skill level ${player.skillLevel} and was added successfully!`);
}
}
8 changes: 3 additions & 5 deletions src/commands/player/getPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, User } from 'discord.js';
import { User } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Player } from '../../db/models';
Expand Down Expand Up @@ -32,11 +32,9 @@ export default class GetPlayerCommand extends Command {
});

if (foundPlayer == null) {
msg.say(`Player \`${user.tag}\` is not in database!`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${user.tag}\` is not in database!`);
}

msg.say(`Player \`${user.tag}\` has the skill level ${foundPlayer.skillLevel}`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${user.tag}\` has the skill level ${foundPlayer.skillLevel}`);
}
}
11 changes: 4 additions & 7 deletions src/commands/player/listMissingPlayers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GuildMember, Message } from 'discord.js';
import { GuildMember } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Player } from '../../db/models';
Expand All @@ -19,8 +19,7 @@ export default class ListPlayersCommand extends Command {
const channel = msg.member.voice.channel;

if (channel == null) {
msg.reply('You are not in a voice channel!');
return new Message(null, null, msg.channel);
return msg.reply('You are not in a voice channel!');
}

const players = await Player.findAll({
Expand All @@ -32,13 +31,11 @@ export default class ListPlayersCommand extends Command {
const missingUsers = channel.members.filter((_, k) => players.find((p) => p.userId === k) == undefined);

if (missingUsers.size === 0) {
msg.say('All Players are in the database! None is missing.');
return new Message(null, null, msg.channel);
return msg.say('All Players are in the database! None is missing.');
}

const userList = missingUsers.reduce(this.printUsers, '');
msg.say(this.printAllUsers(userList));
return new Message(null, null, msg.channel);
return msg.say(this.printAllUsers(userList));
}

printUsers(prev: string, guildUser: GuildMember): string {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/player/listPlayers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Player } from '../../db/models';
Expand Down Expand Up @@ -35,8 +34,7 @@ export default class ListPlayersCommand extends Command {
const players = await Player.findAll(options);
const playerList = players.reduce(this.printPlayers, '');

msg.say(this.printAllPlayers(playerList));
return new Message(null, null, msg.channel);
return msg.say(this.printAllPlayers(playerList));
}

printPlayers(prev: string, { userTag, skillLevel }: Player, i: number): string {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/player/listSkillLevels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

export default class AddPlayerCommand extends Command {
Expand All @@ -23,8 +22,7 @@ export default class AddPlayerCommand extends Command {
}

async run(msg: CommandoMessage) {
msg.say(this.printAllSkills());
return new Message(null, null, msg.channel);
return msg.say(this.printAllSkills());
}

printAllSkills(): string {
Expand Down
8 changes: 3 additions & 5 deletions src/commands/player/removePlayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, User } from 'discord.js';
import { User } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Player } from '../../db/models';
Expand Down Expand Up @@ -32,13 +32,11 @@ export default class RemovePlayerCommand extends Command {
});

if (player == null) {
msg.say(`Player \`${user.tag}\` is not in the database...`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${user.tag}\` is not in the database...`);
}

await player.destroy();

msg.say(`Player \`${user.tag}\` was successfully removed from the database!`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${user.tag}\` was successfully removed from the database!`);
}
}
8 changes: 3 additions & 5 deletions src/commands/player/updatePlayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, User } from 'discord.js';
import { User } from 'discord.js';
import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando';

import { Player } from '../../db/models';
Expand Down Expand Up @@ -39,14 +39,12 @@ export default class UpdatePlayerCommand extends Command {
});

if (foundPlayer == null) {
msg.say(`Player \`${user.tag}\` is not in database!`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${user.tag}\` is not in database!`);
}

foundPlayer.skillLevel = level;
foundPlayer.save();

msg.say(`Player \`${user.tag}\`' skill level has been updated to ${foundPlayer.skillLevel}!`);
return new Message(null, null, msg.channel);
return msg.say(`Player \`${user.tag}\`' skill level has been updated to ${foundPlayer.skillLevel}!`);
}
}
Loading

0 comments on commit 5a03268

Please sign in to comment.