3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 20:55:01 +00:00

Migrate PingableRoles to new Plugin structure

This commit is contained in:
Dark 2020-07-21 23:11:05 +02:00
parent f324dfc227
commit ed344be4b5
9 changed files with 232 additions and 0 deletions

View file

@ -0,0 +1,30 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { pingableRolesCmd } from "../types";
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
export const PingableRoleDisableCmd = pingableRolesCmd({
trigger: ["pingable_role disable", "pingable_role d"],
permission: "can_manage",
signature: {
channelId: ct.channelId(),
role: ct.role(),
},
async run({ message: msg, args, pluginData }) {
const pingableRole = await pluginData.state.pingableRoles.getByChannelAndRoleId(args.channelId, args.role.id);
if (!pingableRole) {
sendErrorMessage(pluginData, msg.channel, `**${args.role.name}** is not set as pingable in <#${args.channelId}>`);
return;
}
await pluginData.state.pingableRoles.delete(args.channelId, args.role.id);
pluginData.state.cache.delete(args.channelId);
sendSuccessMessage(
pluginData,
msg.channel,
`**${args.role.name}** is no longer set as pingable in <#${args.channelId}>`,
);
},
});

View file

@ -0,0 +1,37 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { pingableRolesCmd } from "../types";
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
export const PingableRoleEnableCmd = pingableRolesCmd({
trigger: "pingable_role",
permission: "can_manage",
signature: {
channelId: ct.channelId(),
role: ct.role(),
},
async run({ message: msg, args, pluginData }) {
const existingPingableRole = await pluginData.state.pingableRoles.getByChannelAndRoleId(
args.channelId,
args.role.id,
);
if (existingPingableRole) {
sendErrorMessage(
pluginData,
msg.channel,
`**${args.role.name}** is already set as pingable in <#${args.channelId}>`,
);
return;
}
await pluginData.state.pingableRoles.add(args.channelId, args.role.id);
pluginData.state.cache.delete(args.channelId);
sendSuccessMessage(
pluginData,
msg.channel,
`**${args.role.name}** has been set as pingable in <#${args.channelId}>`,
);
},
});