class PrivateParlorXT::SQLiteDatabase

Overview

An implementation of Database that uses a SQLite database for storing information about SQLiteUser objects

Defined in:

private-parlor-xt/database/SQLite/sqlite_database.cr

Constructors

Instance Method Summary

Instance methods inherited from class PrivateParlorXT::Database

active_users(exclude : UserID) : Array(UserID)
active_users : Array(UserID)
active_users
, add_user(id : UserID, username : String | Nil, realname : String, rank : Int32) : User | Nil add_user, blacklisted_users(time_limit : Time::Span) : Array(User)
blacklisted_users : Array(User)
blacklisted_users
, close close, expire_warnings(warn_lifespan : Time::Span) : Nil expire_warnings, get_user(id : UserID | Nil) : User | Nil get_user, get_user_by_arg(arg : String) : User | Nil get_user_by_arg, get_user_by_name(username : String) : User | Nil get_user_by_name, get_user_by_oid(oid : String) : User | Nil get_user_by_oid, inactive_users(time_limit : Time::Span) : Array(User) | Nil inactive_users, invalid_rank_users(valid_ranks : Array(Int32)) : Array(User) | Nil invalid_rank_users, motd : String | Nil motd, no_users? : Bool | Nil no_users?, set_motd(text : String) : Nil set_motd, update_user(user : User) : Nil update_user, user_counts : NamedTuple(total: Int32, left: Int32, blacklisted: Int32) user_counts, warned_users : Array(User) | Nil warned_users

Constructor methods inherited from class PrivateParlorXT::Database

new new

Constructor Detail

def self.new(connection : DB::Database) #

Creates an instance of SQLiteDatabase and ensures that the proper tables exist


[View source]

Instance Method Detail

def active_users(exclude : UserID) : Array(UserID) #

Queries the database for the most active users, ordered by highest ranking users first, then most active users.

Use this to exclude a user from the result (i.e., when a user does not have debug mode enabled)


[View source]
def active_users : Array(UserID) #

Queries the database for the most active users, ordered by highest ranking users first, then most active users.


[View source]
def add_user(id : UserID, username : String | Nil, realname : String, rank : Int32) : User | Nil #

Adds a user to the database


[View source]
def blacklisted_users(time_limit : Time::Span) : Array(User) #
Description copied from class PrivateParlorXT::Database

Get an array of recently blacklisted users


[View source]
def blacklisted_users : Array(User) #

Get an array of blacklisted users


[View source]
def close #

Close connection to the Database


[View source]
def ensure_schema : Nil #

Ensures that the SQLite database has both a 'system_config' and a 'users' table


[View source]
def expire_warnings(warn_lifespan : Time::Span) : Nil #

Queries the database for users with warnings and removes a warning

If the user still has warnings, the next time a warning is removed should be the current time plus the value of warn_lifespan

This should be invoked as a recurring task


[View source]
def get_user(id : UserID | Nil) : User | Nil #

Get user by UserID


[View source]
def get_user_by_name(username : String) : User | Nil #

Get user by username


[View source]
def get_user_by_oid(oid : String) : User | Nil #

Get user by a four-digit obfuscated ID


[View source]
def inactive_users(time_limit : Time::Span) : Array(User) #

Get users that have not been active within a given time limit


[View source]
def invalid_rank_users(valid_ranks : Array(Int32)) : Array(User) #

Get an array of users whose ranks are currently invalid


[View source]
def motd : String | Nil #

Gets the MOTD/rules, if they exist


[View source]
def no_users? : Bool | Nil #

Returns true if there are no users in the database False otherwise


[View source]
def set_motd(text : String) : Nil #

Sets the MOTD/rules to the given string


[View source]
def update_user(user : User) : Nil #

Updates a user with new data


[View source]
def user_counts : NamedTuple(total: Int32, left: Int32, blacklisted: Int32) #

Get the total count of users, users that have stopped the bot, and users that are blacklisted


[View source]
def warned_users : Array(User) #

Get an array of warned users


[View source]