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:
parent
e684bf7dac
commit
69feccbcab
2 changed files with 13 additions and 6 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue