diff --git a/backend/src/plugins/NameHistory.ts b/backend/src/plugins/NameHistory.ts index ddc0ed6b..f77e69a8 100644 --- a/backend/src/plugins/NameHistory.ts +++ b/backend/src/plugins/NameHistory.ts @@ -8,6 +8,7 @@ import * as t from "io-ts"; import { NICKNAME_RETENTION_PERIOD } from "../data/cleanup/nicknames"; import moment from "moment-timezone"; import { USERNAME_RETENTION_PERIOD } from "../data/cleanup/usernames"; +import { Queue } from "../Queue"; const ConfigSchema = t.type({ can_view: t.boolean, @@ -22,6 +23,8 @@ export class NameHistoryPlugin extends ZeppelinPlugin { protected nicknameHistory: GuildNicknameHistory; protected usernameHistory: UsernameHistory; + protected updateQueue: Queue; + public static getStaticDefaultOptions(): IPluginOptions { return { config: { @@ -42,6 +45,7 @@ export class NameHistoryPlugin extends ZeppelinPlugin { onLoad() { this.nicknameHistory = GuildNicknameHistory.getGuildInstance(this.guildId); this.usernameHistory = new UsernameHistory(); + this.updateQueue = new Queue(); } @d.command("names", "") @@ -91,11 +95,11 @@ export class NameHistoryPlugin extends ZeppelinPlugin { @d.event("messageCreate") async onMessage(msg: Message) { - this.updateNickname(msg.member); + this.updateQueue.add(() => this.updateNickname(msg.member)); } @d.event("voiceChannelJoin") async onVoiceChannelJoin(member: Member) { - this.updateNickname(member); + this.updateQueue.add(() => this.updateNickname(member)); } } diff --git a/backend/src/plugins/UsernameSaver.ts b/backend/src/plugins/UsernameSaver.ts index 140627d6..25cdcde4 100644 --- a/backend/src/plugins/UsernameSaver.ts +++ b/backend/src/plugins/UsernameSaver.ts @@ -2,14 +2,17 @@ import { decorators as d, GlobalPlugin } from "knub"; import { UsernameHistory } from "../data/UsernameHistory"; import { Member, Message, User } from "eris"; import { GlobalZeppelinPlugin } from "./GlobalZeppelinPlugin"; +import { Queue } from "../Queue"; export class UsernameSaver extends GlobalZeppelinPlugin { public static pluginName = "username_saver"; protected usernameHistory: UsernameHistory; + protected updateQueue: Queue; async onLoad() { this.usernameHistory = new UsernameHistory(); + this.updateQueue = new Queue(); } protected async updateUsername(user: User) { @@ -21,15 +24,15 @@ export class UsernameSaver extends GlobalZeppelinPlugin { } } - @d.event("messageCreate") + @d.event("messageCreate", null) async onMessage(msg: Message) { if (msg.author.bot) return; - this.updateUsername(msg.author); + this.updateQueue.add(() => this.updateUsername(msg.author)); } - @d.event("voiceChannelJoin") + @d.event("voiceChannelJoin", null) async onVoiceChannelJoin(member: Member) { if (member.user.bot) return; - this.updateUsername(member.user); + this.updateQueue.add(() => this.updateUsername(member.user)); } }