Skip to content

class Tourmaline::Handlers::CommandHandler
inherits Tourmaline::EventHandler #

Constants#

ANNOTATION = Command #

Class methods#

.new(commands, prefix = nil, group = :default, priority = 0, outgoing = true, private_only = false, group_only = false, admin_only = false, on_edit = false, register = false, register_as = nil, description = 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

Methods#

#admin_only : Bool #

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

View source

#admin_only=(admin_only : Bool) #

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

View source

#call(client : Client, update : Update) #

View source

#commands : Array(String) #

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

View source

#commands=(commands : Array(String)) #

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

View source

#description : String? #

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

View source

#description=(description : String?) #

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

View source

#group_only : Bool #

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

View source

#group_only=(group_only : Bool) #

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

View source

#on_edit : Bool #

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

View source

#on_edit=(on_edit : Bool) #

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

View source

#outgoing : Bool #

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

View source

#outgoing=(outgoing : Bool) #

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

View source

#prefixes : Array(String) #

Prefixes that commands should start with.

View source

#prefixes=(prefixes : Array(String)) #

Prefixes that commands should start with.

View source

#private_only : Bool #

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

View source

#private_only=(private_only : Bool) #

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

View source

#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

#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

#register_as : String? #

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

#register_as=(register_as : String?) #

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