2021-04-05 12:21:27 +00:00
|
|
|
import {Command, NamedCommand} from "../../core";
|
2021-03-31 01:40:29 +00:00
|
|
|
import moment from "moment";
|
2021-04-05 12:21:27 +00:00
|
|
|
import {Storage} from "../../structures";
|
2021-03-31 01:40:29 +00:00
|
|
|
import {MessageEmbed} from "discord.js";
|
|
|
|
|
2021-04-05 12:21:27 +00:00
|
|
|
export default new NamedCommand({
|
2021-03-31 01:40:29 +00:00
|
|
|
description: "Keep and edit your personal todo list.",
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, message, channel, guild, author, member, client, args}) {
|
2021-04-05 12:21:27 +00:00
|
|
|
const user = Storage.getUser(author.id);
|
|
|
|
const embed = new MessageEmbed().setTitle(`Todo list for ${author.tag}`).setColor("BLUE");
|
2021-03-31 01:40:29 +00:00
|
|
|
|
|
|
|
for (const timestamp in user.todoList) {
|
|
|
|
const date = new Date(Number(timestamp));
|
|
|
|
embed.addField(
|
|
|
|
`${moment(date).format("LT")} ${moment(date).format("LL")} (${moment(date).fromNow()})`,
|
|
|
|
user.todoList[timestamp]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-10 13:34:55 +00:00
|
|
|
send(embed);
|
2021-03-31 01:40:29 +00:00
|
|
|
},
|
|
|
|
subcommands: {
|
2021-04-05 12:21:27 +00:00
|
|
|
add: new NamedCommand({
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, message, channel, guild, author, member, client, args}) {
|
2021-04-05 12:21:27 +00:00
|
|
|
const user = Storage.getUser(author.id);
|
|
|
|
const note = args.join(" ");
|
2021-03-31 01:40:29 +00:00
|
|
|
user.todoList[Date.now().toString()] = note;
|
|
|
|
console.debug(user.todoList);
|
|
|
|
Storage.save();
|
2021-04-10 13:34:55 +00:00
|
|
|
send(`Successfully added \`${note}\` to your todo list.`);
|
2021-03-31 01:40:29 +00:00
|
|
|
}
|
|
|
|
}),
|
2021-04-05 12:21:27 +00:00
|
|
|
remove: new NamedCommand({
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, message, channel, guild, author, member, client, args}) {
|
2021-04-05 12:21:27 +00:00
|
|
|
const user = Storage.getUser(author.id);
|
|
|
|
const note = args.join(" ");
|
2021-03-31 01:40:29 +00:00
|
|
|
let isFound = false;
|
|
|
|
|
|
|
|
for (const timestamp in user.todoList) {
|
|
|
|
const selectedNote = user.todoList[timestamp];
|
|
|
|
|
|
|
|
if (selectedNote === note) {
|
|
|
|
delete user.todoList[timestamp];
|
|
|
|
Storage.save();
|
|
|
|
isFound = true;
|
2021-04-10 13:34:55 +00:00
|
|
|
send(`Removed \`${note}\` from your todo list.`);
|
2021-03-31 01:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-10 13:34:55 +00:00
|
|
|
if (!isFound) send("That item couldn't be found.");
|
2021-03-31 01:40:29 +00:00
|
|
|
}
|
|
|
|
}),
|
2021-04-05 12:21:27 +00:00
|
|
|
clear: new NamedCommand({
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, message, channel, guild, author, member, client, args}) {
|
2021-04-05 12:21:27 +00:00
|
|
|
const user = Storage.getUser(author.id);
|
2021-03-31 01:40:29 +00:00
|
|
|
user.todoList = {};
|
|
|
|
Storage.save();
|
2021-04-10 13:34:55 +00:00
|
|
|
send("Cleared todo list.");
|
2021-03-31 01:40:29 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|