mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-18 07:35:02 +00:00
Fix username change logging and saving. Re-enable migrations.
This commit is contained in:
parent
1b1ae98714
commit
e231faf51f
12 changed files with 255 additions and 119 deletions
31
src/plugins/UsernameSaver.ts
Normal file
31
src/plugins/UsernameSaver.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { decorators as d, GlobalPlugin } from "knub";
|
||||
import { UsernameHistory } from "../data/UsernameHistory";
|
||||
import { Member, User } from "eris";
|
||||
|
||||
export class UsernameSaver extends GlobalPlugin {
|
||||
public static pluginName = "username_saver";
|
||||
|
||||
protected usernameHistory: UsernameHistory;
|
||||
|
||||
async onLoad() {
|
||||
this.usernameHistory = UsernameHistory.getInstance(null);
|
||||
}
|
||||
|
||||
protected async updateUsername(user: User) {
|
||||
const newUsername = `${user.username}#${user.discriminator}`;
|
||||
const latestEntry = await this.usernameHistory.getLastEntry(user.id);
|
||||
if (newUsername !== latestEntry.username) {
|
||||
await this.usernameHistory.addEntry(user.id, newUsername);
|
||||
}
|
||||
}
|
||||
|
||||
@d.event("userUpdate", null, false)
|
||||
async onUserUpdate(user: User) {
|
||||
this.updateUsername(user);
|
||||
}
|
||||
|
||||
@d.event("guildMemberAdd", null, false)
|
||||
async onGuildMemberAdd(_, member: Member) {
|
||||
this.updateUsername(member.user);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue