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:
parent
bc5455bf9f
commit
7839cc7da1
4 changed files with 90 additions and 1 deletions
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue