You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

46 lines
1.3 KiB

import {userSnowflakeToUuid, UsersTable} from "../users.js"
import {Snowflake} from "discord-api-types/globals.js"
interface InMemoryUserData {
id: string,
is_admin: boolean
active_at: Date | null
}
export class InMemoryUsersTable implements UsersTable {
private readonly _users: Record<string, InMemoryUserData> = {}
async createBotOwnerAsAdmin(snowflake: Snowflake): Promise<void> {
const uuid = userSnowflakeToUuid(snowflake)
this._users[uuid] = {
id: uuid,
is_admin: true,
active_at: null,
}
}
async getActiveSnowflakeIsAdmin(snowflake: Snowflake): Promise<boolean> {
const uuid = userSnowflakeToUuid(snowflake)
if (!this._users.hasOwnProperty(uuid)) {
this._users[uuid] = {
id: uuid,
is_admin: false,
active_at: new Date(),
}
}
const user = this._users[uuid]
return user.is_admin
}
async getUuidForActiveSnowflake(snowflake: Snowflake): Promise<string> {
const uuid = userSnowflakeToUuid(snowflake)
if (!this._users.hasOwnProperty(uuid)) {
this._users[uuid] = {
id: uuid,
is_admin: false,
active_at: new Date(),
}
}
return uuid
}
}