mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Auto mod blame wolf (#2267)
* feat(meister): add automod * fix(test); rest error with code * fix(rest): log error nicely * fix(test): disable benchmark test until gateway rewrite * fix(automod): enum should start with 1 * fix(helper): better undefined handling of metadata * fix(transfomrers): automod transformers * fix(tests): add some automod tests * Update types/shared.ts Co-authored-by: meister03 <69507874+meister03@users.noreply.github.com> * fix: changes discord made recently * fix(fmt): i hate deno fmt but i love itoh Co-authored-by: meister03 <69507874+meister03@users.noreply.github.com> Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
This commit is contained in:
co-authored by
meister03
LTS20050703
parent
4263b7b787
commit
ccd8506c81
@@ -0,0 +1,92 @@
|
||||
import { AutoModerationActionType, BotWithCache, PermissionStrings } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export function getAutomodRule(bot: BotWithCache) {
|
||||
const getAutomodRuleOld = bot.helpers.getAutomodRule;
|
||||
|
||||
bot.helpers.getAutomodRule = async function (guildId, ruleId) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await getAutomodRuleOld(guildId, ruleId);
|
||||
};
|
||||
}
|
||||
|
||||
export function getAutomodRules(bot: BotWithCache) {
|
||||
const getAutomodRulesOld = bot.helpers.getAutomodRules;
|
||||
|
||||
bot.helpers.getAutomodRules = async function (guildId) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await getAutomodRulesOld(guildId);
|
||||
};
|
||||
}
|
||||
|
||||
export function createAutomodRule(bot: BotWithCache) {
|
||||
const createAutomodRuleOld = bot.helpers.createAutomodRule;
|
||||
|
||||
bot.helpers.createAutomodRule = async function (guildId, options) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
for (const action of options.actions) {
|
||||
// Check for maximum duration seconds
|
||||
if (action.metadata?.durationSeconds && action.metadata.durationSeconds > 2419200) {
|
||||
console.log(
|
||||
`[Warning] Automod action duration seconds is too high: ${action.metadata.durationSeconds}. Setting to Discord's allowed maximum.`,
|
||||
);
|
||||
// Discords max is 4 weeks
|
||||
action.metadata.durationSeconds = 2419200;
|
||||
}
|
||||
|
||||
// Timeout actions require perm check
|
||||
if (action.type === AutoModerationActionType.Timeout) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MODERATE_MEMBERS"]);
|
||||
}
|
||||
}
|
||||
|
||||
return await createAutomodRuleOld(guildId, options);
|
||||
};
|
||||
}
|
||||
|
||||
export function editAutomodRule(bot: BotWithCache) {
|
||||
const editAutomodRuleOld = bot.helpers.editAutomodRule;
|
||||
|
||||
bot.helpers.editAutomodRule = async function (guildId, options) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
for (const action of options.actions ?? []) {
|
||||
// Check for maximum duration seconds
|
||||
if (action.metadata?.durationSeconds && action.metadata.durationSeconds > 2419200) {
|
||||
console.log(
|
||||
`[Warning] Automod action duration seconds is too high: ${action.metadata.durationSeconds}. Setting to Discord's allowed maximum.`,
|
||||
);
|
||||
// Discords max is 4 weeks
|
||||
action.metadata.durationSeconds = 2419200;
|
||||
}
|
||||
|
||||
// Timeout actions require perm check
|
||||
if (action.type === AutoModerationActionType.Timeout) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MODERATE_MEMBERS"]);
|
||||
}
|
||||
}
|
||||
|
||||
return await editAutomodRuleOld(guildId, options);
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteAutomodRule(bot: BotWithCache) {
|
||||
const deleteAutomodRuleOld = bot.helpers.deleteAutomodRule;
|
||||
|
||||
bot.helpers.deleteAutomodRule = async function (guildId, options) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await deleteAutomodRuleOld(guildId, options);
|
||||
};
|
||||
}
|
||||
|
||||
export default function setupAutoModerationPermChecks(bot: BotWithCache) {
|
||||
getAutomodRule(bot);
|
||||
getAutomodRules(bot);
|
||||
createAutomodRule(bot);
|
||||
editAutomodRule(bot);
|
||||
deleteAutomodRule(bot);
|
||||
}
|
||||
Reference in New Issue
Block a user