From 3b69d4fb6b8aa30d1250aba43ea30646c66f12c9 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Wed, 3 Mar 2021 16:51:52 -0700 Subject: [PATCH] todo model and start of cmd --- commands/utility/todo.js | 60 ++++++++++++++++++++++++++++++++++++++++ models/todo.js | 9 ++++++ 2 files changed, 69 insertions(+) create mode 100644 commands/utility/todo.js create mode 100644 models/todo.js diff --git a/commands/utility/todo.js b/commands/utility/todo.js new file mode 100644 index 0000000..fdfcd3a --- /dev/null +++ b/commands/utility/todo.js @@ -0,0 +1,60 @@ +const Discord = require('discord.js'); + +const TD = require('../../models/todo'); + +const ask = require('../../util/ask'); + +module.exports = { + name: "todo", + aliases: ['td'], + meta: { + category: 'Utility', + description: "Create and manage your To-Do lists!", + syntax: '`todo `', + extra: null + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> To-Do Lists") + .setDescription("Create and manage your To-Do lists. You can use the commands like `add` or `view` without specifying a list to see your `quick` list, which is just quick random stuff. Otherwise, you can specify a list name first to manage it.") + .addField("Syntax", "`todo `"), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}todo \``);} + + if (['add', 'a'].includes(args[0].toLowerCase())) { + let list = 'quick'; + let td = await TD.findOne({uid: message.author.id}); + if (td && td.lists.quick.length > 20) {return message.channel.send("Sorry, but your list can only have 20 items or less.");} + let item; + if (!args[1]) {item = await ask(message, "What would you like to your quick list?", 90000); if (!item) {return;}} + else {args.shift(); item = args.join(" ");} + if (item.length > 100) {return message.channel.send("ToDo items can only be less than 100 characters.");} + td = td || new TD({uid: message.author.id}); + td.lists.quick.push(item); + td.markModified(`lists.${list}`); + td.save(); + return message.channel.send(new Discord.MessageEmbed() + .setAuthor("To-Do Added!", message.author.avatarURL()) + .setDescription(`${item}\n\`->\` In list '${list}'`) + .setColor('c375f0') + ); + } + + else if (['v', 'view'].includes(args[0].toLowerCase())) { + let list = 'quick'; + let td = await TD.findOne({uid: message.author.id}); + if (!td) {return message.channel.send("You don't have any todo lists!");} + if (!td.lists[list]) {return message.channel.send("That list doesn't exist!");} + if (!td.lists[list].length) {return message.channel.send("That list is empty!");} + let s = ''; + let n = 0; let i; for (i of td.lists[list]) {n++; s += `**${n}.** ${i}\n`;} + return message.channel.send(new Discord.MessageEmbed() + .setAuthor(message.guild ? message.member.displayName : message.author.username, message.author.avatarURL()) + .setTitle(list === "quick" ? "Personal Quick List" : `List "${list}"`) + .setDescription(s) + .setColor("c375f0") + .setFooter("Natsuki") + .setTimestamp() + ); + } + } +}; \ No newline at end of file diff --git a/models/todo.js b/models/todo.js new file mode 100644 index 0000000..5738bfc --- /dev/null +++ b/models/todo.js @@ -0,0 +1,9 @@ +const mongoose = require('mongoose'); + +const td = new mongoose.Schema({ + uid: {type: String, unique: true}, + lists: {type: Object, default: {quick: []}}, + publicLists: {type: Object, default: {}} +}); + +module.exports = mongoose.model('todo', td); \ No newline at end of file