class Tourmaline::HashPersistence

Overview

Stores all persisted data in memory using a collection of hash tables.

Direct Known Subclasses

Defined in:

Constructors

Instance Method Summary

Instance methods inherited from class Tourmaline::Persistence

chat_exists?(chat_id : Int) : Bool
chat_exists?(username : String) : Bool
chat_exists?
, cleanup cleanup, get_chat(chat_id : Int) : Chat?
get_chat(username : String) : Chat?
get_chat
, get_user(user_id : Int) : User?
get_user(username : String) : User?
get_user
, handle_update(update : Update) handle_update, init init, update_chat(chat : Chat) : Chat update_chat, update_user(user : User) : User update_user, user_exists?(user_id : Int) : Bool
user_exists?(usename : String) : Bool
user_exists?

Constructor Detail

def self.new(filename = nil) #

Instance Method Detail

def chat_exists?(chat_id : Int) : Bool #
Description copied from class Tourmaline::Persistence

Returns true if the chat with the provided chat_id exists.


def chat_exists?(username : String) : Bool #
Description copied from class Tourmaline::Persistence

Returns true if the chat with the provided username exists.


def cleanup #
Description copied from class Tourmaline::Persistence

Gets called upon exit. It can be used to perform any necessary cleanup.


def filename : String #

def get_chat(chat_id : Int) : Chat? #
Description copied from class Tourmaline::Persistence

Fetches a chat by chat_id. Returns nil if the chat is not found.


def get_chat(username : String) : Chat? #
Description copied from class Tourmaline::Persistence

Fetches a chat by username. Returns nil if the chat is not found.


def get_user(user_id : Int) : User? #
Description copied from class Tourmaline::Persistence

Fetches a user by user_id. Returns nil if the user is not found.


def get_user(username : String) : User? #
Description copied from class Tourmaline::Persistence

Fetches a user by username. Returns nil if the user is not found.


def handle_update(update : Update) #
Description copied from class Tourmaline::Persistence

Takes an Update object, pulls out all unique Chats and Users, and uses #update_user and #update_chat on each of them respectively.


def init #
Description copied from class Tourmaline::Persistence

Gets called when the bot is initialized. This can be used for setup if you need access to the bot instance.


def persisted_chat_ids : Hash(String, Int64) #

def persisted_chats : Hash(Int64, Tourmaline::Chat) #

def persisted_user_ids : Hash(String, Int64) #

def persisted_users : Hash(Int64, Tourmaline::User) #

def update_chat(chat : Chat) : Chat #
Description copied from class Tourmaline::Persistence

Create or update the provided Chat.


def update_user(user : User) : User #
Description copied from class Tourmaline::Persistence

Create or update the provided User.


def user_exists?(user_id : Int) : Bool #
Description copied from class Tourmaline::Persistence

Returns true if the user with the provided user_id exists.


def user_exists?(username : String) : Bool #
Description copied from class Tourmaline::Persistence

Returns true if the user with the provided username exists.