mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 02:25:01 +00:00
initial
This commit is contained in:
parent
ff160be1fa
commit
c541063ef3
2 changed files with 59 additions and 0 deletions
|
@ -6,6 +6,7 @@ import { AlertAction } from "./alert";
|
||||||
import { ArchiveThreadAction } from "./archiveThread";
|
import { ArchiveThreadAction } from "./archiveThread";
|
||||||
import { BanAction } from "./ban";
|
import { BanAction } from "./ban";
|
||||||
import { ChangeNicknameAction } from "./changeNickname";
|
import { ChangeNicknameAction } from "./changeNickname";
|
||||||
|
import { ChangePermsAction } from "./changePerms";
|
||||||
import { CleanAction } from "./clean";
|
import { CleanAction } from "./clean";
|
||||||
import { KickAction } from "./kick";
|
import { KickAction } from "./kick";
|
||||||
import { LogAction } from "./log";
|
import { LogAction } from "./log";
|
||||||
|
@ -36,6 +37,7 @@ export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
|
||||||
set_slowmode: SetSlowmodeAction,
|
set_slowmode: SetSlowmodeAction,
|
||||||
start_thread: StartThreadAction,
|
start_thread: StartThreadAction,
|
||||||
archive_thread: ArchiveThreadAction,
|
archive_thread: ArchiveThreadAction,
|
||||||
|
change_perms: ChangePermsAction,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AvailableActions = t.type({
|
export const AvailableActions = t.type({
|
||||||
|
@ -56,4 +58,5 @@ export const AvailableActions = t.type({
|
||||||
set_slowmode: SetSlowmodeAction.configType,
|
set_slowmode: SetSlowmodeAction.configType,
|
||||||
start_thread: StartThreadAction.configType,
|
start_thread: StartThreadAction.configType,
|
||||||
archive_thread: ArchiveThreadAction.configType,
|
archive_thread: ArchiveThreadAction.configType,
|
||||||
|
change_perms: ChangePermsAction.configType,
|
||||||
});
|
});
|
||||||
|
|
56
backend/src/plugins/Automod/actions/changePerms.ts
Normal file
56
backend/src/plugins/Automod/actions/changePerms.ts
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import { Permissions, PermissionString } from "discord.js";
|
||||||
|
import * as t from "io-ts";
|
||||||
|
import { automodAction } from "../helpers";
|
||||||
|
import { tNullable, isValidSnowflake } from "../../../utils";
|
||||||
|
import { noop } from "knub/dist/utils";
|
||||||
|
|
||||||
|
export const ChangePermsAction = automodAction({
|
||||||
|
configType: t.type({
|
||||||
|
target: t.string,
|
||||||
|
channel: tNullable(t.string),
|
||||||
|
perms: t.record(t.keyof(Permissions.FLAGS), t.union([t.boolean, t.null])),
|
||||||
|
}),
|
||||||
|
defaultConfig: {
|
||||||
|
channel: "",
|
||||||
|
},
|
||||||
|
|
||||||
|
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||||
|
const role = await pluginData.guild.roles.fetch(actionConfig.target);
|
||||||
|
if (!role) {
|
||||||
|
const member = await pluginData.guild.members.fetch(actionConfig.target);
|
||||||
|
if (!member) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionConfig.channel && isValidSnowflake(actionConfig.channel)) {
|
||||||
|
const channel = await pluginData.guild.channels.fetch(actionConfig.channel);
|
||||||
|
if (!channel) return;
|
||||||
|
const overwrite = channel.permissionOverwrites.cache.find((pw) => pw.id === actionConfig.target);
|
||||||
|
const allow = new Permissions(overwrite ? overwrite.allow : "0").serialize();
|
||||||
|
const deny = new Permissions(overwrite ? overwrite.deny : "0").serialize();
|
||||||
|
const newPerms: Partial<Record<PermissionString, boolean | null>> = {};
|
||||||
|
|
||||||
|
for (const key in allow) {
|
||||||
|
if (typeof actionConfig.perms[key] !== "undefined") {
|
||||||
|
newPerms[key] = actionConfig.perms[key];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (allow[key]) {
|
||||||
|
newPerms[key] = true;
|
||||||
|
} else if (deny[key]) {
|
||||||
|
newPerms[key] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await channel.permissionOverwrites.create(actionConfig.target, newPerms).catch(noop);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!role) return;
|
||||||
|
|
||||||
|
const perms = new Permissions(role.permissions).serialize();
|
||||||
|
for (const key in actionConfig.perms) {
|
||||||
|
perms[key] = actionConfig.perms[key];
|
||||||
|
}
|
||||||
|
const permsArray: PermissionString[] = <any>Object.keys(perms).filter((key) => perms[key]);
|
||||||
|
await role.setPermissions(new Permissions(permsArray)).catch(noop);
|
||||||
|
},
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue