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

Add 'make_role_mentionable' and 'make_role_unmentionable' custom event actions

This commit is contained in:
Dragory 2020-11-22 14:14:17 +02:00
parent bc5455bf9f
commit 7839cc7da1
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 90 additions and 1 deletions

View file

@ -0,0 +1,44 @@
import { GuildPluginData } from "knub";
import { CustomEventsPluginType, TCustomEvent } from "../types";
import * as t from "io-ts";
import { convertDelayStringToMS, noop, tDelayString } from "../../../utils";
import { ActionError } from "../ActionError";
export const MakeRoleMentionableAction = t.type({
type: t.literal("make_role_mentionable"),
role: t.string,
timeout: tDelayString,
});
export type TMakeRoleMentionableAction = t.TypeOf<typeof MakeRoleMentionableAction>;
export async function makeRoleMentionableAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TMakeRoleMentionableAction,
values: any,
event: TCustomEvent,
eventData: any,
) {
const role = pluginData.guild.roles.get(action.role);
if (!role) {
throw new ActionError(`Unknown role: ${role}`);
}
await role.edit(
{
mentionable: true,
},
`Custom event: ${event.name}`,
);
const timeout = convertDelayStringToMS(action.timeout)!;
setTimeout(() => {
role
.edit(
{
mentionable: false,
},
`Custom event: ${event.name}`,
)
.catch(noop);
}, timeout);
}