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
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue