3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-20 00:05:04 +00:00

Reorganize project. Add folder for shared code between backend/dashboard. Switch from jest to ava for tests.

This commit is contained in:
Dragory 2019-11-02 22:11:26 +02:00
parent cd53d3ce5d
commit 9250c84637
162 changed files with 11056 additions and 9900 deletions

View file

@ -0,0 +1,33 @@
import { decorators as d, GlobalPlugin } from "knub";
import { UsernameHistory } from "../data/UsernameHistory";
import { Member, User } from "eris";
import { GlobalZeppelinPlugin } from "./GlobalZeppelinPlugin";
export class UsernameSaver extends GlobalZeppelinPlugin {
public static pluginName = "username_saver";
protected usernameHistory: UsernameHistory;
async onLoad() {
this.usernameHistory = new UsernameHistory();
}
protected async updateUsername(user: User) {
if (!user) return;
const newUsername = `${user.username}#${user.discriminator}`;
const latestEntry = await this.usernameHistory.getLastEntry(user.id);
if (!latestEntry || 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);
}
}