abstract class PrivateParlorXT::UpdateHandler

Overview

A base class for handling one of the Telegram updates (Tourmaline::Text, Tourmaline::Photo, Tourmaline::ForwardedMessage, etc).

Handlers that are meant to work with Telegram updates should inherit this class, and include an On annotation to have it be usable by the bot.

Direct Known Subclasses

Defined in:

private-parlor-xt/handlers/update_handler.cr

Macro Summary

Instance Method Summary

Instance methods inherited from class PrivateParlorXT::Handler

do(message : Tourmaline::Message, services : Services) : Nil do, reply_message(user : User, message : Tourmaline::Message, services : Services) : Tourmaline::Message | Nil reply_message, reply_user(user : User, reply_message : Tourmaline::Message, services : Services) : User | Nil reply_user, unique?(user : User, message : Tourmaline::Message, services : Services, text : String | Nil = nil) : Bool unique?, update_user_activity(user : User, services : Services) : Nil update_user_activity

Constructor methods inherited from class PrivateParlorXT::Handler

new(config : Config) new

Macro Detail

macro return_on_command(text) #

Returns early if the message text contains a command.

Iterates through all HearsHandlers that are meant to be commands, and returns early if the handler matches a substring in the text (for RegexLiteral patterns) or if the handler starts with a substring (for StringLiteral patterns)


[View source]

Instance Method Detail

def authorized?(user : User, message : Tourmaline::Message, authority : MessagePermissions, services : Services) : Bool #

Returns true if user is authorized to send this type of message (one of the MessagePermissions types).

Returns false otherwise.


[View source]
def deny_user(user : User, services : Services) : Nil #

Queues a system reply when the user cannot chat due to being either cooldowned, blacklisted, media limited, or left.


[View source]
def meets_requirements?(message : Tourmaline::Message) : Bool #

Returns true if the message is not a forward or an album.

Returns false otherwise.


[View source]
def message_receivers(user : User, services : Services) : Array(UserID) #

Returns an array of UserID for which the relayed message will be sent to

If the given User has debug mode enabled, he will get a copy of the relayed message


[View source]
def record_message_statistics(type : Statistics::Messages, services : Services) : Nil #

If the statistics module is enabled, update the message_stats for the given type by incrementing the totals.


[View source]
def reply_receivers(message : Tourmaline::Message, user : User, services : Services) : Hash(UserID, ReplyParameters) | Nil #

Returns a hash of a receiver's UserID to the relevant message ID for which this message will reply to when relayed. When quoting, the ReplyParameters value will contain the replied message's quote if it is not invalid (i.e., user quoted his own message and it had strippable entities or was edited)

The hash will be empty if the message does not have a reply

Returns nil if the message had a reply, but no receiver message IDs could be found (message replied to is no longer in the cache)


[View source]
def user_from_message(message : Tourmaline::Message, services : Services) : User | Nil #

Returns the User associated with the message if the User could be found in the Database. This will also update the User's username and realname if they have changed since the last message.

Returns nil if:

  • Message has no sender
  • Message is a command
  • User does not exist in the Database
  • User cannot chat right now (due to a cooldown, blacklist, media limit, or having left the chat)

[View source]