diff --git a/README.md b/README.md index 7ba74424..ecc4ecac 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 563 +Total: 564 ### Utility: @@ -849,6 +849,11 @@ Total: 563 * **soundboard:** Plays a sound in a voice channel. * **vocodes:** Speak text like a variety of famous figures. +### Reminders: + +* **delete-reminder:** Deletes your reminder. +* **remind:** Sets a reminder. + ### Phone: * **admin-phone:** Starts an admin phone call with a server. (Owner-Only) @@ -870,7 +875,6 @@ Total: 563 * **dating:** Find the person of your dreams with this dating system! * **portal-send:** Send a message to a portal channel. * **prune:** Deletes up to 99 messages from the current channel. -* **remind:** Sets a reminder. * **rename-all:** Renames every member of the server. (Owner-Only) * **screenshot:** Takes a screenshot of any webpage. * **smilebasic:** Responds with a ZIP file for a SmileBASIC project. diff --git a/Xiao.js b/Xiao.js index 7daf8384..eb5987d0 100644 --- a/Xiao.js +++ b/Xiao.js @@ -36,6 +36,7 @@ client.registry ['edit-text', 'Text Manipulation'], ['edit-number', 'Number Manipulation'], ['voice', 'Play Audio'], + ['remind', 'Reminders'], ['phone', 'Phone'], ['code', 'Coding Tools'], ['other', 'Other'], diff --git a/commands/remind/delete-reminder.js b/commands/remind/delete-reminder.js new file mode 100644 index 00000000..1e6b7d25 --- /dev/null +++ b/commands/remind/delete-reminder.js @@ -0,0 +1,20 @@ +const Command = require('../../structures/Command'); + +module.exports = class DeleteReminderCommand extends Command { + constructor(client) { + super(client, { + name: 'delete-reminder', + aliases: ['delete-remind', 'delete-timer', 'del-reminder', 'del-remind', 'del-timer'], + group: 'remind', + memberName: 'remind', + description: 'Deletes your reminder.' + }); + } + + async run(msg) { + const exists = await this.client.timers.exists(msg.channel.id, msg.author.id); + if (!exists) return msg.reply('You do not have a timer set in this channel.'); + await this.client.timers.deleteTimer(msg.channel.id, msg.author.id); + return msg.say('🕰️ Your timer has been deleted.'); + } +}; diff --git a/commands/other/remind.js b/commands/remind/remind.js similarity index 98% rename from commands/other/remind.js rename to commands/remind/remind.js index b2726631..a0a7b819 100644 --- a/commands/other/remind.js +++ b/commands/remind/remind.js @@ -7,7 +7,7 @@ module.exports = class RemindCommand extends Command { super(client, { name: 'remind', aliases: ['timer', 'remind-me'], - group: 'other', + group: 'remind', memberName: 'remind', description: 'Sets a reminder.', args: [ diff --git a/package.json b/package.json index 0ae45cf6..3d816787 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "121.2.2", + "version": "121.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/Client.js b/structures/Client.js index a144ea6d..e3e37c2d 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -5,7 +5,7 @@ const winston = require('winston'); const fs = require('fs'); const path = require('path'); const Redis = require('./Redis'); -const TimerManager = require('./timer/TimerManager'); +const TimerManager = require('./remind/TimerManager'); const PokemonStore = require('./pokemon/PokemonStore'); const MemePosterClient = require('./MemePoster'); const activities = require('../assets/json/activity'); diff --git a/structures/timer/TimerManager.js b/structures/remind/TimerManager.js similarity index 78% rename from structures/timer/TimerManager.js rename to structures/remind/TimerManager.js index b56c329e..7eadc351 100644 --- a/structures/timer/TimerManager.js +++ b/structures/remind/TimerManager.js @@ -1,6 +1,8 @@ module.exports = class TimerManager { constructor(client) { Object.defineProperty(this, 'client', { value: client }); + + this.timeouts = new Map(); } async fetchAll() { @@ -23,9 +25,16 @@ module.exports = class TimerManager { } }, time); if (updateRedis) await this.client.redis.hset('timer', { [`${channelID}-${userID}`]: JSON.stringify(data) }); + this.timeouts.set(`${channelID}-${userID}`, timeout); return timeout; } + deleteTimer(channelID, userID) { + clearTimeout(this.timeouts.get(`${channelID}-${userID}`)); + this.timeouts.delete(`${channelID}-${userID}`); + return this.client.redis.hdel('timer', `${channelID}-${userID}`); + } + exists(channelID, userID) { return this.client.redis.hexists('timer', `${channelID}-${userID}`); }