Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade discord.js v13 -> v14 #928

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
14,695 changes: 7,405 additions & 7,290 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"cron": "^3.5.0",
"dayjs": "^1.11.13",
"decache": "^4.6.2",
"discord.js": "^13.17.1",
"discord.js": "^14.17.3",
"flat-cache": "^3.2.0",
"i18n-string-templates": "^1.0.7",
"json-query": "^2.2.2",
Expand Down
53 changes: 24 additions & 29 deletions src/bot.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import Discord from 'discord.js';
import Discord, { PresenceUpdateStatus } from 'discord.js';

import WorldStateClient from './utilities/WorldStateClient.js';
import EventHandler from './eventHandlers/EventHandler.js';
import Database from './settings/Database.js';
import logger from './utilities/Logger.js';

const {
Client,
WebhookClient,
Intents,
Constants: { Events },
} = Discord;
const { Client, WebhookClient, GatewayIntentBits, Events } = Discord;

const unlog = {
debug: ['WS_CONNECTION_TIMEOUT'],
Expand Down Expand Up @@ -59,7 +54,7 @@ export default class Genesis {
shards,
shardCount: Number(process.env.SHARDS || 1),
presence: {
status: 'dnd',
status: PresenceUpdateStatus.DoNotDisturb,
afk: false,
activities: [
{
Expand All @@ -68,11 +63,11 @@ export default class Genesis {
],
},
intents: [
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildVoiceStates,
],
});

Expand Down Expand Up @@ -148,35 +143,35 @@ export default class Genesis {
}

async setupHandlers() {
this.client.on(Events.CLIENT_READY, async () =>
this.eventHandler.handleEvent({ event: Events.CLIENT_READY, args: [] })
this.client.on(Events.ClientReady, async () =>
this.eventHandler.handleEvent({ event: Events.ClientReady, args: [] })
);

this.client.on(Events.GUILD_CREATE, async (guild) =>
this.eventHandler.handleEvent({ event: Events.GUILD_CREATE, args: [guild] })
this.client.on(Events.GuildCreate, async (guild) =>
this.eventHandler.handleEvent({ event: Events.GuildCreate, args: [guild] })
);
this.client.on(Events.GUILD_DELETE, async (guild) =>
this.eventHandler.handleEvent({ event: Events.GUILD_DELETE, args: [guild] })
this.client.on(Events.GuildDelete, async (guild) =>
this.eventHandler.handleEvent({ event: Events.GuildDelete, args: [guild] })
);
this.client.on(Events.CHANNEL_CREATE, async (channel) =>
this.eventHandler.handleEvent({ event: Events.CHANNEL_CREATE, args: [channel] })
this.client.on(Events.ChannelCreate, async (channel) =>
this.eventHandler.handleEvent({ event: Events.ChannelCreate, args: [channel] })
);
this.client.on(Events.CHANNEL_DELETE, async (channel) =>
this.eventHandler.handleEvent({ event: Events.CHANNEL_DELETE, args: [channel] })
this.client.on(Events.ChannelDelete, async (channel) =>
this.eventHandler.handleEvent({ event: Events.ChannelDelete, args: [channel] })
);

this.client.on(Events.INTERACTION_CREATE, async (interaction) =>
this.eventHandler.handleEvent({ event: Events.INTERACTION_CREATE, args: [interaction] })
this.client.on(Events.InteractionCreate, async (interaction) =>
this.eventHandler.handleEvent({ event: Events.InteractionCreate, args: [interaction] })
);

this.client.on(Events.SHARD_DISCONNECT, (event) => {
this.client.on(Events.ShardDisconnect, (event) => {
this.logger.error(`Disconnected with close event: ${event.code}`);
});
this.client.on(Events.ERROR, (error) => {
this.client.on(Events.Error, (error) => {
if (!unlog.error.test(error.message)) this.logger.error(error);
});
this.client.on(Events.WARN, this.logger.warn);
this.client.on(Events.DEBUG, (message) => {
this.client.on(Events.Warn, this.logger.warn);
this.client.on(Events.Debug, (message) => {
if (/(heartbeat|Latency of|voice|HELLO timeout|CONNECT|Spawning)/i.test(message)) {
this.logger.silly(message);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/embeds/BaseEmbed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageEmbed } from 'discord.js';
import { EmbedBuilder } from 'discord.js';

const defaults = {
url: process.env.EMBED_URL || 'https://warframestat.us',
Expand All @@ -8,7 +8,7 @@ const defaults = {
/**
* Utility class for making rich embeds
*/
export default class BaseEmbed extends MessageEmbed {
export default class BaseEmbed extends EmbedBuilder {
constructor(locale) {
super({
url: defaults.url,
Expand Down
14 changes: 6 additions & 8 deletions src/eventHandlers/AddChannelToDatabase.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import Discord from 'discord.js';
import { ChannelType, Events } from 'discord.js';

import Handler from '../models/BaseEventHandler.js';

const { Events } = Discord.Constants;

/**
* Describes a handler
*/
export default class AddChannelToDatabase extends Handler {
constructor(bot) {
super(bot, 'handlers.addChannel', Events.CHANNEL_CREATE);
super(bot, 'handlers.addChannel', Events.ChannelCreate);
}

// eslint-disable-next-line valid-jsdoc
/**
* add the guild to the Database
* @param {Discord.Channel} channel channel to add to the database
* @param {Discord.channel} channel channel to add to the database
*/
async execute(...[channel]) {
this.logger.debug(`Running ${this.id} for ${this.event}`);

if (channel.type === 'GUILD_VOICE') {
if (channel.type === ChannelType.GuildVoice) {
return;
}
if (channel.type === 'GUILD_TEXT') {
if (channel.type === ChannelType.GuildText) {
try {
await this.settings.addGuildTextChannel(channel);
this.logger.debug(
Expand All @@ -34,7 +32,7 @@ export default class AddChannelToDatabase extends Handler {
await this.settings.addGuild(channel.guild);
this.settings.addGuildTextChannel(channel);
}
} else if (channel.type === 'GUILD_PUBLIC_THREAD' || channel.type === 'GUILD_PRIVATE_THREAD') {
} else if (channel.type === ChannelType.PublicThread || channel.type === ChannelType.PrivateThread) {
if (channel.parentId) {
await this.settings.addGuildTextChannel({ id: channel.parentId, guild: { id: channel.guild.id } });
}
Expand Down
8 changes: 3 additions & 5 deletions src/eventHandlers/AddGuildToDatabase.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Discord from 'discord.js';
import { Events } from 'discord.js';

import Handler from '../models/BaseEventHandler.js';

const { Events } = Discord.Constants;

/**
* Describes a handler
*/
Expand All @@ -13,7 +11,7 @@ export default class AddGuildToDatabase extends Handler {
* @param {Genesis} bot The bot object
*/
constructor(bot) {
super(bot, 'handlers.addGuild', Events.GUILD_CREATE);
super(bot, 'handlers.addGuild', Events.GuildCreate);
this.channelTimeout = 60000;
}

Expand All @@ -28,6 +26,6 @@ export default class AddGuildToDatabase extends Handler {
return;
}
await this.settings.addGuild([guild]);
this.logger.debug(`Joined guild ${guild} (${guild.id}`);
this.logger.debug(`Joined guild ${guild} (${guild.id})`);
}
}
8 changes: 3 additions & 5 deletions src/eventHandlers/AssignDefaultRoles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Discord from 'discord.js';
import { Events } from 'discord.js';

import Handler from '../models/BaseEventHandler.js';
import { games } from '../utilities/CommonFunctions.js';

const { Events } = Discord.Constants;

/**
* Describes a handler
*/
Expand All @@ -14,12 +12,12 @@ export default class AssignDefaultRolesHandle extends Handler {
* @param {Genesis} bot The bot object
*/
constructor(bot) {
super(bot, 'handlers.assignDefaultRoles', Events.GUILD_MEMBER_ADD);
super(bot, 'handlers.assignDefaultRoles', Events.GuildMemberAdd);
}

/**
* add the guild to teh Database
* @param {Discord.Member} member member to add roles to
* @param {Discord.GuildMember} member member to add roles to
*/
async execute(...[member]) {
if (!games.includes('UTIL')) return;
Expand Down
8 changes: 3 additions & 5 deletions src/eventHandlers/BulkMessageDeleteHandle.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import Discord from 'discord.js';
import { ChannelType, Events } from 'discord.js';

import Handler from '../models/BaseEventHandler.js';
import LogEmbed from '../embeds/LogEmbed.js';
import webhook from '../utilities/Webhook.js'; // eslint-disable-line import/no-named-as-default
import { games } from '../utilities/CommonFunctions.js';

const { Events } = Discord.Constants;

/**
* Describes a handler
*/
Expand All @@ -16,7 +14,7 @@ export default class LogMessageDelete extends Handler {
* @param {Genesis} bot The bot object
*/
constructor(bot) {
super(bot, 'handlers.logMessageDeleteBulk', Events.MESSAGE_DELETE_BULK);
super(bot, 'handlers.logMessageDeleteBulk', Events.MessageBulkDelete);
}

/**
Expand All @@ -34,7 +32,7 @@ export default class LogMessageDelete extends Handler {
} else {
channel = undefined;
}
if (channel?.type === 'text') {
if (channel?.type === ChannelType.GuildText) {
const log = new LogEmbed(this.bot, {
color: 0xff5a36,
title: 'Message Deleted',
Expand Down
8 changes: 3 additions & 5 deletions src/eventHandlers/DeleteChannel.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Discord from 'discord.js';
import { ChannelType, Events } from 'discord.js';

import Handler from '../models/BaseEventHandler.js';

const { Events } = Discord.Constants;

/**
* Describes a handler
*/
Expand All @@ -13,7 +11,7 @@ export default class DeleteChannel extends Handler {
* @param {Genesis} bot The bot object
*/
constructor(bot) {
super(bot, 'handlers.deleteChannel', Events.CHANNEL_DELETE);
super(bot, 'handlers.deleteChannel', Events.ChannelDelete);
}

/**
Expand All @@ -23,7 +21,7 @@ export default class DeleteChannel extends Handler {
async execute(...[channel]) {
this.logger.debug(`Running ${this.id} for ${this.event}`);

if (channel.type === 'GUILD_VOICE') {
if (channel.type === ChannelType.GuildVoice) {
return;
}
await this.settings.deleteChannel(channel);
Expand Down
6 changes: 2 additions & 4 deletions src/eventHandlers/DeleteGuild.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Discord from 'discord.js';
import { Events } from 'discord.js';

import Handler from '../models/BaseEventHandler.js';

const { Events } = Discord.Constants;

/**
* Describes a handler
*/
Expand All @@ -13,7 +11,7 @@ export default class DeleteGuild extends Handler {
* @param {Genesis} bot The bot object
*/
constructor(bot) {
super(bot, 'handlers.deleteGuild', Events.GUILD_DELETE);
super(bot, 'handlers.deleteGuild', Events.GuildDelete);
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/eventHandlers/DynamicVoiceHandler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import Discord from 'discord.js';
import { Events, PermissionsBitField } from 'discord.js';
import { Generator } from 'warframe-name-generator';

const {
Constants: { Events },
Permissions,
} = Discord;
const requiredVCPerms = [Permissions.FLAGS.MANAGE_CHANNELS, Permissions.FLAGS.MOVE_MEMBERS];
const requiredVCPerms = [PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.MoveMembers];
const relays = [
'Larunda Relay',
'Vesper Relay',
Expand Down Expand Up @@ -82,14 +78,14 @@ export default class DynamicVoiceHandler {
/** @type Database */
this.settings = settings;

client.on(Events.VOICE_STATE_UPDATE, async (oldMember, newMember) => {
client.on(Events.VoiceStateUpdate, async (oldMember, newMember) => {
const applicable = await this.checkManagementApplicable(oldMember, newMember);
if (applicable) {
await this.checkAllChannels(oldMember.guild, newMember.member);
}
});

client.on(Events.CHANNEL_DELETE, async (channel) => {
client.on(Events.ChannelDelete, async (channel) => {
await this.removeChannel(channel);
});

Expand Down
Loading