From 5a03268a4c673b6de76ade03b960005c52be08ec Mon Sep 17 00:00:00 2001 From: Phuc Tran Date: Sun, 7 Feb 2021 21:46:15 +0100 Subject: [PATCH] resolve workaround FINALLY --- package-lock.json | 19 +++++++- package.json | 4 +- src/commands/match/addMatch.ts | 14 +++--- src/commands/match/deleteMatch.ts | 9 +--- src/commands/match/getMatch.ts | 7 +-- src/commands/match/storeMatchImage.ts | 14 ++---- src/commands/match/updateMatchResult.ts | 11 ++--- src/commands/player/addPlayer.ts | 8 ++-- src/commands/player/getPlayer.ts | 8 ++-- src/commands/player/listMissingPlayers.ts | 11 ++--- src/commands/player/listPlayers.ts | 4 +- src/commands/player/listSkillLevels.ts | 4 +- src/commands/player/removePlayer.ts | 8 ++-- src/commands/player/updatePlayer.ts | 8 ++-- src/commands/team/addTeam.ts | 11 +++-- src/commands/team/buildTeams.ts | 53 +++++++---------------- src/commands/team/changeTeamPlayer.ts | 22 +++------- src/commands/team/deleteTeam.ts | 9 +--- src/commands/team/getTeam.ts | 7 +-- src/commands/team/listRecentTeams.ts | 8 +--- src/commands/team/numberPicking.ts | 37 +++++----------- src/commands/team/updateTeamName copy.ts | 11 +---- src/constants.ts | 2 + src/core/status.ts | 5 ++- 24 files changed, 107 insertions(+), 187 deletions(-) diff --git a/package-lock.json b/package-lock.json index f36b6b0..2aeaa61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1035,11 +1035,21 @@ } }, "discord.js-commando": { - "version": "github:discordjs/commando#3cd5f8c763f0d644432eeba59f831eb942de7bd4", - "from": "github:discordjs/commando#3cd5f8c", + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/discord.js-commando/-/discord.js-commando-0.12.2.tgz", + "integrity": "sha512-3C3VpVVi/GJDImhQ9TKJhhHdK00XVzqbX722Zti6LEs5oA1zydjH89+tgIUkSF7bvaLpZKOfFy0MIeNWv+uL9g==", "requires": { "common-tags": "^1.8.0", + "emoji-regex": "^9.2.0", + "is-promise": "^4.0.0", "require-all": "^3.0.0" + }, + "dependencies": { + "emoji-regex": { + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.1.tgz", + "integrity": "sha512-117l1H6U4X3Krn+MrzYrL57d5H7siRHWraBs7s+LjRuFK7Fe7hJqnJ0skWlinqsycVLU5YAo6L8CsEYQ0V5prg==" + } } }, "doctrine": { @@ -1824,6 +1834,11 @@ "integrity": "sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg==", "dev": true }, + "is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==" + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", diff --git a/package.json b/package.json index eacad64..06e536e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "valo-builder", - "version": "1.0.0", + "version": "2.2.0", "description": "", "main": "src/index.js", "scripts": { @@ -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", diff --git a/src/commands/match/addMatch.ts b/src/commands/match/addMatch.ts index 688f569..1b2a264 100644 --- a/src/commands/match/addMatch.ts +++ b/src/commands/match/addMatch.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Match, Team } from '../../db/models'; @@ -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({ @@ -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})`, + ); } } diff --git a/src/commands/match/deleteMatch.ts b/src/commands/match/deleteMatch.ts index 77d71e8..91db899 100644 --- a/src/commands/match/deleteMatch.ts +++ b/src/commands/match/deleteMatch.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Match } from '../../db/models'; @@ -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!`); } } diff --git a/src/commands/match/getMatch.ts b/src/commands/match/getMatch.ts index e8b89a4..eb28672 100644 --- a/src/commands/match/getMatch.ts +++ b/src/commands/match/getMatch.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { printTeam } from '../../core/print'; @@ -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; @@ -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 : {}); } } diff --git a/src/commands/match/storeMatchImage.ts b/src/commands/match/storeMatchImage.ts index 6eecf93..db42a6e 100644 --- a/src/commands/match/storeMatchImage.ts +++ b/src/commands/match/storeMatchImage.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Match } from '../../db/models'; @@ -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; @@ -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); } } diff --git a/src/commands/match/updateMatchResult.ts b/src/commands/match/updateMatchResult.ts index c57ae23..ff8d9f5 100644 --- a/src/commands/match/updateMatchResult.ts +++ b/src/commands/match/updateMatchResult.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Match } from '../../db/models'; @@ -27,20 +26,17 @@ 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(); @@ -48,9 +44,8 @@ export default class UpdateMatchResultCommand extends Command { 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; } } diff --git a/src/commands/player/addPlayer.ts b/src/commands/player/addPlayer.ts index af9fb49..f5cd63b 100644 --- a/src/commands/player/addPlayer.ts +++ b/src/commands/player/addPlayer.ts @@ -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'; @@ -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({ @@ -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!`); } } diff --git a/src/commands/player/getPlayer.ts b/src/commands/player/getPlayer.ts index 249bc91..cbb23b4 100644 --- a/src/commands/player/getPlayer.ts +++ b/src/commands/player/getPlayer.ts @@ -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'; @@ -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}`); } } diff --git a/src/commands/player/listMissingPlayers.ts b/src/commands/player/listMissingPlayers.ts index 6c9d1ab..eb81a50 100644 --- a/src/commands/player/listMissingPlayers.ts +++ b/src/commands/player/listMissingPlayers.ts @@ -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'; @@ -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({ @@ -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 { diff --git a/src/commands/player/listPlayers.ts b/src/commands/player/listPlayers.ts index f6175c7..85ffe0e 100644 --- a/src/commands/player/listPlayers.ts +++ b/src/commands/player/listPlayers.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Player } from '../../db/models'; @@ -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 { diff --git a/src/commands/player/listSkillLevels.ts b/src/commands/player/listSkillLevels.ts index 346dcad..f1bd07f 100644 --- a/src/commands/player/listSkillLevels.ts +++ b/src/commands/player/listSkillLevels.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; export default class AddPlayerCommand extends Command { @@ -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 { diff --git a/src/commands/player/removePlayer.ts b/src/commands/player/removePlayer.ts index 3207f56..7ea3fff 100644 --- a/src/commands/player/removePlayer.ts +++ b/src/commands/player/removePlayer.ts @@ -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'; @@ -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!`); } } diff --git a/src/commands/player/updatePlayer.ts b/src/commands/player/updatePlayer.ts index fa21d19..38834fe 100644 --- a/src/commands/player/updatePlayer.ts +++ b/src/commands/player/updatePlayer.ts @@ -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'; @@ -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}!`); } } diff --git a/src/commands/team/addTeam.ts b/src/commands/team/addTeam.ts index 91d7ab3..d093bdd 100644 --- a/src/commands/team/addTeam.ts +++ b/src/commands/team/addTeam.ts @@ -1,4 +1,4 @@ -import { Message, User } from 'discord.js'; +import { User } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { neededUsers } from '../../constants'; @@ -58,7 +58,6 @@ export default class AddTeamCommand extends Command { } async run(msg: CommandoMessage, { teamName, user1, user2, user3, user4, user5 }: PromptArgs) { - const end = new Message(null, null, msg.channel); const neededPlayers = Math.ceil(neededUsers / 2); const userIds = [user1.id, user2.id, user3.id, user4.id, user5.id]; const foundPlayers = await Player.findAll({ @@ -66,8 +65,9 @@ export default class AddTeamCommand extends Command { }); if (foundPlayers.length < neededPlayers) { - msg.say(`Some of your players need to be in the database first! Amount: ${neededPlayers - foundPlayers.length}`); - return end; + return msg.say( + `Some of your players need to be in the database first! Amount: ${neededPlayers - foundPlayers.length}`, + ); } const now = Date.now(); @@ -124,9 +124,8 @@ export default class AddTeamCommand extends Command { await team.save(); - msg.say( + return msg.say( `Successfully created team ${team.teamName} (ID: ${team.id}) with \`${user1.tag}\`, \`${user2.tag}\`, \`${user3.tag}\`, \`${user4.tag}\` & \`${user5.tag}\` `, ); - return end; } } diff --git a/src/commands/team/buildTeams.ts b/src/commands/team/buildTeams.ts index ab0765f..6ff2a54 100644 --- a/src/commands/team/buildTeams.ts +++ b/src/commands/team/buildTeams.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Player } from '../../db/models'; import { shuffle } from '../../util/arrayHelper'; @@ -16,7 +15,6 @@ export default class buildTeamsCommand extends Command { } async run(msg: CommandoMessage, rawArgs: string) { - const end = new Message(null, null, msg.channel); const tries = 10; let userIds: string[]; const channel = msg.member.voice.channel; @@ -26,72 +24,54 @@ export default class buildTeamsCommand extends Command { if (rawArgs.trim() === '') { if (channel == null) { - msg.reply('You are not in a voice channel!'); - return end; + return msg.reply('You are not in a voice channel!'); } if (channel.members.size < neededUsers) { - msg.say('There are not enough players in the voice channel.'); - return end; + return msg.say('There are not enough players in the voice channel.'); } else if (channel.members.size > neededUsers) { - msg.say('There are too many players in the voice channel. Can not choose players.'); - return end; + return msg.say('There are too many players in the voice channel. Can not choose players.'); } userIds = channel.members.map((_, k) => k); - await this.buildTeams(msg, userIds, neededUsers, tries, isRandom); - return end; + return await this.buildTeams(msg, userIds, neededUsers, tries, isRandom); } if (channel == null && msg.mentions.users.size == 0) { - msg.reply('You are not in a voice channel and forgot to mention enough players.'); - return end; + return msg.reply('You are not in a voice channel and forgot to mention enough players.'); } if (msg.mentions.users.size == 0) { - msg.say('You forgot to choose the remaining players.'); - return end; + return msg.say('You forgot to choose the remaining players.'); } if (msg.mentions.users.size == neededUsers) { userIds = msg.mentions.users.map((_, k) => k); - await this.buildTeams(msg, userIds, neededUsers, tries, isRandom); - return end; + return await this.buildTeams(msg, userIds, neededUsers, tries, isRandom); } if (channel == null) { - msg.reply('You are not in a voice channel.'); - return end; + return msg.reply('You are not in a voice channel.'); } userIds = channel.members.map((_, k) => k).concat(msg.mentions.users.map((_, k) => k)); if (userIds.length < neededUsers) { - msg.reply(`You didn't mention enough players. ${neededUsers - userIds.length} players are missing.`); - return end; + return msg.reply(`You didn't mention enough players. ${neededUsers - userIds.length} players are missing.`); } else if (userIds.length > neededUsers) { - msg.reply(`You mentioned too many players. You need ${neededUsers} players, not ${userIds.length}`); - return end; + return msg.reply(`You mentioned too many players. You need ${neededUsers} players, not ${userIds.length}`); } - await this.buildTeams(msg, userIds, neededUsers, tries, isRandom); - return end; + return await this.buildTeams(msg, userIds, neededUsers, tries, isRandom); } - async buildTeams( - msg: CommandoMessage, - userIds: string[], - playerCount: number, - tries: number, - isRandom: boolean, - ): Promise { + async buildTeams(msg: CommandoMessage, userIds: string[], playerCount: number, tries: number, isRandom: boolean) { const half = Math.ceil(playerCount / 2); const players = await Player.findAll({ where: { userId: userIds } }); const maxSkillGap = 1; if (players.length < playerCount) { - msg.say(`${playerCount - players.length} players are not in the database. Add them first and try again.`); - return; + return msg.say(`${playerCount - players.length} players are not in the database. Add them first and try again.`); } for (let i = 0; i < tries; i++) { @@ -108,19 +88,18 @@ export default class buildTeamsCommand extends Command { const teamNames1 = team1.reduce(this.printTeamMembers, ''); const teamNames2 = team2.reduce(this.printTeamMembers, ''); - msg.say(this.printTeams(teamNames1, teamNames2)); - return; + return msg.say(this.printTeams(teamNames1, teamNames2)); } } - msg.say(`Could not create fair teams after trying ${tries} times. Try again.`); + return msg.say(`Could not create fair teams after trying ${tries} times. Try again.`); } printTeams(team1: string, team2: string): string { let res = '```\n'; res += 'Team 1'; res += team1; - res += '\nTeam2'; + res += '\nTeam 2'; res += team2; res += '\n```'; diff --git a/src/commands/team/changeTeamPlayer.ts b/src/commands/team/changeTeamPlayer.ts index b4ffbed..4d04e05 100644 --- a/src/commands/team/changeTeamPlayer.ts +++ b/src/commands/team/changeTeamPlayer.ts @@ -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, PlayerH, Team } from '../../db/models'; @@ -39,27 +39,22 @@ export default class ChangeTeamPlayerCommand extends Command { } async run(msg: CommandoMessage, { teamId, user, newUser }: PromptArgs) { - const end = new Message(null, null, msg.channel); - const team = await Team.findOne({ where: { id: teamId }, include: [{ all: true }] }); if (team == null) { - msg.say(`Team with ID \`${teamId}\` is not in the database...`); - return end; + return msg.say(`Team with ID \`${teamId}\` is not in the database...`); } const player = await Player.findOne({ where: { userId: user.id } }); if (player == null) { - msg.say(`Player ${user.tag} is not in the database...`); - return end; + return msg.say(`Player ${user.tag} is not in the database...`); } const newPlayer = await Player.findOne({ where: { userId: newUser.id } }); if (newPlayer == null) { - msg.say(`Player ${newUser.tag} is not in the database...`); - return end; + return msg.say(`Player ${newUser.tag} is not in the database...`); } let isInTeam = false; @@ -77,8 +72,7 @@ export default class ChangeTeamPlayerCommand extends Command { } if (isInTeam) { - msg.say(`Player ${newPlayer.userTag} is already in the team...`); - return end; + return msg.say(`Player ${newPlayer.userTag} is already in the team...`); } const p = new PlayerH({ @@ -101,14 +95,12 @@ export default class ChangeTeamPlayerCommand extends Command { } else if (team.player5.userTag == player.userTag) { team.playerId5 = p.id; } else { - msg.say(`Player ${user.tag} is not in this team (${teamId})`); p.destroy(); - return end; + return msg.say(`Player ${user.tag} is not in this team (${teamId})`); } await team.save(); - msg.say(`Team \`${teamId}\`: Player ${user.tag} was swapped out with ${newUser.tag}`); - return end; + return msg.say(`Team \`${teamId}\`: Player ${user.tag} was swapped out with ${newUser.tag}`); } } diff --git a/src/commands/team/deleteTeam.ts b/src/commands/team/deleteTeam.ts index 16237e9..7371be3 100644 --- a/src/commands/team/deleteTeam.ts +++ b/src/commands/team/deleteTeam.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Team } from '../../db/models'; @@ -27,20 +26,16 @@ export default class DeleteTeamCommand extends Command { } async run(msg: CommandoMessage, { teamId }: PromptArgs) { - const end = new Message(null, null, msg.channel); - const teamToDelete = await Team.findOne({ where: { id: teamId }, }); if (teamToDelete == null) { - msg.say(`Team with ID \`${teamId}\` is not in the database...`); - return end; + return msg.say(`Team with ID \`${teamId}\` is not in the database...`); } await teamToDelete.destroy(); - msg.say(`Team \`${teamId}\` was successfully removed from the database!`); - return end; + return msg.say(`Team \`${teamId}\` was successfully removed from the database!`); } } diff --git a/src/commands/team/getTeam.ts b/src/commands/team/getTeam.ts index 8eb449f..f036a83 100644 --- a/src/commands/team/getTeam.ts +++ b/src/commands/team/getTeam.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { printTeam } from '../../core/print'; @@ -31,11 +30,9 @@ export default class GetTeamCommand extends Command { const team = await Team.findOne({ where: { id: teamId }, include: [{ all: true }] }); if (team == null) { - msg.say(`Team \`${teamId}\` was not found!`); - return new Message(null, null, msg.channel); + return msg.say(`Team \`${teamId}\` was not found!`); } - msg.say(printTeam(team)); - return new Message(null, null, msg.channel); + return msg.say(printTeam(team)); } } diff --git a/src/commands/team/listRecentTeams.ts b/src/commands/team/listRecentTeams.ts index c8cb0e0..0046d9e 100644 --- a/src/commands/team/listRecentTeams.ts +++ b/src/commands/team/listRecentTeams.ts @@ -1,9 +1,7 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { printTeam } from '../../core/print'; import { Team } from '../../db/models'; -import { PlayerH } from '../../db/models'; interface PromptArgs { amount: number; @@ -30,7 +28,6 @@ export default class ListTeamsCommand extends Command { } async run(msg: CommandoMessage, { amount }: PromptArgs) { - const end = new Message(null, null, msg.channel); amount = Math.max(0, Math.min(amount, 20)); const nMostRecentTeams = await Team.findAll({ @@ -41,8 +38,7 @@ export default class ListTeamsCommand extends Command { nMostRecentTeams.reverse(); if (nMostRecentTeams.length == 0 && amount != 0) { - msg.say('No teams in database'); - return end; + return msg.say('No teams in database'); } else if (nMostRecentTeams.length == 1) { msg.say(`Most recent team in database:`); } else if (nMostRecentTeams.length < amount) { @@ -56,7 +52,7 @@ export default class ListTeamsCommand extends Command { res += '\n' + (await printTeam(team)); } res += '\n```'; - msg.say(res); + return msg.say(res); } // async teamToString(team: Team): Promise { diff --git a/src/commands/team/numberPicking.ts b/src/commands/team/numberPicking.ts index 4bc681d..0b9fc82 100644 --- a/src/commands/team/numberPicking.ts +++ b/src/commands/team/numberPicking.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { shuffle } from '../../util/arrayHelper'; @@ -14,63 +13,51 @@ export default class numberPickingCommand extends Command { } async run(msg: CommandoMessage, rawArgs: string) { - const end = new Message(null, null, msg.channel); const neededUsers = 10; let userIds: string[]; const channel = msg.member.voice.channel; if (rawArgs.trim() === '') { if (channel == null) { - msg.reply('You are not in a voice channel!'); - return end; + return msg.reply('You are not in a voice channel!'); } if (channel.members.size < neededUsers) { - msg.say('There are not enough players in the voice channel.'); - return end; + return msg.say('There are not enough players in the voice channel.'); } else if (channel.members.size > neededUsers) { - msg.say('There are too many players in the voice channel. Can not choose players.'); - return end; + return msg.say('There are too many players in the voice channel. Can not choose players.'); } userIds = channel.members.map((_, k) => k); - await this.distributeNumbers(msg, userIds); - return end; + return await this.distributeNumbers(msg, userIds); } if (channel == null && msg.mentions.users.size == 0) { - msg.reply('You are not in a voice channel and forgot to mention enough players.'); - return end; + return msg.reply('You are not in a voice channel and forgot to mention enough players.'); } if (msg.mentions.users.size == 0) { - msg.say('You forgot to choose the remaining players.'); - return end; + return msg.say('You forgot to choose the remaining players.'); } if (msg.mentions.users.size == neededUsers) { userIds = msg.mentions.users.map((_, k) => k); - await this.distributeNumbers(msg, userIds); - return end; + return await this.distributeNumbers(msg, userIds); } if (channel == null) { - msg.reply('You are not in a voice channel.'); - return end; + return msg.reply('You are not in a voice channel.'); } userIds = channel.members.map((_, k) => k).concat(msg.mentions.users.map((_, k) => k)); if (userIds.length < neededUsers) { - msg.reply(`You didn't mention enough players. ${neededUsers - userIds.length} players are missing.`); - return end; + return msg.reply(`You didn't mention enough players. ${neededUsers - userIds.length} players are missing.`); } else if (userIds.length > neededUsers) { - msg.reply(`You mentioned too many players. You need ${neededUsers} players, not ${userIds.length}`); - return end; + return msg.reply(`You mentioned too many players. You need ${neededUsers} players, not ${userIds.length}`); } - await this.distributeNumbers(msg, userIds); - return end; + return await this.distributeNumbers(msg, userIds); } async distributeNumbers(msg: CommandoMessage, userIds: string[]) { @@ -79,6 +66,6 @@ export default class numberPickingCommand extends Command { const guildMember = await msg.guild.members.fetch(userIds[i]); guildMember.user.send(`Your number is: ${i + 1}`); } - msg.say('Sent all users their number. Start picking!'); + return msg.say('Sent all users their number. Start picking!'); } } diff --git a/src/commands/team/updateTeamName copy.ts b/src/commands/team/updateTeamName copy.ts index c0ae1c2..6ae9bd4 100644 --- a/src/commands/team/updateTeamName copy.ts +++ b/src/commands/team/updateTeamName copy.ts @@ -1,4 +1,3 @@ -import { Message } from 'discord.js'; import { Command, CommandoClient, CommandoMessage } from 'discord.js-commando'; import { Team } from '../../db/models'; @@ -33,23 +32,17 @@ export default class UpdateTeamCommand extends Command { } async run(msg: CommandoMessage, { teamId, newTeamName }: PromptArgs) { - const end = new Message(null, null, msg.channel); - const teamToEdit = await Team.findOne({ where: { id: teamId }, }); if (teamToEdit == null) { - msg.say(`Team with ID \`${teamId}\` is not in the database...`); - return end; + return msg.say(`Team with ID \`${teamId}\` is not in the database...`); } - msg.say(teamToEdit); - teamToEdit.teamName = newTeamName; teamToEdit.save(); - msg.say(`Team \`${teamId}\` was renamed to \`${teamToEdit.teamName}\``); - return end; + return msg.say(`Team \`${teamId}\` was renamed to \`${teamToEdit.teamName}\``); } } diff --git a/src/constants.ts b/src/constants.ts index ade943e..8e661c7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -8,4 +8,6 @@ export const botStatus: ActivityOptions[] = [ { name: 'with your feelings ❤', type: 'PLAYING' }, { name: 'you ❤', type: 'WATCHING' }, { name: 'your footsteps ❤', type: 'LISTENING' }, + { name: 'with knifes ❤', type: 'PLAYING' }, + { name: 'https://jetti-ui.herokuapp.com/', type: 'WATCHING' }, ]; diff --git a/src/core/status.ts b/src/core/status.ts index 4ea5cc1..06d63a7 100644 --- a/src/core/status.ts +++ b/src/core/status.ts @@ -4,7 +4,10 @@ import { botStatus } from '../constants'; export const randomStatus = (client: CommandoClient) => { cron.schedule('*/30 * * * *', async () => { - await client.user.setActivity(botStatus[Math.floor(Math.random() * botStatus.length)]); + await client.user.setPresence({ + activity: botStatus[Math.floor(Math.random() * botStatus.length)], + status: 'dnd', + }); console.log('Updated bot activity'); }); };