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

More fixes, change rest of stripObjectToScalars to configAccessibleObj

This commit is contained in:
Dark 2021-07-21 22:14:09 +02:00
parent 4ad99975de
commit acb4913495
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
66 changed files with 623 additions and 192 deletions

View file

@ -1,3 +1,4 @@
import { ChannelTypeStrings } from "src/types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { asSingleLine, disableInlineCode } from "../../../utils";
@ -37,7 +38,19 @@ export const SlowmodeClearCmd = slowmodeCmd({
}
try {
await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force);
if (args.channel.type === ChannelTypeStrings.TEXT) {
await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force);
} else {
sendErrorMessage(
pluginData,
msg.channel,
asSingleLine(`
Failed to clear slowmode from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>:
Threads cannot have Bot Slowmode
`),
);
return;
}
} catch (e) {
sendErrorMessage(
pluginData,

View file

@ -1,5 +1,6 @@
import { Permissions, TextChannel } from "discord.js";
import { Permissions, TextChannel, ThreadChannel } 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, disableInlineCode, HOURS, MINUTES } from "../../../utils";
@ -38,7 +39,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
],
async run({ message: msg, args, pluginData }) {
const channel: TextChannel = args.channel || msg.channel;
const channel: TextChannel | ThreadChannel = args.channel || msg.channel;
if (args.time === 0) {
// Workaround until we can call SlowmodeDisableCmd from here
@ -122,7 +123,7 @@ 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) {
if (existingBotSlowmode && channel.type === ChannelTypeStrings.TEXT) {
await disableBotSlowmodeForChannel(pluginData, channel);
}

View file

@ -1,5 +1,6 @@
import { GuildChannel, Permissions, Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger";
import { isDiscordAPIError, stripObjectToScalars, UnknownUser } from "../../../utils";
@ -20,7 +21,7 @@ export async function applyBotSlowmodeToUserId(
await channel.permissionOverwrites.create(userId as Snowflake, { SEND_MESSAGES: false }, { type: 1 });
}
} catch (e) {
const user = pluginData.client.users.fetch(userId as Snowflake) || new UnknownUser({ id: userId });
const user = (await pluginData.client.users.fetch(userId as Snowflake)) || new UnknownUser({ id: userId });
if (isDiscordAPIError(e) && e.code === 50013) {
logger.warn(
@ -28,14 +29,14 @@ export async function applyBotSlowmodeToUserId(
);
pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Missing permissions to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
user: stripObjectToScalars(user),
channel: stripObjectToScalars(channel),
user: userToConfigAccessibleUser(user),
channel: channelToConfigAccessibleChannel(channel),
});
} else {
pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Failed to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
user: stripObjectToScalars(user),
channel: stripObjectToScalars(channel),
user: userToConfigAccessibleUser(user),
channel: channelToConfigAccessibleChannel(channel),
});
throw e;
}

View file

@ -1,11 +1,11 @@
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
import { GuildChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../data/LogType";
import { SlowmodePluginType } from "../types";
export async function clearBotSlowmodeFromUserId(
pluginData: GuildPluginData<SlowmodePluginType>,
channel: GuildChannel & TextChannel,
channel: TextChannel,
userId: string,
force = false,
) {

View file

@ -1,11 +1,11 @@
import { GuildChannel, TextChannel } from "discord.js";
import { GuildChannel, TextChannel, ThreadChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { SlowmodePluginType } from "../types";
import { clearBotSlowmodeFromUserId } from "./clearBotSlowmodeFromUserId";
export async function disableBotSlowmodeForChannel(
pluginData: GuildPluginData<SlowmodePluginType>,
channel: GuildChannel & TextChannel,
channel: TextChannel,
) {
// Disable channel slowmode
await pluginData.state.slowmodes.deleteChannelSlowmode(channel.id);