mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +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:
parent
293115af22
commit
06877e90cc
476 changed files with 2965 additions and 3251 deletions
|
@ -2,6 +2,7 @@ import { PluginOptions } from "knub";
|
|||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { GuildSlowmodes } from "../../data/GuildSlowmodes";
|
||||
import { makeIoTsConfigParser } from "../../pluginUtils";
|
||||
import { SECONDS } from "../../utils";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
|
@ -40,6 +41,7 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|||
showInDocs: true,
|
||||
info: {
|
||||
prettyName: "Slowmode",
|
||||
configSchema: ConfigSchema,
|
||||
},
|
||||
|
||||
// prettier-ignore
|
||||
|
@ -47,11 +49,11 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|||
LogsPlugin,
|
||||
],
|
||||
|
||||
configSchema: ConfigSchema,
|
||||
configParser: makeIoTsConfigParser(ConfigSchema),
|
||||
defaultOptions,
|
||||
|
||||
// prettier-ignore
|
||||
commands: [
|
||||
messageCommands: [
|
||||
SlowmodeDisableCmd,
|
||||
SlowmodeClearCmd,
|
||||
SlowmodeListCmd,
|
||||
|
@ -79,7 +81,9 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|||
},
|
||||
|
||||
beforeUnload(pluginData) {
|
||||
pluginData.state.savedMessages.events.off("create", pluginData.state.onMessageCreateFn);
|
||||
clearInterval(pluginData.state.clearInterval);
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.savedMessages.events.off("create", state.onMessageCreateFn);
|
||||
clearInterval(state.clearInterval);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Util } from "discord.js";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
import { ChannelType, escapeInlineCode } from "discord.js";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { asSingleLine } from "../../../utils";
|
||||
|
@ -39,7 +38,7 @@ export const SlowmodeClearCmd = slowmodeCmd({
|
|||
}
|
||||
|
||||
try {
|
||||
if (args.channel.type === ChannelTypeStrings.TEXT) {
|
||||
if (args.channel.type === ChannelType.GuildText) {
|
||||
await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force);
|
||||
} else {
|
||||
sendErrorMessage(
|
||||
|
@ -58,7 +57,7 @@ export const SlowmodeClearCmd = slowmodeCmd({
|
|||
msg.channel,
|
||||
asSingleLine(`
|
||||
Failed to clear slowmode from **${args.user.tag}** in <#${args.channel.id}>:
|
||||
\`${Util.escapeInlineCode(e.message)}\`
|
||||
\`${escapeInlineCode(e.message)}\`
|
||||
`),
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { TextChannel } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { slowmodeCmd } from "../types";
|
||||
|
@ -13,7 +12,7 @@ export const SlowmodeGetCmd = slowmodeCmd({
|
|||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const channel = args.channel || (msg.channel as TextChannel);
|
||||
const channel = args.channel || msg.channel;
|
||||
|
||||
let currentSlowmode = channel.rateLimitPerUser;
|
||||
let isNative = true;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { GuildChannel, TextChannel } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { createChunkedMessage } from "knub/dist/helpers";
|
||||
import { createChunkedMessage } from "knub/helpers";
|
||||
import { errorMessage } from "../../../utils";
|
||||
import { slowmodeCmd } from "../types";
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Permissions, TextChannel, ThreadChannel, Util } from "discord.js";
|
||||
import { escapeInlineCode, PermissionsBitField } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { asSingleLine, DAYS, HOURS, MINUTES } from "../../../utils";
|
||||
|
@ -23,7 +22,6 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
permission: "can_manage",
|
||||
source: "guild",
|
||||
|
||||
// prettier-ignore
|
||||
signature: [
|
||||
{
|
||||
time: ct.delay(),
|
||||
|
@ -35,11 +33,16 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
time: ct.delay(),
|
||||
|
||||
mode: ct.string({ option: true, shortcut: "m" }),
|
||||
}
|
||||
},
|
||||
],
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const channel: TextChannel | ThreadChannel = args.channel || msg.channel;
|
||||
const channel = args.channel || msg.channel;
|
||||
|
||||
if (!channel.isTextBased() || channel.isThread()) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Slowmode can only be set on non-thread text-based channels");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.time === 0) {
|
||||
// Workaround until we can call SlowmodeDisableCmd from here
|
||||
|
@ -89,7 +92,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
|
||||
if (mode === "native") {
|
||||
const missingPermissions = getMissingPermissions(
|
||||
channelPermissions ?? new Permissions(),
|
||||
channelPermissions ?? new PermissionsBitField(),
|
||||
NATIVE_SLOWMODE_PERMISSIONS,
|
||||
);
|
||||
if (missingPermissions) {
|
||||
|
@ -104,7 +107,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
|
||||
if (mode === "bot") {
|
||||
const missingPermissions = getMissingPermissions(
|
||||
channelPermissions ?? new Permissions(),
|
||||
channelPermissions ?? new PermissionsBitField(),
|
||||
BOT_SLOWMODE_PERMISSIONS,
|
||||
);
|
||||
if (missingPermissions) {
|
||||
|
@ -123,25 +126,21 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
if (mode === "native") {
|
||||
// If there is an existing bot-maintained slowmode, disable that first
|
||||
const existingBotSlowmode = await pluginData.state.slowmodes.getChannelSlowmode(channel.id);
|
||||
if (existingBotSlowmode && channel.type === ChannelTypeStrings.TEXT) {
|
||||
if (existingBotSlowmode && channel.isTextBased()) {
|
||||
await disableBotSlowmodeForChannel(pluginData, channel);
|
||||
}
|
||||
|
||||
// Set native slowmode
|
||||
try {
|
||||
await channel.edit({
|
||||
rateLimitPerUser: rateLimitSeconds,
|
||||
});
|
||||
await channel.setRateLimitPerUser(rateLimitSeconds);
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Failed to set native slowmode: ${Util.escapeInlineCode(e.message)}`);
|
||||
sendErrorMessage(pluginData, msg.channel, `Failed to set native slowmode: ${escapeInlineCode(e.message)}`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// If there is an existing native slowmode, disable that first
|
||||
if (channel.rateLimitPerUser) {
|
||||
await channel.edit({
|
||||
rateLimitPerUser: 0,
|
||||
});
|
||||
await channel.setRateLimitPerUser(0);
|
||||
}
|
||||
|
||||
// Set bot-maintained slowmode
|
||||
|
@ -149,7 +148,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
|
||||
// Update cache
|
||||
const slowmode = await pluginData.state.slowmodes.getChannelSlowmode(channel.id);
|
||||
await pluginData.state.channelSlowmodeCache.set(channel.id, slowmode ?? null);
|
||||
pluginData.state.channelSlowmodeCache.set(channel.id, slowmode ?? null);
|
||||
}
|
||||
|
||||
const humanizedSlowmodeTime = humanizeDuration(args.time);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Permissions } from "discord.js";
|
||||
import { PermissionsBitField } from "discord.js";
|
||||
|
||||
const p = Permissions.FLAGS;
|
||||
const p = PermissionsBitField.Flags;
|
||||
|
||||
export const NATIVE_SLOWMODE_PERMISSIONS = p.VIEW_CHANNEL | p.MANAGE_CHANNELS;
|
||||
export const BOT_SLOWMODE_PERMISSIONS = p.VIEW_CHANNEL | p.MANAGE_ROLES | p.MANAGE_MESSAGES;
|
||||
export const BOT_SLOWMODE_CLEAR_PERMISSIONS = p.VIEW_CHANNEL | p.MANAGE_ROLES;
|
||||
export const BOT_SLOWMODE_DISABLE_PERMISSIONS = p.VIEW_CHANNEL | p.MANAGE_ROLES;
|
||||
export const NATIVE_SLOWMODE_PERMISSIONS = p.ViewChannel | p.ManageChannels;
|
||||
export const BOT_SLOWMODE_PERMISSIONS = p.ViewChannel | p.ManageRoles | p.ManageMessages;
|
||||
export const BOT_SLOWMODE_CLEAR_PERMISSIONS = p.ViewChannel | p.ManageRoles;
|
||||
export const BOT_SLOWMODE_DISABLE_PERMISSIONS = p.ViewChannel | p.ManageRoles;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as t from "io-ts";
|
||||
import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub";
|
||||
import { BasePluginType, guildPluginEventListener, guildPluginMessageCommand } from "knub";
|
||||
import { SlowmodeChannel } from "../../data/entities/SlowmodeChannel";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { GuildSlowmodes } from "../../data/GuildSlowmodes";
|
||||
import { SlowmodeChannel } from "../../data/entities/SlowmodeChannel";
|
||||
|
||||
export const ConfigSchema = t.type({
|
||||
use_native_slowmode: t.boolean,
|
||||
|
@ -27,5 +27,5 @@ export interface SlowmodePluginType extends BasePluginType {
|
|||
};
|
||||
}
|
||||
|
||||
export const slowmodeCmd = typedGuildCommand<SlowmodePluginType>();
|
||||
export const slowmodeEvt = typedGuildEventListener<SlowmodePluginType>();
|
||||
export const slowmodeCmd = guildPluginMessageCommand<SlowmodePluginType>();
|
||||
export const slowmodeEvt = guildPluginEventListener<SlowmodePluginType>();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Message, TextChannel } from "discord.js";
|
||||
import { Message } from "discord.js";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { noop } from "../../../utils";
|
||||
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
|
||||
|
@ -11,7 +11,7 @@ export async function actualDisableSlowmodeCmd(msg: Message, args, pluginData) {
|
|||
const hasNativeSlowmode = args.channel.rateLimitPerUser;
|
||||
|
||||
if (!botSlowmode && hasNativeSlowmode === 0) {
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Channel is not on slowmode!");
|
||||
sendErrorMessage(pluginData, msg.channel, "Channel is not on slowmode!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ export async function actualDisableSlowmodeCmd(msg: Message, args, pluginData) {
|
|||
if (missingPermissions) {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
msg.channel,
|
||||
`Unable to disable slowmode. ${missingPermissionError(missingPermissions)}`,
|
||||
);
|
||||
return;
|
||||
|
@ -43,11 +43,11 @@ export async function actualDisableSlowmodeCmd(msg: Message, args, pluginData) {
|
|||
if (failedUsers.length) {
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
msg.channel,
|
||||
`Slowmode disabled! Failed to clear slowmode from the following users:\n\n<@!${failedUsers.join(">\n<@!")}>`,
|
||||
);
|
||||
} else {
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, "Slowmode disabled!");
|
||||
sendSuccessMessage(pluginData, msg.channel, "Slowmode disabled!");
|
||||
initMsg.delete().catch(noop);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,27 @@
|
|||
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildTextBasedChannel, Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { isDiscordAPIError, UnknownUser, verboseChannelMention, verboseUserMention } from "../../../utils";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
|
||||
export async function applyBotSlowmodeToUserId(
|
||||
pluginData: GuildPluginData<SlowmodePluginType>,
|
||||
channel: GuildChannel & TextChannel,
|
||||
channel: GuildTextBasedChannel,
|
||||
userId: string,
|
||||
) {
|
||||
// FIXME: Is there a better way to do this?
|
||||
if (channel.isThread()) return;
|
||||
|
||||
// Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account.
|
||||
const existingOverride = channel.permissionOverwrites?.resolve(userId as Snowflake);
|
||||
try {
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channel.id, 5 * 1000);
|
||||
if (existingOverride) {
|
||||
await existingOverride.edit({ SEND_MESSAGES: false });
|
||||
await existingOverride.edit({ SendMessages: false });
|
||||
} else {
|
||||
await channel.permissionOverwrites?.create(userId as Snowflake, { SEND_MESSAGES: false }, { type: 1 });
|
||||
await channel.permissionOverwrites?.create(userId as Snowflake, { SendMessages: false }, { type: 1 });
|
||||
}
|
||||
} catch (e) {
|
||||
const user = await pluginData.client.users.fetch(userId as Snowflake).catch(() => new UnknownUser({ id: userId }));
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { AnyThreadChannel, GuildTextBasedChannel, Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
|
||||
export async function clearBotSlowmodeFromUserId(
|
||||
pluginData: GuildPluginData<SlowmodePluginType>,
|
||||
channel: TextChannel,
|
||||
channel: Exclude<GuildTextBasedChannel, AnyThreadChannel>,
|
||||
userId: string,
|
||||
force = false,
|
||||
) {
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { UnknownUser, verboseChannelMention, verboseUserMention } from "../../../utils";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
import { clearBotSlowmodeFromUserId } from "./clearBotSlowmodeFromUserId";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
export async function clearExpiredSlowmodes(pluginData: GuildPluginData<SlowmodePluginType>) {
|
||||
const expiredSlowmodeUsers = await pluginData.state.slowmodes.getExpiredSlowmodeUsers();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { TextChannel } from "discord.js";
|
||||
import { AnyThreadChannel, GuildTextBasedChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
import { clearBotSlowmodeFromUserId } from "./clearBotSlowmodeFromUserId";
|
||||
|
||||
export async function disableBotSlowmodeForChannel(
|
||||
pluginData: GuildPluginData<SlowmodePluginType>,
|
||||
channel: TextChannel,
|
||||
channel: Exclude<GuildTextBasedChannel, AnyThreadChannel>,
|
||||
) {
|
||||
// Disable channel slowmode
|
||||
await pluginData.state.slowmodes.deleteChannelSlowmode(channel.id);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { ChannelType, GuildTextBasedChannel, Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { SlowmodeChannel } from "../../../data/entities/SlowmodeChannel";
|
||||
import { hasPermission } from "../../../pluginUtils";
|
||||
import { resolveMember } from "../../../utils";
|
||||
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
|
||||
|
@ -10,13 +11,12 @@ import { LogsPlugin } from "../../Logs/LogsPlugin";
|
|||
import { BOT_SLOWMODE_PERMISSIONS } from "../requiredPermissions";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
import { applyBotSlowmodeToUserId } from "./applyBotSlowmodeToUserId";
|
||||
import { SlowmodeChannel } from "../../../data/entities/SlowmodeChannel";
|
||||
|
||||
export async function onMessageCreate(pluginData: GuildPluginData<SlowmodePluginType>, msg: SavedMessage) {
|
||||
if (msg.is_bot) return;
|
||||
|
||||
const channel = pluginData.guild.channels.cache.get(msg.channel_id as Snowflake) as TextChannel;
|
||||
if (!channel) return;
|
||||
const channel = pluginData.guild.channels.cache.get(msg.channel_id as Snowflake) as GuildTextBasedChannel;
|
||||
if (!channel?.isTextBased() || channel.type === ChannelType.GuildStageVoice) return;
|
||||
|
||||
// Don't apply slowmode if the lock was interrupted earlier (e.g. the message was caught by word filters)
|
||||
const thisMsgLock = await pluginData.locks.acquire(messageLock(msg));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue