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",
"name": "debug",
"description": "In-chat debugging tools",
"version": "1.1.1",
"version": "1.1.2",
"tags": ["commands", "tools"],
"dependencies": ["simplecommands"],
"npmDependencies": []

View File

@ -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);
}
}

View File

@ -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": []
}

View File

@ -29,8 +29,8 @@ const wordCache: Record<string, IWordCache> = {};
/**
* 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<string, string>[])
.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: '<word>'
});
}
@DependencyLoad('cron')
public cronLoaded(cron: any): void {
cron.registerTimer(
this,
'0 0 * * *',
() => flushCache(),
);
}
}
module.exports = DictionPlugin;

View File

@ -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

View File

@ -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"]

View File

@ -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);
}
}

View File

@ -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": [

View File

@ -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);
}
}