class Database

Defined in:

privateparlor/database.cr

Constructors

Instance Method Summary

Constructor Detail

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

Create an instance of Database and create the appropriate schema in the SQLite database.


[View source]

Instance Method Detail

def add_user(id, username, realname, rank = 0) : User | Nil #

Inserts a user with the given id, username, and realname into the database.

Returns the new User.


[View source]
def db : DB::Database #

[View source]
def ensure_schema : Nil #

Ensures that the DB schema is usable by the program.

This is the same schema used in secretlounge-ng SQLite databases.


[View source]
def expire_warnings(warn_expire_hours : Int32) : Nil #

Queries the database for warned users and removes warnings they have expired.


[View source]
def get_blacklisted_users : Array(User) | Nil #

Queries the database for blacklisted users who have been banned within the past 48 hours.

Returns an array of User or Nil if no users were found.


[View source]
def get_inactive_users(limit : Int32) : Array(User) | Nil #

[View source]
def get_invalid_rank_users(values : Array(Int32)) : Array(User) | Nil #

[View source]
def get_motd : String | Nil #

Retrieves the motd/rules from the database.

Returns the motd as a string, or returns nil if the motd could not be retrieved.


[View source]
def get_prioritized_users(user : User | Nil = nil) : Array(Int64) #

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


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

Queries the database for a user record with the given id.

Returns a User object.


[View source]
def get_user_by_arg(arg : String) : User | Nil #

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

Queries the database for a user with a given username.

Returns a User object or Nil if no user was found.


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

[View source]
def get_user_counts : NamedTuple #

[View source]
def get_warned_users : Array(User) | Nil #

Queries the database for all warned users that are in the chat.

Returns an array of User or Nil if no users were found.


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

Updates a user record in the database with the current state of user.


[View source]
def no_users? : Bool #

Queries the database for any rows in the user table

Returns true if can't move to next row (table is empty). False otherwise.


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

Sets the motd/rules to the given string.


[View source]