From 930296973ab60c4aff231b9873c17a6604e92008 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Wed, 8 May 2019 08:27:52 +0300 Subject: [PATCH] Fix stacking scheduled post loop when reloading --- src/plugins/Post.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/Post.ts b/src/plugins/Post.ts index cbf61277..2db3cc9c 100644 --- a/src/plugins/Post.ts +++ b/src/plugins/Post.ts @@ -40,6 +40,8 @@ export class PostPlugin extends ZeppelinPlugin { protected scheduledPosts: GuildScheduledPosts; protected logs: GuildLogs; + private scheduledPostLoopTimeout; + onLoad() { this.savedMessages = GuildSavedMessages.getInstance(this.guildId); this.scheduledPosts = GuildScheduledPosts.getInstance(this.guildId); @@ -48,6 +50,10 @@ export class PostPlugin extends ZeppelinPlugin { this.scheduledPostLoop(); } + onUnload() { + clearTimeout(this.scheduledPostLoopTimeout); + } + getDefaultOptions(): IPluginOptions { return { config: { @@ -183,7 +189,7 @@ export class PostPlugin extends ZeppelinPlugin { await this.scheduledPosts.delete(post.id); } - setTimeout(() => this.scheduledPostLoop(), SCHEDULED_POST_CHECK_INTERVAL); + this.scheduledPostLoopTimeout = setTimeout(() => this.scheduledPostLoop(), SCHEDULED_POST_CHECK_INTERVAL); } /**