Class: Xasin::Telegram::OnCommand

Inherits:
OnTelegramEvent show all
Defined in:
lib/xasin/telegram/OnCommand.rb

Instance Attribute Summary collapse

Attributes inherited from OnTelegramEvent

#priority

Instance Method Summary collapse

Methods inherited from OnTelegramEvent

#<=>

Constructor Details

#initialize(options) ⇒ OnCommand

Returns a new instance of OnCommand.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/xasin/telegram/OnCommand.rb', line 9

def initialize(options)
	super()

	@block = options[:block]
	@command = options[:command]

	@required_perms = [options[:permissions]].flatten.uniq

	@deny_message = options[:deny_msg] || 'You are not authorized, %s.'

	@priority += 5
end

Instance Attribute Details

#deny_messageObject

Returns the value of attribute deny_message.



6
7
8
# File 'lib/xasin/telegram/OnCommand.rb', line 6

def deny_message
  @deny_message
end

#required_permsObject

Returns the value of attribute required_perms.



7
8
9
# File 'lib/xasin/telegram/OnCommand.rb', line 7

def required_perms
  @required_perms
end

Instance Method Details

#nomp_message(message) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/xasin/telegram/OnCommand.rb', line 22

def nomp_message(message)
	return if message.handled
	return unless message.command == @command

	if message.user.has_permissions? @required_perms
		@block.call message
	else
		message.reply @deny_message % [message.user.casual_name]
	end
end