39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
import { Maybe, userNameBinding } from "./interfaces"
|
|
|
|
export default class RegistrationHandler {
|
|
private userRegister: userNameBinding[] = []
|
|
private static _instance: RegistrationHandler
|
|
public constructor() {
|
|
console.log('Setup RegistrationHandler')
|
|
}
|
|
public static get Instance() {
|
|
return this._instance || (this._instance = new this())
|
|
}
|
|
|
|
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 getAllMappings(): userNameBinding[] { return this.userRegister }
|
|
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(): string { return "" }
|
|
private buildHelpText(): string { return "" }
|
|
}
|