ttt-discord-bot/server/RegistrationHandler.ts

39 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-11-13 13:48:38 +01:00
import { Maybe, userNameBinding } from "./interfaces"
2021-11-08 17:34:26 +01:00
export default class RegistrationHandler {
2021-11-11 01:01:22 +01:00
private userRegister: userNameBinding[] = []
2021-11-13 13:48:38 +01:00
private static _instance: RegistrationHandler
2021-11-11 01:01:22 +01:00
public constructor() {
console.log('Setup RegistrationHandler')
}
2021-11-13 13:48:38 +01:00
public static get Instance() {
return this._instance || (this._instance = new this())
}
2021-11-11 01:01:22 +01:00
public register(discordname: string, steamname: string): boolean {
const binding: userNameBinding = {
Steam: steamname,
Discord: discordname
}
console.log(`Trying to register ${JSON.stringify(binding)}`)
2021-11-08 17:34:26 +01:00
2021-11-11 01:01:22 +01:00
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
2021-11-08 17:34:26 +01:00
}
2021-11-13 13:48:38 +01:00
public getAllMappings(): userNameBinding[] { return this.userRegister }
2021-11-11 01:01:22 +01:00
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) }
2021-11-13 13:48:38 +01:00
private printHelpText(): string { return "" }
2021-11-08 17:34:26 +01:00
private buildHelpText(): string { return "" }
}