Skip to content

Commit c66ac33

Browse files
committed
feat: update to discordjs v14
1 parent 0c670c3 commit c66ac33

File tree

9 files changed

+52
-27
lines changed

9 files changed

+52
-27
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16.13.2-alpine3.15
1+
FROM node:18.12-alpine
22

33
WORKDIR /usr/src/app
44

docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '3.8'
2+
3+
services:
4+
surftimer-bot:
5+
build: ./
6+
restart: always
7+
environment:
8+
# Discord token (https://discordjs.guide/preparations/setting-up-a-bot-application.html#creating-your-bot)
9+
- TOKEN: 0000000000000
10+
# Guild ID (https://poshbot.readthedocs.io/en/latest/guides/backends/setup-discord-backend/#find-your-guild-id-server-id)
11+
- GUILDID: 0000000000000
12+
# Application ID (https://poshbot.readthedocs.io/en/latest/guides/backends/setup-discord-backend/#authorize-your-bot)
13+
- CLIENTID: 0000000000000
14+
# Database URL (https://www.prisma.io/docs/concepts/database-connectors/mysql#connection-url)
15+
- DATABASE_URL: mysql://USER:PASSWORD@HOST:PORT/DATABASE
16+
# Steam Web API key (https://steamcommunity.com/dev/apikey)
17+
- STEAM_API_KEY: 0000000000000
18+
# The id of the channel where map records will be sent.
19+
- MAP_RECORD_CHANNEL_ID: 869859765987607
20+
# The API key to use in your CSGO plugin. Generate it here (https://toolslite.com/api-key-generator)
21+
- API_KEY: fGREZ78R98-fGREZ78R98-fGREZ78R98-fGREZ78R98-fGREZ78R98

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010
"test": "echo \"Error: no test specified\" && exit 1"
1111
},
1212
"engines": {
13-
"npm": ">=8.1.2",
14-
"node": ">=16.13.2"
13+
"npm": ">=9.1.2",
14+
"node": ">=18.12.0"
1515
},
1616
"module": "es2022",
1717
"author": "Sarrus",
1818
"license": "MIT",
1919
"dependencies": {
20-
"@discordjs/builders": "^0.11.0",
21-
"@discordjs/opus": "^0.7.0",
22-
"@discordjs/rest": "^0.2.0-canary.0",
20+
"@discordjs/opus": "^0.9.0",
2321
"@j4ckofalltrades/steam-webapi-ts": "^1.0.1",
2422
"axios": "^0.25.0",
2523
"discord-api-types": "^0.26.1",
26-
"discord.js": "^13.6.0",
24+
"discord.js": "^14.6.0",
2725
"dotenv": "^14.2.0",
2826
"express": "^4.18.1",
2927
"node-html-to-image": "^3.2.4",
@@ -33,7 +31,7 @@
3331
"devDependencies": {
3432
"@prisma/client": "^3.8.1",
3533
"@types/express": "^4.17.13",
36-
"@types/node": "16.11.19",
34+
"@types/node": "18.11.9",
3735
"prisma": "^3.8.1",
3836
"ts-loader": "^9.2.6",
3937
"ts-node": "10.4.0",

src/api/builder.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BufferResolvable, MessageAttachment, TextChannel } from 'discord.js';
1+
import { BufferResolvable, AttachmentBuilder, TextChannel } from 'discord.js';
22
import * as express from 'express';
33
import { readFileSync } from 'fs';
44
import nodeHtmlToImage from 'node-html-to-image';
@@ -44,10 +44,9 @@ api.post('/record', async (req, res) => {
4444
timeDiff: data.timeDiff,
4545
},
4646
}).then((image) => {
47-
const attachment = new MessageAttachment(
48-
image as BufferResolvable,
49-
'record-image.png',
50-
);
47+
const attachment = new AttachmentBuilder(image as BufferResolvable, {
48+
name: 'record-image.png',
49+
});
5150

5251
const content = {
5352
files: [attachment],

src/commands/mapstats.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { SlashCommandBuilder } from '@discordjs/builders';
22
import {
33
CommandInteraction,
4-
MessageEmbed,
5-
WebhookMessageOptions,
4+
EmbedBuilder,
5+
WebhookEditMessageOptions,
66
} from 'discord.js';
77

88
import { prisma, MAPS_IMAGES_URL } from '../main';
@@ -32,7 +32,10 @@ export default {
3232

3333
async function cmdCallback(
3434
interaction: CommandInteraction,
35-
): Promise<WebhookMessageOptions | string> {
35+
): Promise<WebhookEditMessageOptions | string> {
36+
if (!interaction.isChatInputCommand()) {
37+
return '';
38+
}
3639
const mapname = interaction.options.getString('mapname').toLowerCase();
3740
const res1 = await prisma.ck_maptier.findUnique({
3841
where: {
@@ -117,7 +120,7 @@ async function cmdCallback(
117120
},
118121
});
119122

120-
const embed = new MessageEmbed()
123+
const embed = new EmbedBuilder()
121124
.setTitle(`📈 __Map statistics__ 📈`)
122125
.setImage(`${MAPS_IMAGES_URL}/${mapname}.jpg`)
123126
.addFields([

src/commands/playerstats.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { SlashCommandBuilder } from '@discordjs/builders';
22
import {
33
CommandInteraction,
4-
MessageEmbed,
5-
WebhookMessageOptions,
4+
EmbedBuilder,
5+
WebhookEditMessageOptions,
66
} from 'discord.js';
77
import { prisma, steamWebApi } from '../main';
88
import { convertToSteam64 } from '../utils/convertToSteam64';
@@ -33,7 +33,10 @@ export default {
3333

3434
async function cmdCallback(
3535
interaction: CommandInteraction,
36-
): Promise<WebhookMessageOptions | string> {
36+
): Promise<WebhookEditMessageOptions | string> {
37+
if (!interaction.isChatInputCommand()) {
38+
return '';
39+
}
3740
const playerID = interaction.options.getString('playerid');
3841
const steamID64 = await convertToSteam64(playerID, process.env.STEAM_API_KEY);
3942
if (steamID64 === undefined) {
@@ -106,7 +109,7 @@ async function cmdCallback(
106109
(finishedBonuses / (totalBonuses ? totalBonuses : 1)) * 100,
107110
);
108111

109-
const embed = new MessageEmbed()
112+
const embed = new EmbedBuilder()
110113
.setTitle(`📈 __Player statistics__ 📈`)
111114
.setThumbnail(avatarfull)
112115
.addFields([

src/commands/top.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { SlashCommandBuilder } from '@discordjs/builders';
22
import {
33
CommandInteraction,
4-
MessageEmbed,
5-
WebhookMessageOptions,
4+
EmbedBuilder,
5+
WebhookEditMessageOptions,
66
} from 'discord.js';
77

88
import { prisma, steamWebApi } from '../main';
@@ -23,7 +23,7 @@ export default {
2323
},
2424
};
2525

26-
async function cmdCallback(): Promise<WebhookMessageOptions | string> {
26+
async function cmdCallback(): Promise<WebhookEditMessageOptions | string> {
2727
const res1 = await prisma.ck_playerrank.findMany({
2828
orderBy: {
2929
points: 'desc',
@@ -65,7 +65,7 @@ async function cmdCallback(): Promise<WebhookMessageOptions | string> {
6565
};
6666
});
6767

68-
const embed = new MessageEmbed()
68+
const embed = new EmbedBuilder()
6969
.setTitle(`🏆 __Top players__ 🏆`)
7070
.setThumbnail(avatarfull)
7171
.addFields(fields);

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, Intents } from 'discord.js';
1+
import { Client, GatewayIntentBits } from 'discord.js';
22
import { readdirSync } from 'fs';
33
import { PrismaClient } from '@prisma/client';
44
import * as dotenv from 'dotenv';
@@ -18,7 +18,7 @@ export const prisma = new PrismaClient();
1818
export const MAPS_IMAGES_URL =
1919
'https://raw.githubusercontent.com/Sayt123/SurfMapPics/Maps-and-bonuses/csgo/';
2020

21-
export const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
21+
export const client = new Client({ intents: [GatewayIntentBits.Guilds] });
2222

2323
const commands = new Map<string, SlashCommand>();
2424

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es6",
4+
"skipLibCheck": true,
45
"module": "commonjs",
56
"moduleResolution": "node",
67
"allowSyntheticDefaultImports": true,

0 commit comments

Comments
 (0)