mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 18:25:03 +00:00
update discord.js
This commit is contained in:
parent
ba78103807
commit
ed4ba06f82
14 changed files with 81 additions and 104 deletions
|
@ -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);
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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})`);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue