remind command

This commit is contained in:
Erik 2022-05-06 18:42:43 +03:00
parent b1caa85631
commit 01155df6dd
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -0,0 +1,112 @@
const { Util, FilterUtil } = require("../../../../utilities");
const { SlashCommand } = require("../../../interfaces");
class RemindCommand extends SlashCommand {
constructor(client) {
super(client, {
name: 'remind',
description: 'Set a reminder for yourself',
module: 'utility',
options: [{
name: 'create',
description: 'Create a new reminder',
type: 'SUB_COMMAND',
options: [ {
name: 'in',
description: 'In how long to trigger reminder',
type: 'TIME',
required: true
}, {
name: 'reminder',
description: 'Text to remind you with',
required: true
}],
showUsage: true
}, {
name: ['delete', 'list'],
description: ['Delete an existing reminder', 'List your reminders'],
type: 'SUB_COMMAND',
}],
// showUsage: true
guildOnly: true
});
}
async execute(invoker, { reminder, in: time }) {
const { guild, author, channel, subcommand: { name: subcommand } } = invoker;
if (subcommand === 'create') {
const text = await this._filter(invoker, reminder.value);
// if(result) return { index: 'COMMAND_REMIND_CONTENT_FILTERED' };
await guild.createReminder(time.value, { reminder: text, user: author, channel });
return { index: 'COMMAND_REMIND_CONFIRM', params: { reminder: text, time: Util.humanise(time.value) } };
} else if (subcommand === 'delete') {
const reminders = guild.callbacks.filter((cb) => cb.data.user === author.id).map((val) => val);
const embed = this._remindersEmbed(reminders, guild);
const msg = await invoker.promptMessage(guild.format('COMMAND_REMIND_SELECT'), { embed });
await msg.delete();
const response = msg?.content;
if (!response) return invoker.editReply({ index: 'COMMAND_REMIND_DELETE_TIMEOUT', embeds: [] });
const index = parseInt(response);
if (isNaN(index)) return invoker.editReply({ index: 'COMMAND_REMIND_DELETE_INVALID_INDEX', embeds: [] });
if (index > reminders.length || index < 1) return invoker.editReply({ index: 'COMMAND_REMIND_DELETE_INDEX_OUTOFBOUNDS', embeds: [] });
const reminder = reminders[index - 1];
await guild.removeCallback(reminder.data.id);
return invoker.editReply({ index: 'COMMAND_REMIND_DELETED', emoji: 'success', embeds: [] });
} else if (subcommand === 'list') {
const reminders = guild.callbacks.filter((cb) => cb.data.user === author.id).map((val) => val);
if(!reminders.length) return guild.format('COMMAND_REMIND_NONE');
return { embed: this._remindersEmbed(reminders, guild) };
}
}
_remindersEmbed(reminders, guild) {
const embed = {
title: guild.format('COMMAND_REMINDERS_TITLE'),
fields: []
};
let index = 0;
for (const reminder of reminders) {
const { data } = reminder;
embed.fields.push({
name: `${++index}`,
value: guild.format('COMMAND_REMIND_ENTRY', {
reminder: data.reminder,
channel: data.channel,
created: Math.floor(data.created/1000),
time: Math.floor((data.created + data.time)/1000)
})
});
}
return embed;
}
async _filter(invoker, text) {
const { guild, member } = invoker;
const settings = await guild.settings();
const { wordfilter: { enabled, explicit, fuzzy, regex, whitelist, bypass } } = settings;
if (!enabled) return text;
if (member.roles.cache.map((r) => r.id).some((r) => bypass.includes(r))) return text;
let result = FilterUtil.filterExplicit(text.split(' '), explicit);
if (result) return text.replace(result.match, '[FILTERED]');
result = FilterUtil.filterRegex(text, regex, whitelist);
if (result) return text.replace(result.match, '[FILTERED]');
result = FilterUtil.filterFuzzy(text.split(' '), fuzzy, whitelist);
if (result) return text.replace(result.match, '[FILTERED]');
return false;
}
}
module.exports = RemindCommand;