class

PrivateParlorXT::UpdateHandler

Inherits PrivateParlorXT::Handler < Reference < Object

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.

Instance methods

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.

Source
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.

Source
meets_requirements?(message : Tourmaline::Message) : Bool

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

Returns false otherwise.

Source
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

Source
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.

Source
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)

Source
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)
Source

Macros

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)

Source