HashPersistence
class Tourmaline::HashPersistence
inherits Tourmaline::Persistence
#
Stores all persisted data in memory using a collection of hash tables.
Direct known subclasses#
Tourmaline::JsonPersistence
Class methods#
.new(filename = nil)
#
(filename = nil)
Methods#
#chat_exists?(chat_id : Int) : Bool
#
(chat_id : Int) : Bool
Returns true if the chat with the provided chat_id
exists.
#chat_exists?(username : String) : Bool
#
(username : String) : Bool
Returns true if the chat with the provided username
exists.
#cleanup
#
Gets called upon exit. It can be used to perform any necessary cleanup.
#filename : String
#
: String
#get_chat(chat_id : Int) : Chat?
#
(chat_id : Int) : Chat?
Fetches a chat by chat_id
. Returns nil
if the chat is not found.
#get_chat(username : String) : Chat?
#
(username : String) : Chat?
Fetches a chat by username
. Returns nil
if the chat is not found.
#get_user(user_id : Int) : User?
#
(user_id : Int) : User?
Fetches a user by user_id
. Returns nil
if the user is not found.
#get_user(username : String) : User?
#
(username : String) : User?
Fetches a user by username
. Returns nil
if the user is not found.
#handle_update(update : Update)
#
(update : Update)
Takes an Update
object, pulls out all unique Chat
s and User
s,
and uses update_user
and update_chat
on each of them respectively.
#init
#
Gets called when the bot is initialized. This can be used for setup if you need access to the bot instance.
#persisted_chat_ids : Hash(String, Int64)
#
: Hash(String, Int64)
#persisted_chats : Hash(Int64, Tourmaline::Chat)
#
: Hash(Int64, Tourmaline::Chat)
#persisted_user_ids : Hash(String, Int64)
#
: Hash(String, Int64)
#persisted_users : Hash(Int64, Tourmaline::User)
#
: Hash(Int64, Tourmaline::User)
#update_chat(chat : Chat) : Chat
#
(chat : Chat) : Chat
Create or update the provided Chat
.
#update_user(user : User) : User
#
(user : User) : User
Create or update the provided User
.
#user_exists?(user_id : Int) : Bool
#
(user_id : Int) : Bool
Returns true if the user with the provided user_id
exists.
#user_exists?(username : String) : Bool
#
(username : String) : Bool
Returns true if the user with the provided username
exists.