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

Migrate LocateUser to new Plugin structure

This commit is contained in:
Dark 2020-07-08 02:53:44 +02:00
parent 4a8a63e8b8
commit 63efaf84ee
16 changed files with 380 additions and 0 deletions

View file

@ -0,0 +1,63 @@
import { locateUserCommand } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import moment from "moment-timezone";
import humanizeDuration from "humanize-duration";
import { MINUTES, SECONDS } from "src/utils";
import { sendSuccessMessage } from "src/pluginUtils";
export const FollowCmd = locateUserCommand({
trigger: ["follow", "f"],
description: "Sets up an alert that notifies you any time `<member>` switches or joins voice channels",
usage: "!f 108552944961454080",
permission: "can_alert",
signature: {
member: ct.resolvedMember(),
reminder: ct.string({ required: false, rest: true }),
duration: ct.delay({ option: true, shortcut: "d" }),
active: ct.bool({ option: true, shortcut: "a" }),
},
async run({ message: msg, args, pluginData }) {
const time = args.duration || 10 * MINUTES;
const alertTime = moment().add(time, "millisecond");
const body = args.reminder || "None";
const active = args.active || false;
if (time < 30 * SECONDS) {
this.sendErrorMessage(msg.channel, "Sorry, but the minimum duration for an alert is 30 seconds!");
return;
}
await pluginData.state.alerts.add(
msg.author.id,
args.member.id,
msg.channel.id,
alertTime.format("YYYY-MM-DD HH:mm:ss"),
body,
active,
);
if (!pluginData.state.usersWithAlerts.includes(args.member.id)) {
pluginData.state.usersWithAlerts.push(args.member.id);
}
if (active) {
sendSuccessMessage(
pluginData,
msg.channel,
`Every time ${args.member.mention} joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify and move you.\nPlease make sure to be in a voice channel, otherwise i cannot move you!`,
);
} else {
sendSuccessMessage(
pluginData,
msg.channel,
`Every time ${args.member.mention} joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify you`,
);
}
},
});

View file

@ -0,0 +1,57 @@
import { locateUserCommand } from "../types";
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sorter, createChunkedMessage } from "src/utils";
export const ListFollowCmd = locateUserCommand({
trigger: ["follows", "fs"],
description: "Displays all of your active alerts ordered by expiration time",
usage: "!fs",
permission: "can_alert",
async run({ message: msg, pluginData }) {
const alerts = await pluginData.state.alerts.getAlertsByRequestorId(msg.member.id);
if (alerts.length === 0) {
sendErrorMessage(pluginData, msg.channel, "You have no active alerts!");
return;
}
alerts.sort(sorter("expires_at"));
const longestNum = (alerts.length + 1).toString().length;
const lines = Array.from(alerts.entries()).map(([i, alert]) => {
const num = i + 1;
const paddedNum = num.toString().padStart(longestNum, " ");
return `\`${paddedNum}.\` \`${alert.expires_at}\` **Target:** <@!${alert.user_id}> **Reminder:** \`${
alert.body
}\` **Active:** ${alert.active.valueOf()}`;
});
await createChunkedMessage(msg.channel, lines.join("\n"));
},
});
export const DeleteFollowCmd = locateUserCommand({
trigger: ["follows delete", "fs d"],
description:
"Deletes the alert at the position <num>.\nThe value needed for <num> can be found using `!follows` (`!fs`)",
usage: "!fs d <num>",
permission: "can_alert",
signature: {
num: ct.number({ required: true }),
},
async run({ message: msg, args, pluginData }) {
const alerts = await pluginData.state.alerts.getAlertsByRequestorId(msg.member.id);
alerts.sort(sorter("expires_at"));
if (args.num > alerts.length || args.num <= 0) {
sendErrorMessage(pluginData, msg.channel, "Unknown alert!");
return;
}
const toDelete = alerts[args.num - 1];
await pluginData.state.alerts.delete(toDelete.id);
sendSuccessMessage(pluginData, msg.channel, "Alert deleted");
},
});

View file

@ -0,0 +1,20 @@
import { locateUserCommand } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { resolveMember } from "src/utils";
import { sendWhere } from "../utils/sendWhere";
export const WhereCmd = locateUserCommand({
trigger: ["where", "w"],
description: "Posts an instant invite to the voice channel that `<member>` is in",
usage: "!w 108552944961454080",
permission: "can_where",
signature: {
member: ct.resolvedMember(),
},
async run({ message: msg, args, pluginData }) {
const member = await resolveMember(pluginData.client, pluginData.guild, args.member.id);
sendWhere.call(this, pluginData.guild, member, msg.channel, `${msg.member.mention} | `);
},
});