Skip to content

Commit

Permalink
GH-48: Bump discord.js from 12.5.3 to 13.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Oct 27, 2021
1 parent 096b79c commit 9dea53c
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 84 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
"typescript"
],
"dependencies": {
"discord.js": "^12.5.3"
"discord.js": "^13.2.0"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^16.11.6",
"@types/ws": "^7.4.4",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"eslint": "^8.1.0",
Expand All @@ -48,7 +47,7 @@
"build:watch": "tsc -w -p tsconfig.release.json",
"format:check": "prettier --config .prettierrc --list-different \"**/**.ts\"",
"format": "prettier --config .prettierrc --write \"**/**.ts\"",
"lint": "eslint . --ext .ts,.tsx",
"lint": "eslint . --ext .ts",
"serve": "node dist/bin/tictactoe.js",
"start": "yarn build && yarn serve",
"test": "jest --coverage",
Expand Down
7 changes: 4 additions & 3 deletions src/bot/GameCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GuildMember, Message, TextChannel, User } from 'discord.js';
import TicTacToeBot from '@bot/TicTacToeBot';
import { GuildMember, Message, Permissions, TextChannel, User } from 'discord.js';
import GameChannel from '@bot/channel/GameChannel';
import TicTacToeBot from '@bot/TicTacToeBot';
import localize from '@config/localize';

/**
Expand Down Expand Up @@ -189,7 +189,8 @@ export default class GameCommand {
invited &&
!invited.user.bot &&
invitation.member !== invited &&
invited.permissionsIn(invitation.channel).has('VIEW_CHANNEL')
invitation.channel instanceof TextChannel &&
invited.permissionsIn(invitation.channel).has(Permissions.FLAGS.VIEW_CHANNEL)
);
}
}
2 changes: 1 addition & 1 deletion src/bot/TicTacToeBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class TicTacToeBot {
* Attaches a new Discord client to the module by preparing command handing.
*/
public attachToClient(client: Client): void {
client.on('message', this.command.handle.bind(this.command));
client.on('messageCreate', this.command.handle.bind(this.command));
}

/**
Expand Down
26 changes: 14 additions & 12 deletions src/bot/gameboard/GameBoardMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class GameBoardMessage {
* @private
*/
private async onMoveSelected(collected: Collection<Snowflake, MessageReaction>): Promise<void> {
const move = GameBoardBuilder.MOVE_REACTIONS.indexOf(collected.first()!.emoji.name);
const move = GameBoardBuilder.MOVE_REACTIONS.indexOf(collected.first()!.emoji.name!);
await this.playTurn(move);
}

Expand Down Expand Up @@ -188,8 +188,10 @@ export default class GameBoardMessage {
* @private
*/
private async onExpire(): Promise<void> {
if (this.message && this.message.deletable && !this.message.deleted) {
await this.message.delete();
try {
await this.message?.delete();
} catch {
// ignore api error
}
await this.channel.expireGame();
}
Expand All @@ -202,15 +204,15 @@ export default class GameBoardMessage {
const expireTime = this.configuration?.gameExpireTime ?? 30;
if (!this.message || this.message.deleted) return;
this.message
.awaitReactions(
(reaction, user) => {
return (
user.id === this.getEntity(this.game.currentPlayer)?.id &&
this.game.isMoveValid(GameBoardMessage.reactionToMove(reaction.emoji.name))
);
},
{ max: 1, time: expireTime * 1000, errors: ['time'] }
)
.awaitReactions({
filter: (reaction, user) =>
reaction.emoji.name != null &&
user.id === this.getEntity(this.game.currentPlayer)?.id &&
this.game.isMoveValid(GameBoardMessage.reactionToMove(reaction.emoji.name)),
max: 1,
time: expireTime * 1000,
errors: ['time']
})
.then(this.onMoveSelected.bind(this))
.catch(this.onExpire.bind(this));
}
Expand Down
37 changes: 21 additions & 16 deletions src/bot/request/DuelRequestMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export default class DuelRequestMessage {
}

this.message
.awaitReactions(
(reaction, user) => {
return (
DuelRequestMessage.REACTIONS.includes(reaction.emoji.name) &&
user.id === this.invited.id
);
},
{ max: 1, time: this.expireTime * 1000, errors: ['time'] }
)
.awaitReactions({
filter: (reaction, user) =>
reaction.emoji.name != null &&
DuelRequestMessage.REACTIONS.includes(reaction.emoji.name) &&
user.id === this.invited.id,
max: 1,
time: this.expireTime * 1000,
errors: ['time']
})
.then(this.challengeAnswered.bind(this))
.catch(this.challengeExpired.bind(this));
}
Expand All @@ -82,9 +82,12 @@ export default class DuelRequestMessage {
* @param message message to answer if needed
*/
public async close(message?: string): Promise<void> {
if (this.message && this.message.deletable && !this.message.deleted) {
await this.message.delete();
try {
await this.message?.delete();
} catch {
// ignore api error
}

if (message) {
await this.request.channel.send(message);
}
Expand Down Expand Up @@ -132,11 +135,13 @@ export default class DuelRequestMessage {
localize.__('duel.action');

return this.request.channel.send({
embed: {
color: '#2980b9',
title: localize.__('duel.title'),
description: content
}
embeds: [
{
color: '#2980b9',
title: localize.__('duel.title'),
description: content
}
]
});
}
}
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client, Message } from 'discord.js';
import { Client, Intents, Message } from 'discord.js';
import EventHandler, { EventType } from '@bot/EventHandler';
import TicTacToeBot from '@bot/TicTacToeBot';
import localize from '@config/localize';
Expand Down Expand Up @@ -59,7 +59,14 @@ class TicTacToe {
throw new Error('Game command needed to start Discord client.');
}

const client = new Client();
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS
]
});

this.bot.attachToClient(client);
await client.login(loginToken);
}
Expand Down

0 comments on commit 9dea53c

Please sign in to comment.