3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 10:25:01 +00:00

update discord.js

This commit is contained in:
almeidx 2022-06-13 14:24:50 +01:00
parent ba78103807
commit ed4ba06f82
No known key found for this signature in database
GPG key ID: C5FF0C40763546C5
14 changed files with 81 additions and 104 deletions

View file

@ -13,8 +13,8 @@
"cors": "^2.8.5",
"cross-env": "^5.2.0",
"deep-diff": "^1.0.2",
"discord-api-types": "^0.33.1",
"discord.js": "^13.7.0",
"discord-api-types": "^0.33.5",
"discord.js": "^13.8.0",
"dotenv": "^4.0.0",
"emoji-regex": "^8.0.0",
"erlpack": "github:discord/erlpack",
@ -124,16 +124,16 @@
}
},
"node_modules/@discordjs/builders": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz",
"integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==",
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.14.0.tgz",
"integrity": "sha512-+fqLIqa9wN3R+kvlld8sgG0nt04BAZxdCDP4t2qZ9TJsquLWA+xMtT8Waibb3d4li4AQS+IOfjiHAznv/dhHgQ==",
"dependencies": {
"@sapphire/shapeshift": "^2.0.0",
"@sapphire/shapeshift": "^3.1.0",
"@sindresorhus/is": "^4.6.0",
"discord-api-types": "^0.31.1",
"discord-api-types": "^0.33.3",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.1",
"tslib": "^2.3.1"
"tslib": "^2.4.0"
},
"engines": {
"node": ">=16.9.0"
@ -150,20 +150,15 @@
"url": "https://github.com/sindresorhus/is?sponsor=1"
}
},
"node_modules/@discordjs/builders/node_modules/discord-api-types": {
"version": "0.31.2",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.31.2.tgz",
"integrity": "sha512-gpzXTvFVg7AjKVVJFH0oJGC0q0tO34iJGSHZNz9u3aqLxlD6LfxEs9wWVVikJqn9gra940oUTaPFizCkRDcEiA=="
},
"node_modules/@discordjs/builders/node_modules/tslib": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
"integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ=="
},
"node_modules/@discordjs/collection": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.6.0.tgz",
"integrity": "sha512-Ieaetb36l0nmAS5X9Upqk4W7euAO6FdXPxn3I8vBAKEcoIzEZI1mcVcPfCfagGJZSgBKpENnAnKkP4GAn+MV8w==",
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0.tgz",
"integrity": "sha512-R5i8Wb8kIcBAFEPLLf7LVBQKBDYUL+ekb23sOgpkpyGT+V4P7V83wTxcsqmX+PbqHt4cEHn053uMWfRqh/Z/nA==",
"engines": {
"node": ">=16.9.0"
}
@ -209,9 +204,9 @@
}
},
"node_modules/@sapphire/shapeshift": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-2.2.0.tgz",
"integrity": "sha512-UEnKgMlQyI0yY/q+lCMX0VJft9y86IsesgbIQj6e62FBYSaMVr+IaMNpi4z45Q14VnuMACbK0yrbHISNqgUYcQ==",
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.2.0.tgz",
"integrity": "sha512-asNgE5Ooil2/oGIAj6vZMoUc2ZFED0TGYD7jwvZsjHPQZBEh9ITj94ca4bCgiCR1s2ER/UjzykH+5wE3ebVZnQ==",
"engines": {
"node": ">=v15.0.0",
"npm": ">=7.0.0"
@ -1704,35 +1699,30 @@
}
},
"node_modules/discord-api-types": {
"version": "0.33.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.1.tgz",
"integrity": "sha512-dc7Xzm3isROh77jdxikQnLzKDslOPORm2Q8odXrKgEy8Aqfd1r9ISVTU/xsHkH6bFo+Hjf1A1C5OnBtu8ghy4w=="
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.5.tgz",
"integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg=="
},
"node_modules/discord.js": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.7.0.tgz",
"integrity": "sha512-iV/An3FEB/CiBGdjWHRtgskM4UuWPq5vjhjKsrQhdVU16dbKrBxA+eIV2HWA07B3tXUGM6eco1wkr42gxxV1BA==",
"version": "13.8.0",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.8.0.tgz",
"integrity": "sha512-EPAA/2VLycYN5wSzavqa4iJ6qj3UtQFtHw5TH/60Fj29ymfEsCQVn//o1mTpwDxzwb+rPIrWhkxKIGGnjfv0Iw==",
"dependencies": {
"@discordjs/builders": "^0.13.0",
"@discordjs/collection": "^0.6.0",
"@discordjs/builders": "^0.14.0",
"@discordjs/collection": "^0.7.0",
"@sapphire/async-queue": "^1.3.1",
"@types/node-fetch": "^2.6.1",
"@types/ws": "^8.5.3",
"discord-api-types": "^0.30.0",
"discord-api-types": "^0.33.3",
"form-data": "^4.0.0",
"node-fetch": "^2.6.1",
"ws": "^8.6.0"
"ws": "^8.7.0"
},
"engines": {
"node": ">=16.6.0",
"npm": ">=7.0.0"
}
},
"node_modules/discord.js/node_modules/discord-api-types": {
"version": "0.30.0",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.30.0.tgz",
"integrity": "sha512-wYst0jrT8EJs2tVlwUTQ2xT0oWMjUrRMpFTkNY3NMleWyQNHgWaKhqFfxdLPdC2im9IuR5EsxcEgjhf/npeftw=="
},
"node_modules/discord.js/node_modules/form-data": {
"version": "4.0.0",
"license": "MIT",
@ -5275,6 +5265,7 @@
},
"node_modules/zlib-sync": {
"version": "0.1.7",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"nan": "^2.14.0"
@ -5323,16 +5314,16 @@
}
},
"@discordjs/builders": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz",
"integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==",
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.14.0.tgz",
"integrity": "sha512-+fqLIqa9wN3R+kvlld8sgG0nt04BAZxdCDP4t2qZ9TJsquLWA+xMtT8Waibb3d4li4AQS+IOfjiHAznv/dhHgQ==",
"requires": {
"@sapphire/shapeshift": "^2.0.0",
"@sapphire/shapeshift": "^3.1.0",
"@sindresorhus/is": "^4.6.0",
"discord-api-types": "^0.31.1",
"discord-api-types": "^0.33.3",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.1",
"tslib": "^2.3.1"
"tslib": "^2.4.0"
},
"dependencies": {
"@sindresorhus/is": {
@ -5340,11 +5331,6 @@
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
"integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw=="
},
"discord-api-types": {
"version": "0.31.2",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.31.2.tgz",
"integrity": "sha512-gpzXTvFVg7AjKVVJFH0oJGC0q0tO34iJGSHZNz9u3aqLxlD6LfxEs9wWVVikJqn9gra940oUTaPFizCkRDcEiA=="
},
"tslib": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
@ -5353,9 +5339,9 @@
}
},
"@discordjs/collection": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.6.0.tgz",
"integrity": "sha512-Ieaetb36l0nmAS5X9Upqk4W7euAO6FdXPxn3I8vBAKEcoIzEZI1mcVcPfCfagGJZSgBKpENnAnKkP4GAn+MV8w=="
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0.tgz",
"integrity": "sha512-R5i8Wb8kIcBAFEPLLf7LVBQKBDYUL+ekb23sOgpkpyGT+V4P7V83wTxcsqmX+PbqHt4cEHn053uMWfRqh/Z/nA=="
},
"@nodelib/fs.scandir": {
"version": "2.1.3",
@ -5381,9 +5367,9 @@
"version": "1.3.1"
},
"@sapphire/shapeshift": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-2.2.0.tgz",
"integrity": "sha512-UEnKgMlQyI0yY/q+lCMX0VJft9y86IsesgbIQj6e62FBYSaMVr+IaMNpi4z45Q14VnuMACbK0yrbHISNqgUYcQ=="
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.2.0.tgz",
"integrity": "sha512-asNgE5Ooil2/oGIAj6vZMoUc2ZFED0TGYD7jwvZsjHPQZBEh9ITj94ca4bCgiCR1s2ER/UjzykH+5wE3ebVZnQ=="
},
"@silvia-odwyer/photon-node": {
"version": "0.3.1"
@ -6382,31 +6368,26 @@
}
},
"discord-api-types": {
"version": "0.33.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.1.tgz",
"integrity": "sha512-dc7Xzm3isROh77jdxikQnLzKDslOPORm2Q8odXrKgEy8Aqfd1r9ISVTU/xsHkH6bFo+Hjf1A1C5OnBtu8ghy4w=="
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.5.tgz",
"integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg=="
},
"discord.js": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.7.0.tgz",
"integrity": "sha512-iV/An3FEB/CiBGdjWHRtgskM4UuWPq5vjhjKsrQhdVU16dbKrBxA+eIV2HWA07B3tXUGM6eco1wkr42gxxV1BA==",
"version": "13.8.0",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.8.0.tgz",
"integrity": "sha512-EPAA/2VLycYN5wSzavqa4iJ6qj3UtQFtHw5TH/60Fj29ymfEsCQVn//o1mTpwDxzwb+rPIrWhkxKIGGnjfv0Iw==",
"requires": {
"@discordjs/builders": "^0.13.0",
"@discordjs/collection": "^0.6.0",
"@discordjs/builders": "^0.14.0",
"@discordjs/collection": "^0.7.0",
"@sapphire/async-queue": "^1.3.1",
"@types/node-fetch": "^2.6.1",
"@types/ws": "^8.5.3",
"discord-api-types": "^0.30.0",
"discord-api-types": "^0.33.3",
"form-data": "^4.0.0",
"node-fetch": "^2.6.1",
"ws": "^8.6.0"
"ws": "^8.7.0"
},
"dependencies": {
"discord-api-types": {
"version": "0.30.0",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.30.0.tgz",
"integrity": "sha512-wYst0jrT8EJs2tVlwUTQ2xT0oWMjUrRMpFTkNY3NMleWyQNHgWaKhqFfxdLPdC2im9IuR5EsxcEgjhf/npeftw=="
},
"form-data": {
"version": "4.0.0",
"requires": {

View file

@ -28,8 +28,8 @@
"cors": "^2.8.5",
"cross-env": "^5.2.0",
"deep-diff": "^1.0.2",
"discord-api-types": "^0.33.1",
"discord.js": "^13.7.0",
"discord-api-types": "^0.33.5",
"discord.js": "^13.8.0",
"dotenv": "^4.0.0",
"emoji-regex": "^8.0.0",
"erlpack": "github:discord/erlpack",

View file

@ -2,7 +2,14 @@
* @file Utility functions that are plugin-instance-specific (i.e. use PluginData)
*/
import { GuildMember, Message, MessageMentionOptions, MessageOptions, TextChannel } from "discord.js";
import {
GuildMember,
GuildTextBasedChannel,
Message,
MessageMentionOptions,
MessageOptions,
TextChannel,
} from "discord.js";
import * as t from "io-ts";
import { CommandContext, configUtils, ConfigValidationError, GuildPluginData, helpers, PluginOptions } from "knub";
import { PluginOverrideCriteria } from "knub/dist/config/configTypes";
@ -187,7 +194,7 @@ export function getPluginConfigPreprocessor(
export async function sendSuccessMessage(
pluginData: AnyPluginData<any>,
channel: TextChannel,
channel: GuildTextBasedChannel,
body: string,
allowedMentions?: MessageMentionOptions,
): Promise<Message | undefined> {

View file

@ -38,7 +38,7 @@ export const AlertAction = automodAction({
const channel = pluginData.guild.channels.cache.get(actionConfig.channel as Snowflake);
const logs = pluginData.getPlugin(LogsPlugin);
if (channel && channel instanceof TextChannel) {
if (channel?.isText()) {
const text = actionConfig.text;
const theMessageLink =
contexts[0].message && messageLink(pluginData.guild.id, contexts[0].message.channel_id, contexts[0].message.id);

View file

@ -36,7 +36,7 @@ export const ReplyAction = automodAction({
.filter((c) => c.message?.channel_id)
.filter((c) => {
const channel = pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake);
return channel instanceof TextChannel || channel instanceof ThreadChannel;
return channel?.isText();
});
const contextsByChannelId = contextsWithTextChannels.reduce((map: Map<string, AutomodContext[]>, context) => {

View file

@ -1,4 +1,4 @@
import { Snowflake, TextChannel } from "discord.js";
import { Snowflake } from "discord.js";
import { AllowedGuilds } from "../../data/AllowedGuilds";
import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments";
import { Configs } from "../../data/Configs";
@ -74,7 +74,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()({
const guild = await pluginData.client.guilds.fetch(guildId as Snowflake);
if (guild) {
const channel = guild.channels.cache.get(channelId as Snowflake);
if (channel instanceof TextChannel) {
if (channel?.isText()) {
sendSuccessMessage(pluginData, channel, "Global plugins reloaded!");
}
}

View file

@ -18,8 +18,7 @@ export async function postToCaseLogChannel(
if (!caseLogChannelId) return null;
const caseLogChannel = pluginData.guild.channels.cache.get(caseLogChannelId as Snowflake);
// This doesn't use `!isText() || isThread()` because TypeScript had some issues inferring types from it
if (!caseLogChannel || !(caseLogChannel instanceof TextChannel || caseLogChannel instanceof NewsChannel)) return null;
if (!caseLogChannel?.isText() || caseLogChannel.isThread()) return null;
let result: InternalPosterMessageResult | null = null;
try {

View file

@ -1,11 +1,4 @@
import {
Message,
MessageEditOptions,
NewsChannel,
TextChannel,
WebhookClient,
WebhookEditMessageOptions,
} from "discord.js";
import { Message, MessageEditOptions, WebhookClient, WebhookEditMessageOptions } from "discord.js";
import { GuildPluginData } from "knub";
import { InternalPosterPluginType } from "../types";
import { isDiscordAPIError, noop } from "../../../utils";
@ -18,12 +11,10 @@ export async function editMessage(
message: Message,
content: MessageEditOptions & WebhookEditMessageOptions,
): Promise<void> {
if (!(message.channel instanceof TextChannel || message.channel instanceof NewsChannel)) {
if (!message.channel.isText()) {
return;
}
const channel = message.channel as TextChannel | NewsChannel;
await pluginData.state.queue.add(async () => {
if (message.webhookId) {
const webhook = await pluginData.state.webhooks.find(message.webhookId);

View file

@ -1,11 +1,11 @@
import { GuildPluginData } from "knub";
import { InternalPosterPluginType } from "../types";
import { NewsChannel, TextChannel, WebhookClient } from "discord.js";
import { GuildTextBasedChannel, ThreadChannel, WebhookClient } from "discord.js";
import { getOrCreateWebhookForChannel } from "./getOrCreateWebhookForChannel";
export async function getOrCreateWebhookClientForChannel(
pluginData: GuildPluginData<InternalPosterPluginType>,
channel: TextChannel | NewsChannel,
channel: Exclude<GuildTextBasedChannel, ThreadChannel>,
): Promise<WebhookClient | null> {
if (!pluginData.state.webhookClientCache.has(channel.id)) {
const webhookInfo = await getOrCreateWebhookForChannel(pluginData, channel);

View file

@ -1,13 +1,13 @@
import { GuildPluginData } from "knub";
import { InternalPosterPluginType } from "../types";
import { NewsChannel, Permissions, TextChannel } from "discord.js";
import { GuildTextBasedChannel, Permissions, ThreadChannel } from "discord.js";
import { isDiscordAPIError } from "../../../utils";
type WebhookInfo = [id: string, token: string];
export async function getOrCreateWebhookForChannel(
pluginData: GuildPluginData<InternalPosterPluginType>,
channel: TextChannel | NewsChannel,
channel: Exclude<GuildTextBasedChannel, ThreadChannel>,
): Promise<WebhookInfo | null> {
// tslint:disable-next-line:no-console FIXME: Here for debugging purposes
console.log(`getOrCreateWebhookForChannel(${channel.id})`);

View file

@ -1,8 +1,6 @@
import { Message, MessageOptions, NewsChannel, TextChannel, WebhookClient } from "discord.js";
import { GuildTextBasedChannel, MessageOptions } from "discord.js";
import { GuildPluginData } from "knub";
import { InternalPosterPluginType } from "../types";
import { getOrCreateWebhookForChannel } from "./getOrCreateWebhookForChannel";
import { APIMessage } from "discord-api-types";
import { isDiscordAPIError } from "../../../utils";
import { getOrCreateWebhookClientForChannel } from "./getOrCreateWebhookClientForChannel";
@ -12,7 +10,7 @@ export type InternalPosterMessageResult = {
};
async function sendDirectly(
channel: TextChannel | NewsChannel,
channel: GuildTextBasedChannel,
content: MessageOptions,
): Promise<InternalPosterMessageResult | null> {
return channel.send(content).then((message) => ({
@ -26,11 +24,11 @@ async function sendDirectly(
*/
export async function sendMessage(
pluginData: GuildPluginData<InternalPosterPluginType>,
channel: TextChannel | NewsChannel,
channel: GuildTextBasedChannel,
content: MessageOptions,
): Promise<InternalPosterMessageResult | null> {
return pluginData.state.queue.add(async () => {
const webhookClient = await getOrCreateWebhookClientForChannel(pluginData, channel);
const webhookClient = !channel.isThread() ? await getOrCreateWebhookClientForChannel(pluginData, channel) : null;
if (!webhookClient) {
return sendDirectly(channel, content);
}

View file

@ -3,12 +3,12 @@ import { LogsPluginType } from "../types";
import { LogType } from "../../../data/LogType";
import { log } from "../util/log";
import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter";
import { BaseGuildTextChannel, ThreadChannel, User } from "discord.js";
import type { GuildTextBasedChannel, User } from "discord.js";
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
interface LogPostedScheduledMessageData {
author: User;
channel: BaseGuildTextChannel | ThreadChannel;
channel: GuildTextBasedChannel;
messageId: string;
}

View file

@ -1,4 +1,4 @@
import { Message, MessageAttachment, MessageOptions, NewsChannel, TextChannel, ThreadChannel } from "discord.js";
import { GuildTextBasedChannel, Message, MessageOptions, MessageAttachment } from "discord.js";
import fs from "fs";
import { GuildPluginData } from "knub";
import { downloadFile } from "../../../utils";
@ -9,7 +9,7 @@ const fsp = fs.promises;
export async function postMessage(
pluginData: GuildPluginData<PostPluginType>,
channel: TextChannel | NewsChannel | ThreadChannel,
channel: GuildTextBasedChannel,
content: MessageOptions,
attachments: MessageAttachment[] = [],
enableMentions: boolean = false,

View file

@ -1,4 +1,5 @@
import { Snowflake, TextChannel } from "discord.js";
import { ChannelFlags } from "discord-api-types/v10.js";
import { GuildTextBasedChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { getChannelIdFromMessageId } from "../data/getChannelIdFromMessageId";
import { isSnowflake } from "../utils";
@ -7,7 +8,7 @@ const channelAndMessageIdRegex = /^(\d+)[\-\/](\d+)$/;
const messageLinkRegex = /^https:\/\/(?:\w+\.)?discord(?:app)?\.com\/channels\/\d+\/(\d+)\/(\d+)$/i;
export interface MessageTarget {
channel: TextChannel;
channel: Exclude<GuildTextBasedChannel, ThreadChannel>;
messageId: string;
}
@ -47,7 +48,7 @@ export async function resolveMessageTarget(pluginData: GuildPluginData<any>, val
}
const channel = pluginData.guild.channels.resolve(result.channelId as Snowflake);
if (!channel || !(channel instanceof TextChannel)) {
if (!channel?.isText() || channel instanceof ThreadChannel) {
return null;
}