Class: Rubot::Client
- Inherits:
-
Discordrb::Bot
- Object
- Discordrb::Bot
- Rubot::Client
show all
- Includes:
- ApplicationCommand
- Defined in:
- lib/rubot/classes/client.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_application_command, #launch_application_commands
Constructor Details
#initialize(application_commands_path:, commands_path: nil, events_path: nil) ⇒ Client
15
16
17
18
|
# File 'lib/rubot/classes/client.rb', line 15
def initialize(application_commands_path:, commands_path: nil, events_path: nil)
@manager = Manager.new(:application_commands_path => application_commands_path, :commands_path => commands_path, :events_path => events_path)
super(:token => ENV["BOT_TOKEN"], :intents => :all, :ignore_bots => true)
end
|
Instance Attribute Details
#application_commands_queue ⇒ Object
Returns the value of attribute application_commands_queue.
12
13
14
|
# File 'lib/rubot/classes/client.rb', line 12
def application_commands_queue
@application_commands_queue
end
|
#commands ⇒ Object
Returns the value of attribute commands.
12
13
14
|
# File 'lib/rubot/classes/client.rb', line 12
def commands
@commands
end
|
#events ⇒ Object
Returns the value of attribute events.
12
13
14
|
# File 'lib/rubot/classes/client.rb', line 12
def events
@events
end
|
#manager ⇒ Object
Returns the value of attribute manager.
12
13
14
|
# File 'lib/rubot/classes/client.rb', line 12
def manager
@manager
end
|
Instance Method Details
#add_command(name:, &block) ⇒ Object
32
33
34
35
|
# File 'lib/rubot/classes/client.rb', line 32
def add_command(name:, &block)
@commands ||= Array[]
@commands << Command.new(block, :name => name)
end
|
#add_event(attributes = {}, name:, &block) ⇒ Object
37
38
39
40
|
# File 'lib/rubot/classes/client.rb', line 37
def add_event(attributes = {}, name:, &block)
@events ||= Array[]
@events << Event.new(block, attributes, :name => name)
end
|
#command(name) ⇒ Object
42
43
44
|
# File 'lib/rubot/classes/client.rb', line 42
def command(name)
@commands[name] || false
end
|
#event(name) ⇒ Object
46
47
48
|
# File 'lib/rubot/classes/client.rb', line 46
def event(name)
@events[name] || false
end
|
#remove_application_commands ⇒ Object
50
51
52
53
54
55
|
# File 'lib/rubot/classes/client.rb', line 50
def remove_application_commands
get_application_commands.map(&:id).each do |id|
delete_application_command(id)
end
@application_commands = Array[]
end
|
#run(background = false) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rubot/classes/client.rb', line 20
def run(background = false)
@manager.load
launch_application_commands
@events&.each(&:run)
Thread.new do
loop do
stop if $stdin.gets.chomp.downcase.match?(/^\.exit/)
end
end
super(background)
end
|