3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-07 19:17:19 +00:00

Save names using a queue to avoid race conditions

This commit is contained in:
Dragory 2020-06-02 01:40:02 +03:00
parent e684bf7dac
commit 69feccbcab
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 13 additions and 6 deletions

View file

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