ttt-discord-bot/server/RegistrationHandler.ts

37 lines
1.4 KiB
TypeScript

export interface userNameBinding {
Steam: string,
Discord: string
}
export type Maybe<T> = T | undefined
export default class RegistrationHandler {
private userRegister: userNameBinding[] = []
public constructor() {
console.log('Setup RegistrationHandler')
}
public register(discordname: string, steamname: string): boolean {
const binding: userNameBinding = {
Steam: steamname,
Discord: discordname
}
console.log(`Trying to register ${JSON.stringify(binding)}`)
let alreadyPresentBinding = this.userRegister.find(x => x.Discord == binding.Discord)
if (alreadyPresentBinding) {
console.log(`Binding already present: ${alreadyPresentBinding}, overwriting.`)
alreadyPresentBinding = binding
}
else {
this.userRegister.push(binding)
console.log(`Binding successfully added.`)
}
return true
}
public removeUser(discordName: string): void { this.userRegister = this.userRegister.filter(x => x.Discord !== discordName) }
public getNameRegisteredForDiscordUser(discordUser: string): Maybe<userNameBinding> { return this.userRegister.find(x => x.Discord == discordUser) }
public getNameRegisteredForSteamUser(steamUser: string): Maybe<userNameBinding> { return this.userRegister.find(x => x.Steam == steamUser) }
public listRegisteredMembers(): string { return JSON.stringify(this.userRegister) }
private printHelpText(): void { }
private buildHelpText(): string { return "" }
}