remove config save, its unnecessary

This commit is contained in:
Evert Prants 2021-10-02 12:31:46 +03:00
parent b99d47d425
commit 08cce57ab6
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
9 changed files with 27 additions and 21 deletions

View File

@ -2,7 +2,7 @@
"main": "plugin.js", "main": "plugin.js",
"name": "debug", "name": "debug",
"description": "In-chat debugging tools", "description": "In-chat debugging tools",
"version": "1.1.1", "version": "1.1.2",
"tags": ["commands", "tools"], "tags": ["commands", "tools"],
"dependencies": ["simplecommands"], "dependencies": ["simplecommands"],
"npmDependencies": [] "npmDependencies": []

View File

@ -104,8 +104,7 @@ class UtilityPlugin extends Plugin {
@EventListener('pluginUnload') @EventListener('pluginUnload')
public unloadEventHandler(plugin: string | Plugin): void { public unloadEventHandler(plugin: string | Plugin): void {
if (plugin === this.name || plugin === this) { if (plugin === this.name || plugin === this) {
this.config.save().then(() => this.emit('pluginUnloaded', this);
this.emit('pluginUnloaded', this));
} }
} }

View File

@ -2,8 +2,8 @@
"main": "plugin.js", "main": "plugin.js",
"name": "diction", "name": "diction",
"description": "Find definitions for words", "description": "Find definitions for words",
"version": "1.2.2", "version": "1.2.3",
"tags": ["commands", "utility", "dictionary"], "tags": ["commands", "utility", "dictionary"],
"dependencies": ["simplecommands"], "dependencies": ["simplecommands", "cron"],
"npmDependencies": [] "npmDependencies": []
} }

View File

@ -29,8 +29,8 @@ const wordCache: Record<string, IWordCache> = {};
/** /**
* Find and remove words that haven't been looked up for a day * Find and remove words that haven't been looked up for a day
*/ */
function flushCache() { function flushCache(): void {
let oldestWords: string[] = []; const oldestWords: string[] = [];
Object.keys(wordCache).forEach((word) => { Object.keys(wordCache).forEach((word) => {
const cached = wordCache[word]; const cached = wordCache[word];
let notOld = false; let notOld = false;
@ -162,17 +162,17 @@ class DictionPlugin extends Plugin {
], ],
definitions: (response as Record<string, string>[]) definitions: (response as Record<string, string>[])
.filter(entry => entry.text) .filter(entry => entry.text)
.map(({ partOfSpeech, text }) => ({ .map((data) => ({
partOfSpeech, text: text.replace(/(<([^>]+)>)/ig, '') partOfSpeech: data.partOfSpeech,
text: data.text.replace(/(<([^>]+)>)/ig, ''),
})), })),
inserted: Date.now(), inserted: Date.now(),
} };
wordCache[word] = cached; wordCache[word] = cached;
chosenDefinition = cached.definitions[0]; chosenDefinition = cached.definitions[0];
definitionCount = cached.definitions.length; definitionCount = cached.definitions.length;
logger.log(`[diction] Dictionary cached the word "${word}"`); logger.log(`[diction] Dictionary cached the word "${word}"`);
flushCache();
} }
const { partOfSpeech, text } = chosenDefinition; const { partOfSpeech, text } = chosenDefinition;
@ -189,6 +189,15 @@ class DictionPlugin extends Plugin {
usage: '<word>' usage: '<word>'
}); });
} }
@DependencyLoad('cron')
public cronLoaded(cron: any): void {
cron.registerTimer(
this,
'0 0 * * *',
() => flushCache(),
);
}
} }
module.exports = DictionPlugin; module.exports = DictionPlugin;

View File

@ -7,11 +7,11 @@
}, },
{ {
"name": "debug", "name": "debug",
"version": "1.1.1" "version": "1.1.2"
}, },
{ {
"name": "diction", "name": "diction",
"version": "1.2.2" "version": "1.2.3"
}, },
{ {
"name": "fun", "name": "fun",
@ -35,7 +35,7 @@
}, },
{ {
"name": "url-twitter", "name": "url-twitter",
"version": "1.0.1" "version": "1.0.2"
}, },
{ {
"name": "urlreply", "name": "urlreply",
@ -43,7 +43,7 @@
}, },
{ {
"name": "utility", "name": "utility",
"version": "3.1.3" "version": "3.1.4"
} }
], ],
"typescript": true "typescript": true

View File

@ -2,7 +2,7 @@
"main": "plugin.js", "main": "plugin.js",
"name": "url-twitter", "name": "url-twitter",
"description": "Twitter URL", "description": "Twitter URL",
"version": "1.0.1", "version": "1.0.2",
"tags": ["urlreply", "twitter"], "tags": ["urlreply", "twitter"],
"dependencies": ["urlreply"], "dependencies": ["urlreply"],
"npmDependencies": ["twitter-lite@1.1.0"] "npmDependencies": ["twitter-lite@1.1.0"]

View File

@ -42,8 +42,7 @@ class TwitterURLPlugin extends Plugin {
@EventListener('pluginUnload') @EventListener('pluginUnload')
public unloadEventHandler(plugin: string | Plugin): void { public unloadEventHandler(plugin: string | Plugin): void {
if (plugin === this.name || plugin === this) { if (plugin === this.name || plugin === this) {
this.config.save().then(() => this.emit('pluginUnloaded', this);
this.emit('pluginUnloaded', this));
} }
} }

View File

@ -2,7 +2,7 @@
"main": "plugin.js", "main": "plugin.js",
"name": "utility", "name": "utility",
"description": "Utility commands and math operations", "description": "Utility commands and math operations",
"version": "3.1.3", "version": "3.1.4",
"tags": ["commands", "tools"], "tags": ["commands", "tools"],
"dependencies": ["simplecommands"], "dependencies": ["simplecommands"],
"npmDependencies": [ "npmDependencies": [

View File

@ -795,8 +795,7 @@ class UtilityPlugin extends Plugin {
@EventListener('pluginUnload') @EventListener('pluginUnload')
public unloadEventHandler(plugin: string | Plugin): void { public unloadEventHandler(plugin: string | Plugin): void {
if (plugin === this.name || plugin === this) { if (plugin === this.name || plugin === this) {
this.config.save().then(() => this.emit('pluginUnloaded', this);
this.emit('pluginUnloaded', this));
} }
} }