Skip to content

Commit

Permalink
feat: update to discordjs v14
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarrus1 committed Nov 25, 2022
1 parent 0c670c3 commit c66ac33
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.13.2-alpine3.15
FROM node:18.12-alpine

WORKDIR /usr/src/app

Expand Down
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.8'

services:
surftimer-bot:
build: ./
restart: always
environment:
# Discord token (https://discordjs.guide/preparations/setting-up-a-bot-application.html#creating-your-bot)
- TOKEN: 0000000000000
# Guild ID (https://poshbot.readthedocs.io/en/latest/guides/backends/setup-discord-backend/#find-your-guild-id-server-id)
- GUILDID: 0000000000000
# Application ID (https://poshbot.readthedocs.io/en/latest/guides/backends/setup-discord-backend/#authorize-your-bot)
- CLIENTID: 0000000000000
# Database URL (https://www.prisma.io/docs/concepts/database-connectors/mysql#connection-url)
- DATABASE_URL: mysql://USER:PASSWORD@HOST:PORT/DATABASE
# Steam Web API key (https://steamcommunity.com/dev/apikey)
- STEAM_API_KEY: 0000000000000
# The id of the channel where map records will be sent.
- MAP_RECORD_CHANNEL_ID: 869859765987607
# The API key to use in your CSGO plugin. Generate it here (https://toolslite.com/api-key-generator)
- API_KEY: fGREZ78R98-fGREZ78R98-fGREZ78R98-fGREZ78R98-fGREZ78R98
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"npm": ">=8.1.2",
"node": ">=16.13.2"
"npm": ">=9.1.2",
"node": ">=18.12.0"
},
"module": "es2022",
"author": "Sarrus",
"license": "MIT",
"dependencies": {
"@discordjs/builders": "^0.11.0",
"@discordjs/opus": "^0.7.0",
"@discordjs/rest": "^0.2.0-canary.0",
"@discordjs/opus": "^0.9.0",
"@j4ckofalltrades/steam-webapi-ts": "^1.0.1",
"axios": "^0.25.0",
"discord-api-types": "^0.26.1",
"discord.js": "^13.6.0",
"discord.js": "^14.6.0",
"dotenv": "^14.2.0",
"express": "^4.18.1",
"node-html-to-image": "^3.2.4",
Expand All @@ -33,7 +31,7 @@
"devDependencies": {
"@prisma/client": "^3.8.1",
"@types/express": "^4.17.13",
"@types/node": "16.11.19",
"@types/node": "18.11.9",
"prisma": "^3.8.1",
"ts-loader": "^9.2.6",
"ts-node": "10.4.0",
Expand Down
9 changes: 4 additions & 5 deletions src/api/builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BufferResolvable, MessageAttachment, TextChannel } from 'discord.js';
import { BufferResolvable, AttachmentBuilder, TextChannel } from 'discord.js';
import * as express from 'express';
import { readFileSync } from 'fs';
import nodeHtmlToImage from 'node-html-to-image';
Expand Down Expand Up @@ -44,10 +44,9 @@ api.post('/record', async (req, res) => {
timeDiff: data.timeDiff,
},
}).then((image) => {
const attachment = new MessageAttachment(
image as BufferResolvable,
'record-image.png',
);
const attachment = new AttachmentBuilder(image as BufferResolvable, {
name: 'record-image.png',
});

const content = {
files: [attachment],
Expand Down
11 changes: 7 additions & 4 deletions src/commands/mapstats.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import {
CommandInteraction,
MessageEmbed,
WebhookMessageOptions,
EmbedBuilder,
WebhookEditMessageOptions,
} from 'discord.js';

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

async function cmdCallback(
interaction: CommandInteraction,
): Promise<WebhookMessageOptions | string> {
): Promise<WebhookEditMessageOptions | string> {
if (!interaction.isChatInputCommand()) {
return '';
}
const mapname = interaction.options.getString('mapname').toLowerCase();
const res1 = await prisma.ck_maptier.findUnique({
where: {
Expand Down Expand Up @@ -117,7 +120,7 @@ async function cmdCallback(
},
});

const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle(`📈 __Map statistics__ 📈`)
.setImage(`${MAPS_IMAGES_URL}/${mapname}.jpg`)
.addFields([
Expand Down
11 changes: 7 additions & 4 deletions src/commands/playerstats.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import {
CommandInteraction,
MessageEmbed,
WebhookMessageOptions,
EmbedBuilder,
WebhookEditMessageOptions,
} from 'discord.js';
import { prisma, steamWebApi } from '../main';
import { convertToSteam64 } from '../utils/convertToSteam64';
Expand Down Expand Up @@ -33,7 +33,10 @@ export default {

async function cmdCallback(
interaction: CommandInteraction,
): Promise<WebhookMessageOptions | string> {
): Promise<WebhookEditMessageOptions | string> {
if (!interaction.isChatInputCommand()) {
return '';
}
const playerID = interaction.options.getString('playerid');
const steamID64 = await convertToSteam64(playerID, process.env.STEAM_API_KEY);
if (steamID64 === undefined) {
Expand Down Expand Up @@ -106,7 +109,7 @@ async function cmdCallback(
(finishedBonuses / (totalBonuses ? totalBonuses : 1)) * 100,
);

const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle(`📈 __Player statistics__ 📈`)
.setThumbnail(avatarfull)
.addFields([
Expand Down
8 changes: 4 additions & 4 deletions src/commands/top.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import {
CommandInteraction,
MessageEmbed,
WebhookMessageOptions,
EmbedBuilder,
WebhookEditMessageOptions,
} from 'discord.js';

import { prisma, steamWebApi } from '../main';
Expand All @@ -23,7 +23,7 @@ export default {
},
};

async function cmdCallback(): Promise<WebhookMessageOptions | string> {
async function cmdCallback(): Promise<WebhookEditMessageOptions | string> {
const res1 = await prisma.ck_playerrank.findMany({
orderBy: {
points: 'desc',
Expand Down Expand Up @@ -65,7 +65,7 @@ async function cmdCallback(): Promise<WebhookMessageOptions | string> {
};
});

const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle(`🏆 __Top players__ 🏆`)
.setThumbnail(avatarfull)
.addFields(fields);
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client, Intents } from 'discord.js';
import { Client, GatewayIntentBits } from 'discord.js';
import { readdirSync } from 'fs';
import { PrismaClient } from '@prisma/client';
import * as dotenv from 'dotenv';
Expand All @@ -18,7 +18,7 @@ export const prisma = new PrismaClient();
export const MAPS_IMAGES_URL =
'https://raw.githubusercontent.com/Sayt123/SurfMapPics/Maps-and-bonuses/csgo/';

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

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

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "es6",
"skipLibCheck": true,
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
Expand Down

0 comments on commit c66ac33

Please sign in to comment.