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

Update djs & knub (#395)

* update pkgs

Signed-off-by: GitHub <noreply@github.com>

* new knub typings

Signed-off-by: GitHub <noreply@github.com>

* more pkg updates

Signed-off-by: GitHub <noreply@github.com>

* more fixes

Signed-off-by: GitHub <noreply@github.com>

* channel typings

Signed-off-by: GitHub <noreply@github.com>

* more message utils typings fixes

Signed-off-by: GitHub <noreply@github.com>

* migrate permissions

Signed-off-by: GitHub <noreply@github.com>

* fix: InternalPoster webhookables

Signed-off-by: GitHub <noreply@github.com>

* djs typings: Attachment & Util

Signed-off-by: GitHub <noreply@github.com>

* more typings

Signed-off-by: GitHub <noreply@github.com>

* fix: rename permissionNames

Signed-off-by: GitHub <noreply@github.com>

* more fixes

Signed-off-by: GitHub <noreply@github.com>

* half the number of errors

* knub commands => messageCommands

Signed-off-by: GitHub <noreply@github.com>

* configPreprocessor => configParser

Signed-off-by: GitHub <noreply@github.com>

* fix channel.messages

Signed-off-by: GitHub <noreply@github.com>

* revert automod any typing

Signed-off-by: GitHub <noreply@github.com>

* more configParser typings

Signed-off-by: GitHub <noreply@github.com>

* revert

Signed-off-by: GitHub <noreply@github.com>

* remove knub type params

Signed-off-by: GitHub <noreply@github.com>

* fix more MessageEmbed / MessageOptions

Signed-off-by: GitHub <noreply@github.com>

* dumb commit for @almeidx to see why this is stupid

Signed-off-by: GitHub <noreply@github.com>

* temp disable custom_events

Signed-off-by: GitHub <noreply@github.com>

* more minor typings fixes - 23 err left

Signed-off-by: GitHub <noreply@github.com>

* update djs dep

* +debug build method (revert this)

Signed-off-by: GitHub <noreply@github.com>

* Revert "+debug build method (revert this)"

This reverts commit a80af1e729.

* Redo +debug build (Revert this)

Signed-off-by: GitHub <noreply@github.com>

* uniform before/after Load shorthands

Signed-off-by: GitHub <noreply@github.com>

* remove unused imports & add prettier plugin

Signed-off-by: GitHub <noreply@github.com>

* env fixes for web platform hosting

Signed-off-by: GitHub <noreply@github.com>

* feat: knub v32-next; related fixes

* fix: allow legacy keys in change_perms action

* fix: request Message Content intent

* fix: use Knub's config validation logic in API

* fix(dashboard): fix error when there are no message and/or slash commands in a plugin

* fix(automod): start_thread action thread options

* fix(CustomEvents): message command types

* chore: remove unneeded type annotation

* feat: add forum channel icon; use thread icon for news threads

* chore: make tslint happy

* chore: fix formatting

---------

Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: almeidx <almeidx@pm.me>
Co-authored-by: Dragory <2606411+Dragory@users.noreply.github.com>
This commit is contained in:
Tiago R 2023-04-01 12:58:17 +01:00 committed by GitHub
parent 293115af22
commit 06877e90cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
476 changed files with 2965 additions and 3251 deletions

View file

@ -1,7 +1,10 @@
import { PluginOptions } from "knub";
import { onGuildEvent } from "../../data/GuildEvents";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { GuildScheduledPosts } from "../../data/GuildScheduledPosts";
import { makeIoTsConfigParser } from "../../pluginUtils";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { EditCmd } from "./commands/EditCmd";
@ -12,8 +15,6 @@ import { ScheduledPostsDeleteCmd } from "./commands/ScheduledPostsDeleteCmd";
import { ScheduledPostsListCmd } from "./commands/ScheduledPostsListCmd";
import { ScheduledPostsShowCmd } from "./commands/ScheduledPostsShowCmd";
import { ConfigSchema, PostPluginType } from "./types";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { onGuildEvent } from "../../data/GuildEvents";
import { postScheduledPost } from "./util/postScheduledPost";
const defaultOptions: PluginOptions<PostPluginType> = {
@ -35,14 +36,15 @@ export const PostPlugin = zeppelinGuildPlugin<PostPluginType>()({
showInDocs: true,
info: {
prettyName: "Post",
configSchema: ConfigSchema,
},
dependencies: () => [TimeAndDatePlugin, LogsPlugin],
configSchema: ConfigSchema,
configParser: makeIoTsConfigParser(ConfigSchema),
defaultOptions,
// prettier-ignore
commands: [
messageCommands: [
PostCmd,
PostEmbedCmd,
EditCmd,
@ -61,12 +63,16 @@ export const PostPlugin = zeppelinGuildPlugin<PostPluginType>()({
},
afterLoad(pluginData) {
pluginData.state.unregisterGuildEventListener = onGuildEvent(pluginData.guild.id, "scheduledPost", (post) =>
const { state, guild } = pluginData;
state.unregisterGuildEventListener = onGuildEvent(guild.id, "scheduledPost", (post) =>
postScheduledPost(pluginData, post),
);
},
beforeUnload(pluginData) {
pluginData.state.unregisterGuildEventListener?.();
const { state } = pluginData;
state.unregisterGuildEventListener?.();
},
});

View file

@ -1,4 +1,3 @@
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { postCmd } from "../types";

View file

@ -1,4 +1,4 @@
import { MessageEmbed, Snowflake, TextChannel } from "discord.js";
import { APIEmbed } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { trimLines } from "../../../utils";
@ -42,7 +42,7 @@ export const EditEmbedCmd = postCmd({
return;
}
const embed = (targetMessage.embeds![0] ?? { fields: [] }) as MessageEmbed;
const embed = (targetMessage.embeds![0] ?? { fields: [] }) as APIEmbed;
if (args.title) embed.title = args.title;
if (content) embed.description = formatContent(content);
if (color) embed.color = color;

View file

@ -1,4 +1,4 @@
import { MessageEmbedOptions } from "discord.js";
import { APIEmbed } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { isValidEmbed, trimLines } from "../../../utils";
@ -46,7 +46,7 @@ export const PostEmbedCmd = postCmd({
}
}
let embed: MessageEmbedOptions = {};
let embed: APIEmbed = {};
if (args.title) embed.title = args.title;
if (color) embed.color = color;

View file

@ -1,8 +1,8 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { clearUpcomingScheduledPost } from "../../../data/loops/upcomingScheduledPostsLoop";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { sorter } from "../../../utils";
import { postCmd } from "../types";
import { clearUpcomingScheduledPost } from "../../../data/loops/upcomingScheduledPostsLoop";
export const ScheduledPostsDeleteCmd = postCmd({
trigger: ["scheduled_posts delete", "scheduled_posts d"],

View file

@ -1,4 +1,4 @@
import { Util } from "discord.js";
import { escapeCodeBlock } from "discord.js";
import humanizeDuration from "humanize-duration";
import moment from "moment-timezone";
import { createChunkedMessage, DBDateFormat, deactivateMentions, sorter, trimLines } from "../../../utils";
@ -26,7 +26,7 @@ export const ScheduledPostsListCmd = postCmd({
const isTruncated = previewText.length > SCHEDULED_POST_PREVIEW_TEXT_LENGTH;
previewText = Util.escapeCodeBlock(deactivateMentions(previewText))
previewText = escapeCodeBlock(deactivateMentions(previewText))
.replace(/\s+/g, " ")
.slice(0, SCHEDULED_POST_PREVIEW_TEXT_LENGTH);

View file

@ -1,4 +1,3 @@
import { TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { sorter } from "../../../utils";
@ -22,6 +21,6 @@ export const ScheduledPostsShowCmd = postCmd({
return;
}
postMessage(pluginData, msg.channel as TextChannel, post.content, post.attachments, post.enable_mentions);
postMessage(pluginData, msg.channel, post.content, post.attachments, post.enable_mentions);
},
});

View file

@ -1,5 +1,5 @@
import * as t from "io-ts";
import { BasePluginType, typedGuildCommand } from "knub";
import { BasePluginType, guildPluginMessageCommand } from "knub";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { GuildScheduledPosts } from "../../data/GuildScheduledPosts";
@ -20,4 +20,4 @@ export interface PostPluginType extends BasePluginType {
};
}
export const postCmd = typedGuildCommand<PostPluginType>();
export const postCmd = guildPluginMessageCommand<PostPluginType>();

View file

@ -1,17 +1,15 @@
import { Channel, GuildTextBasedChannel, Message, NewsChannel, TextChannel, ThreadChannel } from "discord.js";
import { GuildTextBasedChannel, Message } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { LogType } from "../../../data/LogType";
import { registerUpcomingScheduledPost } from "../../../data/loops/upcomingScheduledPostsLoop";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { DBDateFormat, errorMessage, MINUTES, StrictMessageContent } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { PostPluginType } from "../types";
import { parseScheduleTime } from "./parseScheduleTime";
import { postMessage } from "./postMessage";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { registerUpcomingScheduledPost } from "../../../data/loops/upcomingScheduledPostsLoop";
const MIN_REPEAT_TIME = 5 * MINUTES;
const MAX_REPEAT_TIME = Math.pow(2, 32);
@ -30,7 +28,7 @@ export async function actualPostCmd(
"repeat-times"?: number;
} = {},
) {
if (!targetChannel.isText()) {
if (!targetChannel.isTextBased()) {
msg.channel.send(errorMessage("Specified channel is not a text-based channel"));
return;
}
@ -42,19 +40,11 @@ export async function actualPostCmd(
if (opts.repeat) {
if (opts.repeat < MIN_REPEAT_TIME) {
sendErrorMessage(
pluginData,
msg.channel as TextChannel,
`Minimum time for -repeat is ${humanizeDuration(MIN_REPEAT_TIME)}`,
);
sendErrorMessage(pluginData, msg.channel, `Minimum time for -repeat is ${humanizeDuration(MIN_REPEAT_TIME)}`);
return;
}
if (opts.repeat > MAX_REPEAT_TIME) {
sendErrorMessage(
pluginData,
msg.channel as TextChannel,
`Max time for -repeat is ${humanizeDuration(MAX_REPEAT_TIME)}`,
);
sendErrorMessage(pluginData, msg.channel, `Max time for -repeat is ${humanizeDuration(MAX_REPEAT_TIME)}`);
return;
}
}
@ -65,7 +55,7 @@ export async function actualPostCmd(
// Schedule the post to be posted later
postAt = await parseScheduleTime(pluginData, msg.author.id, opts.schedule);
if (!postAt) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Invalid schedule time");
sendErrorMessage(pluginData, msg.channel, "Invalid schedule time");
return;
}
} else if (opts.repeat) {
@ -82,17 +72,17 @@ export async function actualPostCmd(
// Invalid time
if (!repeatUntil) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Invalid time specified for -repeat-until");
sendErrorMessage(pluginData, msg.channel, "Invalid time specified for -repeat-until");
return;
}
if (repeatUntil.isBefore(moment.utc())) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "You can't set -repeat-until in the past");
sendErrorMessage(pluginData, msg.channel, "You can't set -repeat-until in the past");
return;
}
if (repeatUntil.isAfter(MAX_REPEAT_UNTIL)) {
sendErrorMessage(
pluginData,
msg.channel as TextChannel,
msg.channel,
"Unfortunately, -repeat-until can only be at most 100 years into the future. Maybe 99 years would be enough?",
);
return;
@ -100,26 +90,18 @@ export async function actualPostCmd(
} else if (opts["repeat-times"]) {
repeatTimes = opts["repeat-times"];
if (repeatTimes <= 0) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "-repeat-times must be 1 or more");
sendErrorMessage(pluginData, msg.channel, "-repeat-times must be 1 or more");
return;
}
}
if (repeatUntil && repeatTimes) {
sendErrorMessage(
pluginData,
msg.channel as TextChannel,
"You can only use one of -repeat-until or -repeat-times at once",
);
sendErrorMessage(pluginData, msg.channel, "You can only use one of -repeat-until or -repeat-times at once");
return;
}
if (opts.repeat && !repeatUntil && !repeatTimes) {
sendErrorMessage(
pluginData,
msg.channel as TextChannel,
"You must specify -repeat-until or -repeat-times for repeated messages",
);
sendErrorMessage(pluginData, msg.channel, "You must specify -repeat-until or -repeat-times for repeated messages");
return;
}
@ -134,7 +116,7 @@ export async function actualPostCmd(
// Save schedule/repeat information in DB
if (postAt) {
if (postAt < moment.utc()) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Post can't be scheduled to be posted in the past");
sendErrorMessage(pluginData, msg.channel, "Post can't be scheduled to be posted in the past");
return;
}
@ -210,6 +192,6 @@ export async function actualPostCmd(
}
if (targetChannel.id !== msg.channel.id || opts.schedule || opts.repeat) {
sendSuccessMessage(pluginData, msg.channel as TextChannel, successMessage);
sendSuccessMessage(pluginData, msg.channel, successMessage);
}
}

View file

@ -1,12 +1,4 @@
import {
GuildTextBasedChannel,
Message,
MessageAttachment,
MessageOptions,
NewsChannel,
TextChannel,
ThreadChannel,
} from "discord.js";
import { Attachment, GuildTextBasedChannel, Message, MessageCreateOptions } from "discord.js";
import fs from "fs";
import { GuildPluginData } from "knub";
import { downloadFile } from "../../../utils";
@ -18,8 +10,8 @@ const fsp = fs.promises;
export async function postMessage(
pluginData: GuildPluginData<PostPluginType>,
channel: GuildTextBasedChannel,
content: MessageOptions,
attachments: MessageAttachment[] = [],
content: MessageCreateOptions,
attachments: Attachment[] = [],
enableMentions: boolean = false,
): Promise<Message> {
if (typeof content === "string") {

View file

@ -1,13 +1,13 @@
import { Snowflake, TextChannel, User } from "discord.js";
import { Snowflake, User } from "discord.js";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { logger } from "../../../logger";
import { DBDateFormat, verboseChannelMention, verboseUserMention } from "../../../utils";
import { PostPluginType } from "../types";
import { postMessage } from "./postMessage";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { ScheduledPost } from "../../../data/entities/ScheduledPost";
import { registerUpcomingScheduledPost } from "../../../data/loops/upcomingScheduledPostsLoop";
import { logger } from "../../../logger";
import { DBDateFormat, verboseChannelMention, verboseUserMention } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { PostPluginType } from "../types";
import { postMessage } from "./postMessage";
export async function postScheduledPost(pluginData: GuildPluginData<PostPluginType>, post: ScheduledPost) {
// First, update the scheduled post or delete it from the database *before* we try posting it.
@ -45,7 +45,7 @@ export async function postScheduledPost(pluginData: GuildPluginData<PostPluginTy
// Post the message
const channel = pluginData.guild.channels.cache.get(post.channel_id as Snowflake);
if (channel?.isText() || channel?.isThread()) {
if (channel?.isTextBased() || channel?.isThread()) {
const [username, discriminator] = post.author_name.split("#");
const author: User = (await pluginData.client.users.fetch(post.author_id as Snowflake)) || {
id: post.author_id,