class Tourmaline::Handlers::CommandHandler

Defined in:

tourmaline/handlers/command_handler.cr

Constant Summary

ANNOTATION = Command

Constructors

Instance Method Summary

Instance methods inherited from class Tourmaline::EventHandler

call(update : Update) call, client : Client client, client=(client : Client) client=, client? : Client | Nil client?

Constructor Detail

def self.new(commands, prefix = nil, outgoing : Bool = true, private_only : Bool = false, group_only : Bool = false, on_edit : Bool = false, register : Bool = false, register_as : Nil | String = nil, description : Nil | String = nil, &block : Context -> ) #

Create a new CommandHandler instance using the provided #commands. #commands can be a single command string, or an array of possible commands.

!!! warning If #admin_only is true, get_chat_adminstrators will be run every time the handler is invoked. This should be fine in testing, but in production it's recommended to cache admins and do your own guarding.


[View source]

Instance Method Detail

def call(update : Update) #

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

Commands (without prefix) that this handler should respond to.


[View source]
def commands=(commands : Array(String)) #

Commands (without prefix) that this handler should respond to.


[View source]
def description : String | Nil #

Used when registering the command with BotFather. If #register is true, but this is not set, the command will not be registered.


[View source]
def description=(description : String | Nil) #

Used when registering the command with BotFather. If #register is true, but this is not set, the command will not be registered.


[View source]
def group_only : Bool #

If true, this handler will only respond if the command is sent in a group.


[View source]
def group_only=(group_only : Bool) #

If true, this handler will only respond if the command is sent in a group.


[View source]
def on_edit : Bool #

If true, this handler will also run (or re-run) when messages are edited.


[View source]
def on_edit=(on_edit : Bool) #

If true, this handler will also run (or re-run) when messages are edited.


[View source]
def outgoing : Bool #

User API: if true, this command will only be activated by an outgoing message.


[View source]
def outgoing=(outgoing : Bool) #

User API: if true, this command will only be activated by an outgoing message.


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

Prefixes that commands should start with.


[View source]
def prefixes=(prefixes : Array(String)) #

Prefixes that commands should start with.


[View source]
def private_only : Bool #

If true, this handler will only respond if the command is sent in private.


[View source]
def private_only=(private_only : Bool) #

If true, this handler will only respond if the command is sent in private.


[View source]
def register : Bool #

Register this command with BotFather. Only works is #prefixes contains / (as it does by default), as non-botcommands can't be registed with BotFather.


[View source]
def register=(register : Bool) #

Register this command with BotFather. Only works is #prefixes contains / (as it does by default), as non-botcommands can't be registed with BotFather.


[View source]
def register_as : String | Nil #

By default the first command in #commands will be selected as the command name to register. If this property is set, it will be used instead.


[View source]
def register_as=(register_as : String | Nil) #

By default the first command in #commands will be selected as the command name to register. If this property is set, it will be used instead.


[View source]