class PrivateParlor

Included Modules

Defined in:

privateparlor/telegram.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(config : Config) #

Creates a new instance of PrivateParlor.

Arguments:

config : a Config from parsing the config.yaml file


[View source]

Instance Method Detail

def access : AuthorizedRanks #

[View source]
def albums : Hash(String, Album) #

[View source]
def allow_media_spoilers : Bool | Nil #

[View source]
def blacklist_command(ctx : CommandHandler::Context) : Nil #

Blacklists a user from the chat, deletes the reply, and removes all the user's incoming and outgoing messages from the queue.

Checks for the following permissions: blacklist

If blacklist, allows the user to blacklist another user.


[View source]
def blacklist_contact : String | Nil #

[View source]
def check_r9k_media(file_id : String, user : Database::User) : Bool | Nil #

[View source]
def check_text(text : String, user : Database::User, msid : Int64, entities : Array(Tourmaline::MessageEntity)) : String | Nil #

Checks if the text contains a special font or starts a sign command.

Returns the given text or a formatted text if it is allowed; nil if otherwise or a sign command could not be used.


[View source]
def command_disabled(ctx : CommandHandler::Context) : Nil #

Sends a message to the user if a disabled command is used


[View source]
def cooldown_time_begin : Array(Int32) #

[View source]
def cooldown_time_linear_b : Int32 #

[View source]
def cooldown_time_linear_m : Int32 #

[View source]
def database : Database #

[View source]
def default_rank : Int32 #

[View source]
def delete_command(ctx : CommandHandler::Context) : Nil #

Delete a message from a user, give a warning and a cooldown.

Checks for the following permissions: delete

If delete, allows the user to delete a message


[View source]
def delete_messages(msid : Int64, user_id : Int64, debug_enabled : Bool | Nil) : Int64 | Nil #

Deletes the given message for all receivers and removes it from the message history.

Returns the sender's (user_id) original message id upon success.


[View source]
def demote_command(ctx : CommandHandler::Context) : Nil #

Demotes a user to a given rank.

Checks for the following permissions: demote

If used with a reply, the reply user is demoted to either the user rank or a given rank.


[View source]
def demote_from_args(user : Database::User, args : Array(String) | Nil, msid : Int64) : Nil #

[View source]
def demote_from_reply(user : Database::User, arg : String | Nil, msid : Int64, reply : Int64) : Nil #

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

Sends a message to the user explaining why they cannot chat at this time


[View source]
def downvote_command(ctx : CommandHandler::Context) : Nil #

Downvotes a message.

Checks for the following permissions: downvote

If downvote, allows the user to downvote a message


[View source]
def downvote_limit_interval : Int32 #

[View source]
def enable_karma_sign : Bool | Nil #

[View source]
def enable_ranksay : Bool | Nil #

[View source]
def enable_sign : Bool | Nil #

[View source]
def enable_tripsign : Bool | Nil #

[View source]
def entity_types : Array(String) #

[View source]
def force_leave(user_id : Int64) : Nil #

Set blocked user to left in the database and delete all incoming messages from the queue.

Should only be invoked in #send_messages, as this does not check the queue_mutex


[View source]
def get_history_type(db : DB::Database, config : Config) : History | DatabaseHistory #

Determine appropriate History type based on given config variables


[View source]
def handle_animation(update : Tourmaline::Update) : Nil #

Prepares a "animation" message for relaying.


[View source]
def handle_audio(update : Tourmaline::Update) : Nil #

Prepares a "audio" message for relaying.


[View source]
def handle_basketball(update : Tourmaline::Update) : Nil #

Prepares a "basketball" message for relaying.


[View source]
def handle_bowling(update : Tourmaline::Update) : Nil #

Prepares a "bowling" message for relaying.


[View source]
def handle_contact(update : Tourmaline::Update) : Nil #

Prepares a contact message for relaying.


[View source]
def handle_dart(update : Tourmaline::Update) : Nil #

Prepares a "dart" message for relaying.


[View source]
def handle_dice(update : Tourmaline::Update) : Nil #

Prepares a "dice" message for relaying.


[View source]
def handle_document(update : Tourmaline::Update) : Nil #

Prepares a "document" message for relaying.


[View source]
def handle_embedded_command(text : String, user : Database::User, msid : Int64) : String | Nil #

[View source]
def handle_forwarded_message(update : Tourmaline::Update) : Nil #

Prepares a forwarded message for relaying.


[View source]
def handle_karma_sign(text : String, user : Database::User, msid : Int64) : String | Nil #

Given a command text, checks if karma signs are enabled and if the karma sign would be spammy, then returns the argument with a karma level signature


[View source]
def handle_location(update : Tourmaline::Update) : Nil #

Prepares a location message for relaying.


[View source]
def handle_media_group(update : Tourmaline::Update) : Nil #

Prepares an album message for relaying.


[View source]
def handle_photo(update : Tourmaline::Update) : Nil #

Prepares a "photo" message for relaying.


[View source]
def handle_poll(update : Tourmaline::Update) : Nil #

Prepares a poll for relaying.


[View source]
def handle_ranksay(rank : String, text : String, user : Database::User, msid : Int64) : String | Nil #

Given a ranked say command, checks if ranked says are enabled and determines the rank (either given or the user's current rank), then returns the argument with a ranked signature

Checks for the following permissions: ranksay, ranksay_lower

If ranksay, allows the user to sign a message with the user's rank name.

If ranksay_lower, allows the user to sign a message with the user's rank name and any subordinate rank.


[View source]
def handle_regular_forward(message : Tourmaline::Message, user : Database::User) : Nil #

[View source]
def handle_sign(text : String, user : Database::User, msid : Int64) : String | Nil #

Given a command text, checks if signs are enabled, user has private forwards, or sign would be spammy, then returns the argument with a username signature

Checks for the following permissions: sign

If sign, allows the user to sign a message


[View source]
def handle_slot_machine(update : Tourmaline::Update) : Nil #

Prepares a "slot_machine" message for relaying.


[View source]
def handle_soccerball(update : Tourmaline::Update) : Nil #

Prepares a "soccerball" message for relaying.


[View source]
def handle_sticker(update : Tourmaline::Update) : Nil #

Prepares a sticker message for relaying.


[View source]
def handle_text(update : Tourmaline::Update) #

Prepares a text message for relaying.


[View source]
def handle_tripcode(text : String, user : Database::User, msid : Int64) : String | Nil #

Given a command text, checks if tripcodes are enabled, if tripcode would be spammy, or if user does not have a tripcode set, then returns the argument with a tripcode header

Checks for the following permissions: tsign

If tsign, allows the user to sign a message with a tripcode.


[View source]
def handle_venue(update : Tourmaline::Update) : Nil #

Prepares a venue message for relaying.


[View source]
def handle_video(update : Tourmaline::Update) : Nil #

Prepares a "video" message for relaying.


[View source]
def handle_video_note(update : Tourmaline::Update) : Nil #

Prepares a "video_note" message for relaying.


[View source]
def handle_voice(update : Tourmaline::Update) : Nil #

Prepares a "voice" message for relaying.


[View source]
def help_command(ctx : CommandHandler::Context) : Nil #

Returns a message containing all the commands that a user can use, according to the user's rank.


[View source]
def history : History | DatabaseHistory #

[View source]
def inactivity_limit : Int32 #

[View source]
def info_command(ctx : CommandHandler::Context) : Nil #

Returns a message containing the user's OID, username, karma, warnings, etc.

Checks for the following permissions: #ranked_info (for replies only)

If this is used with a reply, returns the user info of that message if the invoker is ranked.


[View source]
def initialize_handlers(descriptions : CommandDescriptions, config : Config) : Nil #

Initializes CommandHandlers and UpdateHandlers Also checks whether or not a command or media type is enabled via the config, and registers commands with BotFather


[View source]
def karma_info_command(ctx : CommandHandler::Context) : Nil #

[View source]
def karma_levels : Hash(Int32, String) #

[View source]
def karma_warn_penalty : Int32 #

[View source]
def kick_inactive_users : Nil #

Kicks any users that have been inactive for a duration of time.


[View source]
def linked_network : Hash(String, String) #

[View source]
def locale : Locale #

[View source]
def log_channel : String #

[View source]
def log_channel=(log_channel : String) #

[View source]
def log_output(log : String, params : Hash(String, String | Nil) = {"" => ""}) : Nil #

Formats and outputs given log message to the log (either STDOUT or a file, defined in config) with INFO severity.

Also outputs message to a given log channel, if available


[View source]
def media_disabled(update : Tourmaline::Update, type : String) : Nil #

Sends a message to the user if a disabled media type is sent


[View source]
def media_limit_period : Int32 #

[View source]
def motd_command(ctx : CommandHandler::Context) : Nil #

Replies with the motd/rules associated with this bot.

Checks for the following permissions: motd_set (only when an argument is given)

If the host invokes this command, the motd/rules can be set or modified.


[View source]
def pin_command(ctx : CommandHandler::Context) : Nil #

[View source]
def preliminary_message_check(update : Tourmaline::Update) : Tuple(Tourmaline::Message | Nil, Database::User | Nil) #

[View source]
def preliminary_message_check(ctx : CommandHandler::Context | Tourmaline::Update) : Tuple(Tourmaline::Message | Nil, Database::User | Nil) #

[View source]
def promote_command(ctx : CommandHandler::Context) : Nil #

Promotes a user to a given rank.

Checks for the following permissions: promote, promote_lower, promote_same

If promote, the reply user can be promoted to a rank lower or equal to the invoker's rank.

If promote_lower, the reply user can be promoted to a rank lower than the invoker's rank.

If promote_same, the reply user can only be promoted to the invoker's rank.

If used with a reply, the reply user is promoted to the invoker's rank or the given rank.


[View source]
def promote_from_args(user : Database::User, authority : CommandPermissions, args : Array(String) | Nil, msid : Int64) : Nil #

[View source]
def promote_from_reply(user : Database::User, authority : CommandPermissions, arg : String | Nil, msid : Int64, reply : Int64) : Nil #

[View source]
def pseudonymous : Bool | Nil #

[View source]
def purge_command(ctx : CommandHandler::Context) : Nil #

Delete all messages from recently blacklisted users.

Checks for the following permissions: purge

If purge, allows the user to run a purge


[View source]
def queue : MessageQueue #

[View source]
def r9k_cooldown : Int32 #

[View source]
def r9k_forwards : Bool | Nil #

[View source]
def r9k_media : Bool | Nil #

[View source]
def r9k_text : Bool | Nil #

[View source]
def r9k_warn : Bool | Nil #

[View source]
def ranked_info(user : Database::User, msid : Int64, reply : Int64) : Nil #

[View source]
def register_tasks(spam_interval_seconds : Int32) : Array(Tasker::Task) #

Starts various background tasks and stores them in a hash.


[View source]
def registration_open : Bool | Nil #

[View source]
def regular_forwards : Bool | Nil #

[View source]
def relay(reply_message : Tourmaline::Message | Nil, user : Database::User, cached_msid : Int64, proc : MessageProc) : Nil #

Caches a message and sends it to the queue for relaying.


[View source]
def relay(reply_message : Tourmaline::Message | Nil, user : Database::User, cached_msid : Array(Int64), proc : MessageProc) : Nil #

Caches an album message and sends it to the queue for relaying.


[View source]
def relay_album(message : Tourmaline::Message, album : String, user : Database::User, caption : String | Nil, entities : Array(MessageEntity) = [] of MessageEntity) : Nil #

[View source]
def relay_regular_forward(user : Database::User, message : Tourmaline::Message, text : String) : Nil #

[View source]
def relay_to_one(reply_message : Int64 | Nil, user : Int64, reply : String, params : Hash(String, String | Nil)) : Nil #

Relay a message to a single user. Used for system messages.


[View source]
def relay_to_one(reply_message : Int64 | Nil, user : Int64, text : String) #

Relay a message to a single user. Used for system messages.


[View source]
def remove_command(ctx : CommandHandler::Context) : Nil #

Remove a message from a user without giving a warning or cooldown.

Checks for the following permissions: remove

If remove, allows the user to remove a message


[View source]
def reveal_command(ctx : CommandHandler::Context) : Nil #

Privately reveal username to another user


[View source]
def revert_ranked_users : Nil #

Checks the database for any users that have ranks not found in the AuthorizedRanks hash.

If the rank is not valid, the user is reverted to the default user rank.


[View source]
def send_messages : Bool | Nil #

Receives a Message from the #queue, calls its proc, and adds the returned message id to the History

This function should be invoked in a Fiber.


[View source]
def sign_limit_interval : Int32 #

[View source]
def smileys : Array(String) #

[View source]
def spam_handler : SpamScoreHandler | Nil #

[View source]
def spamming?(id : Int64, msid : Int64, score : Float32) : Bool | Nil #

[View source]
def spamming_text?(id : Int64, msid : Int64, text : String) : Bool | Nil #

[View source]
def spoil_messages(msid : Int64, user_id : Int64, debug_enabled : Bool | Nil, input : InputMedia) : Bool | Nil #

Spoils the given media message for all receivers by editing the media with the given input.

Returns true on success, false or nil otherwise.


[View source]
def spoiler_command(ctx : CommandHandler::Context) : Nil #

Adds a spoiler overlay to a media message when replied to.

Checks for the following permissions: spoiler

If spoiler, allows the user to add a spoiler to a relayed media message.


[View source]
def start_command(ctx : CommandHandler::Context) : Nil #

User starts the bot and begins receiving messages.

If the user is not in the database, this will add the user to it

If blacklisted or joined, this will not allow them to rejoin

Left users can rejoin the bot with this command


[View source]
def stop_command(ctx : CommandHandler::Context) : Nil #

Stops the bot for the user.

This will set the user status to left, meaning the user will not receive any further messages.


[View source]
def tasks : Array(Tasker::Task) #

[View source]
def toggle_debug_command(ctx : CommandHandler::Context) : Nil #

Toggle the user's toggle_debug attribute.


[View source]
def toggle_karma_command(ctx : CommandHandler::Context) : Nil #

Toggle the user's hide_karma attribute.


[View source]
def tripcode_command(ctx : CommandHandler::Context) : Nil #

Set/modify/view the user's tripcode.


[View source]
def tripcode_salt : String #

[View source]
def uncooldown_command(ctx : CommandHandler::Context) : Nil #

Removes a cooldown and warning from a user if the user is in cooldown.

Checks for the following permissions: uncooldown

If uncooldown, allows the user to uncooldown another user


[View source]
def unpin_command(ctx : CommandHandler::Context) : Nil #

[View source]
def upvote_command(ctx : CommandHandler::Context) : Nil #

Upvotes a message.

Checks for the following permissions: upvote

If upvote, allows the user to upvote a message


[View source]
def upvote_limit_interval : Int32 #

[View source]
def user_info(user : Database::User, msid : Int64) : Nil #

[View source]
def users_command(ctx : CommandHandler::Context) : Nil #

Return a message containing the number of users in the bot.

Checks for the following permissions: users

If the user does not have the "users" permission, show the total numbers of users. Otherwise, return a message containing the number of joined, left, and blacklisted users.


[View source]
def valid_codepoints : Array(Range(Int32, Int32)) #

[View source]
def validate_r9k_media(file_id : String | Nil, user : Database::User, message : Tourmaline::Message) : String | Nil #

[View source]
def validate_r9k_text(text : String, user : Database::User, message : Tourmaline::Message) : Tuple(String | Nil, String | Nil) #

[View source]
def version_command(ctx : CommandHandler::Context) : Nil #

Returns a message containing the progam's version.


[View source]
def warn_command(ctx : CommandHandler::Context) : Nil #

Warns a message without deleting it. Gives the user who sent the message a warning and a cooldown.

Checks for the following permissions: warn

If warn, allows the user to warn a message


[View source]
def warn_expire_hours : Int32 #

[View source]
def whitelist_command(ctx : CommandHandler::Context) : Nil #

Whitelists a user, allowing the user to join the chat. Only applicable if registration is closed

Checks for the following permissions: whitelist

If whitelist, allows the user to whitelist another user by user ID.


[View source]