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 {
|
||||||
|
try {
|
||||||
|
|
||||||
const binding: userNameBinding = {
|
const binding: userNameBinding = {
|
||||||
Steam: steamname,
|
Steam: steamname,
|
||||||
Discord: discordname
|
DiscordUser: discordUser
|
||||||
}
|
}
|
||||||
console.log(`Trying to register ${JSON.stringify(binding)}`)
|
console.log(`Trying to register ${JSON.stringify(binding)}`)
|
||||||
|
let alreadyPresentBinding = this.userRegister.find(x => x.DiscordUser.user.username == binding.DiscordUser.user.username)
|
||||||
let alreadyPresentBinding = this.userRegister.find(x => x.Discord == binding.Discord)
|
|
||||||
if (alreadyPresentBinding) {
|
if (alreadyPresentBinding) {
|
||||||
console.log(`Binding already present: ${alreadyPresentBinding}, overwriting.`)
|
console.log(`Binding already present: ${JSON.stringify(alreadyPresentBinding)}, overwriting.`)
|
||||||
alreadyPresentBinding = binding
|
alreadyPresentBinding = binding
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.userRegister.push(binding)
|
this.userRegister.push(binding)
|
||||||
console.log(`Binding successfully added.`)
|
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