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

Add 'set_channel_permission_overrides' custom event action

This commit is contained in:
Dragory 2020-11-22 14:59:02 +02:00
parent 7839cc7da1
commit e7efd48519
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,41 @@
import { GuildPluginData } from "knub";
import { CustomEventsPluginType, TCustomEvent } from "../types";
import * as t from "io-ts";
import { ActionError } from "../ActionError";
export const SetChannelPermissionOverridesAction = t.type({
type: t.literal("set_channel_permission_overrides"),
channel: t.string,
overrides: t.array(
t.type({
type: t.union([t.literal("member"), t.literal("role")]),
id: t.string,
allow: t.number,
deny: t.number,
}),
),
});
export type TSetChannelPermissionOverridesAction = t.TypeOf<typeof SetChannelPermissionOverridesAction>;
export async function setChannelPermissionOverridesAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TSetChannelPermissionOverridesAction,
values: any,
event: TCustomEvent,
eventData: any,
) {
const channel = pluginData.guild.channels.get(action.channel);
if (!channel) {
throw new ActionError(`Unknown channel: ${action.channel}`);
}
for (const override of action.overrides) {
await channel.editPermission(
override.id,
override.allow,
override.deny,
override.type,
`Custom event: ${event.name}`,
);
}
}