update registration handler for new interface
This commit is contained in:
parent
ef4bb487df
commit
66b1a3bd7d
@ -1,3 +1,4 @@
|
|||||||
|
import { GuildMember } from "discord.js"
|
||||||
import { Maybe, userNameBinding } from "./interfaces"
|
import { Maybe, userNameBinding } from "./interfaces"
|
||||||
|
|
||||||
export default class RegistrationHandler {
|
export default class RegistrationHandler {
|
||||||
@ -10,29 +11,45 @@ export default class RegistrationHandler {
|
|||||||
return this._instance || (this._instance = new this())
|
return this._instance || (this._instance = new this())
|
||||||
}
|
}
|
||||||
|
|
||||||
public register(discordname: string, steamname: string): boolean {
|
public register(discordUser: GuildMember, steamname: string): boolean {
|
||||||
const binding: userNameBinding = {
|
try {
|
||||||
Steam: steamname,
|
|
||||||
Discord: discordname
|
|
||||||
}
|
|
||||||
console.log(`Trying to register ${JSON.stringify(binding)}`)
|
|
||||||
|
|
||||||
let alreadyPresentBinding = this.userRegister.find(x => x.Discord == binding.Discord)
|
const binding: userNameBinding = {
|
||||||
if (alreadyPresentBinding) {
|
Steam: steamname,
|
||||||
console.log(`Binding already present: ${alreadyPresentBinding}, overwriting.`)
|
DiscordUser: discordUser
|
||||||
alreadyPresentBinding = binding
|
}
|
||||||
}
|
console.log(`Trying to register ${JSON.stringify(binding)}`)
|
||||||
else {
|
let alreadyPresentBinding = this.userRegister.find(x => x.DiscordUser.user.username == binding.DiscordUser.user.username)
|
||||||
this.userRegister.push(binding)
|
if (alreadyPresentBinding) {
|
||||||
console.log(`Binding successfully added.`)
|
console.log(`Binding already present: ${JSON.stringify(alreadyPresentBinding)}, overwriting.`)
|
||||||
|
alreadyPresentBinding = binding
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.userRegister.push(binding)
|
||||||
|
console.log(`Binding successfully added.`)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
public getAllMappings(): userNameBinding[] { return this.userRegister }
|
public getAllMappings(): userNameBinding[] {
|
||||||
public removeUser(discordName: string): void { this.userRegister = this.userRegister.filter(x => x.Discord !== discordName) }
|
return this.userRegister
|
||||||
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 removeUser(discordUser: GuildMember): void {
|
||||||
public listRegisteredMembers(): string { return JSON.stringify(this.userRegister) }
|
this.userRegister = this.userRegister.filter(x => x.DiscordUser.user.id !== discordUser.user.id)
|
||||||
|
}
|
||||||
|
public getNameRegisteredForDiscordUser(discordUser: GuildMember): Maybe<userNameBinding> {
|
||||||
|
return this.userRegister.find(x => x.DiscordUser.user.id == discordUser.user.id)
|
||||||
|
}
|
||||||
|
public getNameRegisteredForSteamUser(steamUser: string): Maybe<userNameBinding> {
|
||||||
|
return this.userRegister.find(x => x.Steam == steamUser)
|
||||||
|
}
|
||||||
|
public listRegisteredMembers(): string {
|
||||||
|
const output = this.userRegister.map(x => `${x.DiscordUser.user.username} : ${x.Steam}\n`)
|
||||||
|
return output.join()
|
||||||
|
}
|
||||||
private printHelpText(): string { return "" }
|
private printHelpText(): string { return "" }
|
||||||
private buildHelpText(): string { return "" }
|
private buildHelpText(): string { return "" }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user