Skip to content

Commit a162de7

Browse files
committed
regression to discord.js v11
1 parent d04b390 commit a162de7

10 files changed

Lines changed: 69 additions & 80 deletions

File tree

package-lock.json

Lines changed: 29 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"homepage": "https://github.com/tabarra/txAdmin#readme",
2727
"dependencies": {
2828
"@citizenfx/http-wrapper": "^0.2.2",
29+
"@discordjs/collection": "^0.1.5",
2930
"@koa/router": "^9.0.1",
3031
"axios": "^0.19.2",
3132
"big-integer": "^1.6.48",
@@ -34,7 +35,7 @@
3435
"clone": "^2.1.2",
3536
"color-support": "^1.1.3",
3637
"dateformat": "^3.0.3",
37-
"discord.js": "^12.2.0",
38+
"discord.js": "^11.6.4",
3839
"fs-extra": "^9.0.1",
3940
"humanize-duration": "^3.23.1",
4041
"json-colorizer": "^2.2.2",

src/components/discordBot/commands/addwl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//Requires
22
const modulename = 'DiscordBot:cmd:addwl';
3-
const { MessageEmbed } = require("discord.js");
43
const { dir, log, logOk, logWarn, logError } = require('../../../extras/console')(modulename);
54

65
/**

src/components/discordBot/commands/help.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//Requires
22
const modulename = 'DiscordBot:cmd:help';
3-
const { MessageEmbed } = require("discord.js");
3+
const { RichEmbed } = require("discord.js");
44
const { dir, log, logOk, logWarn, logError } = require('../../../extras/console')(modulename);
55

66
module.exports = {
@@ -16,9 +16,10 @@ module.exports = {
1616
`:game_die: **Available commands:**`,
1717
'```',
1818
...cmdDescs,
19+
'...more commands to come soon 😮',
1920
'```',
2021
];
21-
const outMsg = new MessageEmbed({
22+
const outMsg = new RichEmbed({
2223
color: 0x4287F5,
2324
description: descLines.join('\n')
2425
});

src/components/discordBot/commands/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//Requires
22
const modulename = 'DiscordBot:cmd:info';
3-
const { MessageEmbed } = require("discord.js");
3+
const { RichEmbed } = require("discord.js");
44
const { dir, log, logOk, logWarn, logError } = require('../../../extras/console')(modulename);
55

66
//TODO: this doesn't make sense if we are not saving ot the db the player identifiers

src/components/discordBot/commands/status.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//Requires
22
const modulename = 'DiscordBot:cmd:status';
33
const humanizeDuration = require('humanize-duration');
4-
const { MessageEmbed } = require("discord.js");
4+
const { RichEmbed } = require("discord.js");
55
const { dir, log, logOk, logWarn, logError } = require('../../../extras/console')(modulename);
66

77
module.exports = {
@@ -36,7 +36,7 @@ module.exports = {
3636
});
3737

3838
//Prepare object
39-
const outMsg = new MessageEmbed({
39+
const outMsg = new RichEmbed({
4040
color: cardColor,
4141
title: cardTitle,
4242
description: desc,

src/components/discordBot/commands/txadmin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//Requires
22
const modulename = 'DiscordBot:cmd:txadmin';
3-
const { MessageEmbed } = require("discord.js");
3+
const { RichEmbed } = require("discord.js");
44
const { dir, log, logOk, logWarn, logError } = require('../../../extras/console')(modulename);
55

66
module.exports = {
77
description: 'Prints the current txAdmin version',
88
async execute(message, args) {
9-
const outMsg = new MessageEmbed({
9+
const outMsg = new RichEmbed({
1010
color: 0x4DEEEA,
1111
title: `${globals.config.serverName} uses txAdmin v${GlobalData.txAdminVersion} :smiley:`,
1212
description: `Checkout the project:\n GitHub: https://github.com/tabarra/txAdmin\n Discord: https://discord.gg/f3TsfvD`

src/components/discordBot/index.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//Requires
22
const modulename = 'DiscordBot';
33
const Discord = require('discord.js');
4+
5+
//FIXME: remove when updating to djs12, as well as this from the package.json
6+
const Collection = require('@discordjs/collection');
7+
48
const { dir, log, logOk, logWarn, logError } = require('../../extras/console')(modulename);
59

610
//NOTE: fix for the fact that fxserver (as of 2627) does not have URLSearchParams as part of the global scope
@@ -48,7 +52,7 @@ module.exports = class DiscordBot {
4852
* NOTE: setting them up statically due to webpack requirements
4953
*/
5054
setupCommands(){
51-
this.commands = new Discord.Collection([
55+
this.commands = new Collection([
5256
['addwl', require('./commands/addwl.js')],
5357
['help', require('./commands/help.js')],
5458
['status', require('./commands/status.js')],
@@ -69,7 +73,7 @@ module.exports = class DiscordBot {
6973
if(
7074
!this.config.announceChannel ||
7175
!this.client ||
72-
this.client.ws.status ||
76+
this.client.status ||
7377
!this.announceChannel
7478
){
7579
if(GlobalData.verbose) logWarn(`returning false, not ready yet`, 'sendAnnouncement');
@@ -96,30 +100,29 @@ module.exports = class DiscordBot {
96100
this.client.on('ready', async () => {
97101
logOk(`Started and logged in as '${this.client.user.tag}'`);
98102
this.client.user.setActivity(globals.config.serverName, {type: 'WATCHING'});
99-
this.announceChannel = await this.client.channels.resolve(this.config.announceChannel);
103+
// this.announceChannel = await this.client.channels.resolve(this.config.announceChannel);
104+
this.announceChannel = this.client.channels.find(x => x.id === this.config.announceChannel);
100105
if(!this.announceChannel){
101106
logError(`The announcements channel could not be found. Check the ID: ${this.config.announceChannel}`);
107+
}else{
108+
let cmdDescs = [];
109+
this.commands.forEach((cmd, name) => {
110+
cmdDescs.push(`${this.config.prefix}${name}: ${cmd.description}`);
111+
});
112+
const descLines = [
113+
`:rocket: **txAdmin** v${GlobalData.txAdminVersion} bot started!`,
114+
`:game_die: **Commands:**`,
115+
'```',
116+
...cmdDescs,
117+
'...more commands to come soon 😮',
118+
'```',
119+
];
120+
const msg = new Discord.RichEmbed({
121+
color: 0x4287F5,
122+
description: descLines.join('\n')
123+
});
124+
this.announceChannel.send(msg);
102125
}
103-
104-
//Prepare description
105-
let cmdDescs = [];
106-
this.commands.each((cmd, name) => {
107-
cmdDescs.push(`${this.config.prefix}${name}: ${cmd.description}`);
108-
});
109-
const descLines = [
110-
`:rocket: **txAdmin** v${GlobalData.txAdminVersion} bot started!`,
111-
`:game_die: **Commands:**`,
112-
'```',
113-
...cmdDescs,
114-
'(more commands to come soon...)',
115-
'```',
116-
];
117-
const msg = new Discord.MessageEmbed({
118-
color: 0x4287F5,
119-
description: descLines.join('\n')
120-
});
121-
122-
this.sendAnnouncement(msg);
123126
});
124127

125128
//Setup remaining event listeners

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if(typeof txAdminVersion !== 'string' || txAdminVersion == 'null'){
6868
//Check if this version of txAdmin is too outdated to be considered safe to use in prod
6969
//NOTE: Only valid if its being very actively maintained.
7070
// Use 30d for patch 0, or 45~60d otherwise
71-
const txAdminVersionBestBy = 1593513059 + (30 * 86400); //2020-06-30 + 30 days
71+
const txAdminVersionBestBy = 1593555666 + (30 * 86400); //2020-06-30 + 30 days
7272
if(now() > txAdminVersionBestBy){
7373
logError(`This version of txAdmin is outdated.`);
7474
logError(`Please update as soon as possible.`);

webpack.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ module.exports = {
3737
},
3838
externals: {
3939
// discord.js
40-
'ffmpeg-static': 'empty',
40+
'@discordjs/opus': 'empty',
41+
'node-opus': 'empty',
42+
'opusscript': 'empty',
4143
},
4244
stats: 'errors-warnings',
4345
plugins: [

0 commit comments

Comments
 (0)