Add 'set_channel_permission_overrides' custom event action
This commit is contained in:
parent
7839cc7da1
commit
e7efd48519
3 changed files with 46 additions and 0 deletions
|
@ -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}`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import { moveToVoiceChannelAction } from "../actions/moveToVoiceChannelAction";
|
|||
import { messageAction } from "../actions/messageAction";
|
||||
import { makeRoleMentionableAction } from "../actions/makeRoleMentionableAction";
|
||||
import { makeRoleUnmentionableAction } from "../actions/makeRoleUnmentionableAction";
|
||||
import { setChannelPermissionOverridesAction } from "../actions/setChannelPermissionOverrides";
|
||||
|
||||
export async function runEvent(
|
||||
pluginData: GuildPluginData<CustomEventsPluginType>,
|
||||
|
@ -30,6 +31,8 @@ export async function runEvent(
|
|||
await makeRoleMentionableAction(pluginData, action, values, event, eventData);
|
||||
} else if (action.type === "make_role_unmentionable") {
|
||||
await makeRoleUnmentionableAction(pluginData, action, values, event, eventData);
|
||||
} else if (action.type === "set_channel_permission_overrides") {
|
||||
await setChannelPermissionOverridesAction(pluginData, action, values, event, eventData);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import { MoveToVoiceChannelAction } from "./actions/moveToVoiceChannelAction";
|
|||
import { MessageAction } from "./actions/messageAction";
|
||||
import { MakeRoleMentionableAction } from "./actions/makeRoleMentionableAction";
|
||||
import { MakeRoleUnmentionableAction } from "./actions/makeRoleUnmentionableAction";
|
||||
import { SetChannelPermissionOverridesAction } from "./actions/setChannelPermissionOverrides";
|
||||
|
||||
// Triggers
|
||||
const CommandTrigger = t.type({
|
||||
|
@ -26,6 +27,7 @@ const AnyAction = t.union([
|
|||
MessageAction,
|
||||
MakeRoleMentionableAction,
|
||||
MakeRoleUnmentionableAction,
|
||||
SetChannelPermissionOverridesAction,
|
||||
]);
|
||||
type TAnyAction = t.TypeOf<typeof AnyAction>;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue