Class: SimpleXChat::BasicCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/simplex-chat/cmd-runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, desc = "", num_args: 0, min_role: GroupMemberRole::MEMBER, per_sender_cooldown_secs: nil, per_issuer_cooldown_secs: nil) ⇒ BasicCommand

TODO: Allow optional arguments



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simplex-chat/cmd-runner.rb', line 6

def initialize(name, desc="", num_args: 0, min_role: GroupMemberRole::MEMBER,
               per_sender_cooldown_secs: nil, per_issuer_cooldown_secs: nil)
  @name = name
  @num_args = num_args
  @desc = desc
  @min_role = min_role
  @per_sender_cooldown_secs = per_sender_cooldown_secs
  @per_issuer_cooldown_secs = per_issuer_cooldown_secs
  @last_runs = {
    :per_sender => {},
    :per_issuer => {}
  }
  @last_runs_lock = Mutex.new
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



3
4
5
# File 'lib/simplex-chat/cmd-runner.rb', line 3

def desc
  @desc
end

#min_roleObject (readonly)

Returns the value of attribute min_role.



3
4
5
# File 'lib/simplex-chat/cmd-runner.rb', line 3

def min_role
  @min_role
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/simplex-chat/cmd-runner.rb', line 3

def name
  @name
end

#num_argsObject (readonly)

Returns the value of attribute num_args.



3
4
5
# File 'lib/simplex-chat/cmd-runner.rb', line 3

def num_args
  @num_args
end

Instance Method Details

#validate_and_execute(client, chat_msg, args) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/simplex-chat/cmd-runner.rb', line 21

def validate_and_execute(client, chat_msg, args)
  return if not validate(client, chat_msg, args)
  begin
    execute client, chat_msg, args
  rescue
    client.api_send_text_message chat_msg[:chat_type], chat_msg[:sender], "@#{chat_msg[:contact]}: Failed to execute command"
  end
end