From 08cce57ab6597f46abd4790363719208e650a9bb Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sat, 2 Oct 2021 12:31:46 +0300 Subject: [PATCH] remove config save, its unnecessary --- debug/plugin.json | 2 +- debug/plugin.ts | 3 +-- diction/plugin.json | 4 ++-- diction/plugin.ts | 21 +++++++++++++++------ squeebot.repo.json | 8 ++++---- url-twitter/plugin.json | 2 +- url-twitter/plugin.ts | 3 +-- utility/plugin.json | 2 +- utility/plugin.ts | 3 +-- 9 files changed, 27 insertions(+), 21 deletions(-) diff --git a/debug/plugin.json b/debug/plugin.json index 302bc7f..cc96771 100644 --- a/debug/plugin.json +++ b/debug/plugin.json @@ -2,7 +2,7 @@ "main": "plugin.js", "name": "debug", "description": "In-chat debugging tools", - "version": "1.1.1", + "version": "1.1.2", "tags": ["commands", "tools"], "dependencies": ["simplecommands"], "npmDependencies": [] diff --git a/debug/plugin.ts b/debug/plugin.ts index 8968b27..a1b368c 100644 --- a/debug/plugin.ts +++ b/debug/plugin.ts @@ -104,8 +104,7 @@ class UtilityPlugin extends Plugin { @EventListener('pluginUnload') public unloadEventHandler(plugin: string | Plugin): void { if (plugin === this.name || plugin === this) { - this.config.save().then(() => - this.emit('pluginUnloaded', this)); + this.emit('pluginUnloaded', this); } } diff --git a/diction/plugin.json b/diction/plugin.json index 2abf437..7525d16 100644 --- a/diction/plugin.json +++ b/diction/plugin.json @@ -2,8 +2,8 @@ "main": "plugin.js", "name": "diction", "description": "Find definitions for words", - "version": "1.2.2", + "version": "1.2.3", "tags": ["commands", "utility", "dictionary"], - "dependencies": ["simplecommands"], + "dependencies": ["simplecommands", "cron"], "npmDependencies": [] } diff --git a/diction/plugin.ts b/diction/plugin.ts index cd73d09..f543af8 100644 --- a/diction/plugin.ts +++ b/diction/plugin.ts @@ -29,8 +29,8 @@ const wordCache: Record = {}; /** * Find and remove words that haven't been looked up for a day */ -function flushCache() { - let oldestWords: string[] = []; +function flushCache(): void { + const oldestWords: string[] = []; Object.keys(wordCache).forEach((word) => { const cached = wordCache[word]; let notOld = false; @@ -162,17 +162,17 @@ class DictionPlugin extends Plugin { ], definitions: (response as Record[]) .filter(entry => entry.text) - .map(({ partOfSpeech, text }) => ({ - partOfSpeech, text: text.replace(/(<([^>]+)>)/ig, '') + .map((data) => ({ + partOfSpeech: data.partOfSpeech, + text: data.text.replace(/(<([^>]+)>)/ig, ''), })), inserted: Date.now(), - } + }; wordCache[word] = cached; chosenDefinition = cached.definitions[0]; definitionCount = cached.definitions.length; logger.log(`[diction] Dictionary cached the word "${word}"`); - flushCache(); } const { partOfSpeech, text } = chosenDefinition; @@ -189,6 +189,15 @@ class DictionPlugin extends Plugin { usage: '' }); } + + @DependencyLoad('cron') + public cronLoaded(cron: any): void { + cron.registerTimer( + this, + '0 0 * * *', + () => flushCache(), + ); + } } module.exports = DictionPlugin; diff --git a/squeebot.repo.json b/squeebot.repo.json index 88e6a65..85d58f4 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -7,11 +7,11 @@ }, { "name": "debug", - "version": "1.1.1" + "version": "1.1.2" }, { "name": "diction", - "version": "1.2.2" + "version": "1.2.3" }, { "name": "fun", @@ -35,7 +35,7 @@ }, { "name": "url-twitter", - "version": "1.0.1" + "version": "1.0.2" }, { "name": "urlreply", @@ -43,7 +43,7 @@ }, { "name": "utility", - "version": "3.1.3" + "version": "3.1.4" } ], "typescript": true diff --git a/url-twitter/plugin.json b/url-twitter/plugin.json index 914e5a2..6d610c5 100644 --- a/url-twitter/plugin.json +++ b/url-twitter/plugin.json @@ -2,7 +2,7 @@ "main": "plugin.js", "name": "url-twitter", "description": "Twitter URL", - "version": "1.0.1", + "version": "1.0.2", "tags": ["urlreply", "twitter"], "dependencies": ["urlreply"], "npmDependencies": ["twitter-lite@1.1.0"] diff --git a/url-twitter/plugin.ts b/url-twitter/plugin.ts index 9539cb9..b87ccb7 100644 --- a/url-twitter/plugin.ts +++ b/url-twitter/plugin.ts @@ -42,8 +42,7 @@ class TwitterURLPlugin extends Plugin { @EventListener('pluginUnload') public unloadEventHandler(plugin: string | Plugin): void { if (plugin === this.name || plugin === this) { - this.config.save().then(() => - this.emit('pluginUnloaded', this)); + this.emit('pluginUnloaded', this); } } diff --git a/utility/plugin.json b/utility/plugin.json index ca0db3e..8df1279 100644 --- a/utility/plugin.json +++ b/utility/plugin.json @@ -2,7 +2,7 @@ "main": "plugin.js", "name": "utility", "description": "Utility commands and math operations", - "version": "3.1.3", + "version": "3.1.4", "tags": ["commands", "tools"], "dependencies": ["simplecommands"], "npmDependencies": [ diff --git a/utility/plugin.ts b/utility/plugin.ts index 243feb1..8b9d4c1 100644 --- a/utility/plugin.ts +++ b/utility/plugin.ts @@ -795,8 +795,7 @@ class UtilityPlugin extends Plugin { @EventListener('pluginUnload') public unloadEventHandler(plugin: string | Plugin): void { if (plugin === this.name || plugin === this) { - this.config.save().then(() => - this.emit('pluginUnloaded', this)); + this.emit('pluginUnloaded', this); } }