From 9bc00229a16cf7a610a8d66628ec6acb54891426 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:05:28 +0700 Subject: [PATCH] Create UserNoteManager.js --- src/managers/UserNoteManager.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/managers/UserNoteManager.js diff --git a/src/managers/UserNoteManager.js b/src/managers/UserNoteManager.js new file mode 100644 index 00000000..d31bf07 --- /dev/null +++ b/src/managers/UserNoteManager.js @@ -0,0 +1,33 @@ +'use strict'; + +const { Collection } = require('@discordjs/collection'); +const BaseManager = require('./BaseManager'); + +/** + * Manages API methods for Client and stores their cache. + * @extends {BaseManager} + */ +class UserNoteManager extends BaseManager { + constructor(client, data = {}) { + super(client); + /** + * Cache User Note + * @type {Collection} + */ + this.cache = new Collection(Object.entries(data)); + } + + _reload(data = {}) { + this.cache = new Collection(Object.entries(data)); + return this; + } + + async updateNote(id, note = null) { + await this.client.api.users['@me'].notes(id).put({ data: { note } }); + if (!note) this.cache.delete(id, note); + else this.cache.set(id, note); + return this; + } +} + +module.exports = UserNoteManager;