mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
66 lines
2.6 KiB
TypeScript
66 lines
2.6 KiB
TypeScript
import {Command, NamedCommand, RestCommand} from "../../core";
|
|
import moment from "moment";
|
|
import {Storage} from "../../structures";
|
|
import {MessageEmbed} from "discord.js";
|
|
|
|
export default new NamedCommand({
|
|
description: "Keep and edit your personal todo list.",
|
|
async run({send, message, channel, guild, author, member, client, args}) {
|
|
const user = Storage.getUser(author.id);
|
|
const embed = new MessageEmbed().setTitle(`Todo list for ${author.tag}`).setColor("BLUE");
|
|
|
|
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]
|
|
);
|
|
}
|
|
|
|
send(embed);
|
|
},
|
|
subcommands: {
|
|
add: new NamedCommand({
|
|
run: "You need to specify a note to add.",
|
|
any: new RestCommand({
|
|
async run({send, message, channel, guild, author, member, client, args, combined}) {
|
|
const user = Storage.getUser(author.id);
|
|
user.todoList[Date.now().toString()] = combined;
|
|
console.debug(user.todoList);
|
|
Storage.save();
|
|
send(`Successfully added \`${combined}\` to your todo list.`);
|
|
}
|
|
})
|
|
}),
|
|
remove: new NamedCommand({
|
|
run: "You need to specify a note to remove.",
|
|
any: new RestCommand({
|
|
async run({send, message, channel, guild, author, member, client, args, combined}) {
|
|
const user = Storage.getUser(author.id);
|
|
let isFound = false;
|
|
|
|
for (const timestamp in user.todoList) {
|
|
const selectedNote = user.todoList[timestamp];
|
|
|
|
if (selectedNote === combined) {
|
|
delete user.todoList[timestamp];
|
|
Storage.save();
|
|
isFound = true;
|
|
send(`Removed \`${combined}\` from your todo list.`);
|
|
}
|
|
}
|
|
|
|
if (!isFound) send("That item couldn't be found.");
|
|
}
|
|
})
|
|
}),
|
|
clear: new NamedCommand({
|
|
async run({send, message, channel, guild, author, member, client, args}) {
|
|
const user = Storage.getUser(author.id);
|
|
user.todoList = {};
|
|
Storage.save();
|
|
send("Cleared todo list.");
|
|
}
|
|
})
|
|
}
|
|
});
|