mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Start move to configAccessibleObjects, exclude perm overrides from logs
configAccessibleObjects are used to guarantee backwards compatibility and consistency. Perm overrides from our own plugins are ignored as to not spam logs through bot managed slowmode or companion channels
This commit is contained in:
parent
dda19de6e6
commit
d2dd103175
28 changed files with 259 additions and 75 deletions
|
@ -66,6 +66,7 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|||
afterLoad(pluginData) {
|
||||
const { state } = pluginData;
|
||||
|
||||
state.serverLogs = new GuildLogs(pluginData.guild.id);
|
||||
state.clearInterval = setInterval(() => clearExpiredSlowmodes(pluginData), BOT_SLOWMODE_CLEAR_INTERVAL);
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
|
|
|
@ -19,6 +19,7 @@ export interface SlowmodePluginType extends BasePluginType {
|
|||
savedMessages: GuildSavedMessages;
|
||||
logs: GuildLogs;
|
||||
clearInterval: NodeJS.Timeout;
|
||||
serverLogs: GuildLogs;
|
||||
|
||||
onMessageCreateFn;
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ export async function applyBotSlowmodeToUserId(
|
|||
// 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 });
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
|
||||
export async function clearBotSlowmodeFromUserId(
|
||||
|
@ -13,6 +14,7 @@ export async function clearBotSlowmodeFromUserId(
|
|||
// Previously we diffed the overrides so we could clear the "send messages" override without touching other
|
||||
// overrides. Unfortunately, it seems that was a bit buggy - we didn't always receive the event for the changed
|
||||
// overrides and then we also couldn't diff against them. For consistency's sake, we just delete the override now.
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channel.id, 3 * 1000);
|
||||
await channel.permissionOverwrites.resolve(userId as Snowflake)?.delete();
|
||||
} catch (e) {
|
||||
if (!force) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { GuildChannel, 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 { stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||
|
@ -22,10 +23,11 @@ export async function clearExpiredSlowmodes(pluginData: GuildPluginData<Slowmode
|
|||
|
||||
const realUser =
|
||||
pluginData.client.users!.fetch(user.user_id as Snowflake) || new UnknownUser({ id: user.user_id });
|
||||
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Failed to clear slowmode permissions from {userMention(user)} in {channelMention(channel)}`,
|
||||
user: stripObjectToScalars(realUser),
|
||||
channel: stripObjectToScalars(channel),
|
||||
user: userToConfigAccessibleUser(await realUser),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue