file description import { r } from "rethinkdb-ts" ; import { setupRethink } from "../scripts/setup" ; import { logger } from "../utils/logger" ; import config from "../../config.json" ; export function startRethink ( ) { return r . connectPool ( { db : config . database ?. db || undefined , password : config . database ?. password || undefined , port : config . database ?. port || 28015 , host : config . database ?. host || undefined , user : config . database ?. user || undefined , silent : true , } ) ; } startRethink ( ) . catch ( ( err ) => { logger . error ( `RethinkDB failed to start. Be sure the config file is setup properly and that it's running. Exiting. (error: ${ err })` ) ; process . exit ( 1 ) ; } ) . then ( async ( ) => { await setupRethink ( ) ; } ) ; export class RethinkProvider { db : typeof r ; dblock : any ; constructor ( ) { this . db = r ; this . dblock = this . db . db ( config . database . db ?? "db" ) . wait ( ) ; } /**
     * Guild config functions
     */ async getGuildConfig ( guild ) { await this . dblock ; return this . db . table ( "guildconfig" ) . get ( guild ) . run ( ) as Promise < GuildConfig > ; } async updateGuildConfig ( guild , config ) { await this . dblock ; return this . db . table ( "guildconfig" ) . get ( guild ) . update ( config ) . run ( ) ; } async replaceGuildConfig ( guild , config ) { await this . dblock ; return this . db . table ( "guildconfig" ) . get ( guild ) . replace ( config ) . run ( ) ; } async deleteGuildConfig ( guild ) { await this . dblock ; return this . db . table ( "guildconfig" ) . get ( guild ) . delete ( ) . run ( ) ; } async insertBlankGuildConfig ( guild ) { await this . dblock ; return this . db . table ( "guildconfig" ) . insert ( { id : guild } ) . run ( ) ; } /**
     * User config functions
     */ async getUserConfig ( user ) { await this . dblock ; return this . db . table ( "userconfig" ) . get ( user ) . run ( ) as Promise < UserConfig > ; } async updateUserConfig ( user , config ) { await this . dblock ; return this . db . table ( "userconfig" ) . get ( user ) . update ( config ) . run ( ) ; } async replaceUserConfig ( user , config ) { await this . dblock ; return this . db . table ( "userconfig" ) . get ( user ) . replace ( config ) . run ( ) ; } async deleteUserConfig ( user ) { await this . dblock ; return this . db . table ( "userconfig" ) . get ( user ) . delete ( ) . run ( ) ; } async insertBlankUserConfig ( user ) { await this . dblock ; return this . db . table ( "userconfig" ) . insert ( { id : user } ) . run ( ) ; } /**
     * Warning functions
     */ async getAllGuildWarnings ( guild ) { await this . dblock ; return this . db . table ( "warnings" ) . filter ( { guild : guild } ) . run ( ) as Promise < UserWarning [ ] > ; } async getUserWarning ( warning ) { await this . dblock ; return this . db . table ( "warnings" ) . get ( warning ) . run ( ) as Promise < UserWarning > ; } async getAllUserWarnings ( user ) { await this . dblock ; return this . db . table ( "warnings" ) . filter ( { receiver : user } ) . run ( ) as Promise < UserWarning [ ] > ; } async getAllUserGuildWarnings ( user , guild ) { await this . dblock ; return this . db . table ( "warnings" ) . filter ( { receiver : user , guild : guild } ) . run ( ) as Promise < UserWarning [ ] > ; } async insertUserWarning ( warning ) { await this . dblock ; return this . db . table ( "warnings" ) . insert ( warning ) . run ( ) ; } async deleteUserWarning ( user , id ) { await this . dblock ; return this . db . table ( "warnings" ) . filter ( { receiver : user , id : id } ) . delete ( ) . run ( ) ; } /**
     * Point functions
     */ async getAllGuildPoints ( guild ) { await this . dblock ; return this . db . table ( "points" ) . filter ( { guild : guild } ) . run ( ) as Promise < UserPoint [ ] > ; } async getUserPoint ( point ) { await this . dblock ; return this . db . table ( "points" ) . get ( point ) . run ( ) as Promise < UserPoint > ; } async getAllUserPoints ( user ) { await this . dblock ; return this . db . table ( "points" ) . filter ( { receiver : user } ) . run ( ) as Promise < UserPoint [ ] > ; } async getAllUserGuildPoints ( user , guild ) { await this . dblock ; return this . db . table ( "points" ) . filter ( { receiver : user , guild : guild } ) . run ( ) as Promise < UserPoint [ ] > ; } async insertUserPoint ( point ) { await this . dblock ; return this . db . table ( "points" ) . insert ( point ) . run ( ) ; } async deleteUserPoint ( user , id ) { await this . dblock ; return this . db . table ( "points" ) . filter ( { receiver : user , id : id } ) . delete ( ) . run ( ) ; } /**
     * Economy functions
     */ async getAllCookies ( ) { await this . dblock ; return this . db . table ( "economy" ) . run ( ) as Promise < UserCookies [ ] > ; } async getUserCookies ( user ) { await this . dblock ; return this . db . table ( "economy" ) . get ( user ) . run ( ) as Promise < UserCookies > ; } async updateUserCookies ( user , cookies ) { await this . dblock ; return this . db . table ( "economy" ) . get ( user ) . update ( cookies ) . run ( ) ; } async insertUserCookies ( cookies ) { await this . dblock ; return this . db . table ( "economy" ) . insert ( cookies ) . run ( ) ; } async insertBlankUserCookies ( user ) { await this . dblock ; return this . db . table ( "economy" ) . insert ( { id : user , amount : 0 , lastclaim : null } ) . run ( ) ; } /**
     * Reminder functions
     */ async getAllReminders ( ) { await this . dblock ; return this . db . table ( "reminders" ) . run ( ) ; } async getAllUserReminders ( user ) { await this . dblock ; return this . db . table ( "reminders" ) . filter ( { user : user } ) . run ( ) as Promise < Reminder [ ] > ; } async insertUserReminder ( reminder ) { await this . dblock ; return this . db . table ( "reminders" ) . insert ( reminder ) . run ( ) ; } async deleteUserReminder ( user , reminder ) { await this . dblock ; return this . db . table ( "reminders" ) . filter ( { id : reminder , user : user } ) . delete ( ) . run ( ) ; } /**
     * Marriage functions
     */ async getMarriageState ( user , member ) { await this . dblock ; return this . db . table ( "marriages" ) . getAll ( user , member , { index : "marriages" } ) . run ( ) as Promise < UserMarriage [ ] > ; } async getUserMarriage ( user ) { await this . dblock ; return this . db . table ( "marriages" ) . getAll ( user , { index : "marriages" } ) . run ( ) as Promise < UserMarriage [ ] > ; } async insertUserMarriage ( user , member ) { await this . dblock ; return this . db . table ( "marriages" ) . insert ( { id : user , spouse : member } ) . run ( ) ; } async deleteUserMarriage ( user ) { await this . dblock ; return this . db . table ( "marriages" ) . getAll ( user , { index : "marriages" } ) . delete ( ) . run ( ) ; } /**
     * Mute cache functions
     */ async getMuteCache ( ) { await this . dblock ; return this . db . table ( "mutecache" ) . run ( ) as Promise < MuteCache [ ] > ; } async getGuildMuteCache ( guild ) { await this . dblock ; return this . db . table ( "mutecache" ) . filter ( { guild : guild } ) . run ( ) as Promise < MuteCache [ ] > ; } async getUserMuteCache ( user ) { await this . dblock ; return this . db . table ( "mutecache" ) . filter ( { member : user } ) . run ( ) as Promise < MuteCache [ ] > ; } async getUserGuildMuteCache ( guild , user ) { await this . dblock ; return this . db . table ( "mutecache" ) . filter ( { guild : guild , member : user } ) . run ( ) as Promise < MuteCache [ ] > ; } async deleteUserGuildMuteCache ( guild , user ) { await this . dblock ; return this . db . table ( "mutecache" ) . filter ( { guild : guild , member : user } ) . delete ( ) . run ( ) ; } async insertMuteCache ( config ) { await this . dblock ; return this . db . table ( "mutecache" ) . insert ( config ) . run ( ) ; } /**
     * Steam monitoring functions
     */ async getAllMonitors ( ) { await this . dblock ; return this . db . table ( "monitoring" ) . run ( ) as Promise < SteamMonitor [ ] > ; } async getAllUserMonitors ( user ) { await this . dblock ; return this . db . table ( "monitoring" ) . filter ( { user : user } ) . run ( ) as Promise < SteamMonitor [ ] > ; } async deleteUserMonitor ( user , id ) { await this . dblock ; return this . db . table ( "monitoring" ) . filter ( { id : id , user : user } ) . delete ( ) . run ( ) ; } async insertUserMonitor ( monitor ) { await this . dblock ; return this . db . table ( "monitoring" ) . insert ( monitor ) . run ( ) ; } /**
     * Blacklist functions
     */ async getBlacklist ( ) { await this . dblock ; return this . db . table ( "blacklist" ) . run ( ) as Promise < BlacklistInfo [ ] > ; } async getBlacklistedGuild ( guild ) { await this . dblock ; return this . db . table ( "blacklist" ) . filter ( { id : guild , guild : true } ) . run ( ) ; } async getBlacklistedUser ( user ) { await this . dblock ; return this . db . table ( "blacklist" ) . filter ( { id : user , user : true } ) . run ( ) ; } async insertBlacklistedItem ( item ) { await this . dblock ; return this . db . table ( "blacklist" ) . insert ( item ) . run ( ) ; } async deleteBlacklistedItem ( item ) { await this . dblock ; return this . db . table ( "blacklist" ) . get ( item ) . delete ( ) . run ( ) ; } }