activematrix 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +218 -51
  3. data/lib/active_matrix/agent_manager.rb +275 -0
  4. data/lib/active_matrix/agent_registry.rb +154 -0
  5. data/lib/{matrix_sdk → active_matrix}/api.rb +18 -22
  6. data/lib/{matrix_sdk → active_matrix}/bot/base.rb +42 -39
  7. data/lib/{matrix_sdk → active_matrix}/bot/main.rb +4 -5
  8. data/lib/active_matrix/bot/multi_instance_base.rb +189 -0
  9. data/lib/active_matrix/bot.rb +7 -0
  10. data/lib/{matrix_sdk → active_matrix}/client.rb +21 -34
  11. data/lib/active_matrix/client_pool.rb +194 -0
  12. data/lib/{matrix_sdk → active_matrix}/errors.rb +4 -4
  13. data/lib/active_matrix/event_router.rb +215 -0
  14. data/lib/active_matrix/logging.rb +56 -0
  15. data/lib/active_matrix/memory/agent_memory.rb +128 -0
  16. data/lib/active_matrix/memory/base.rb +101 -0
  17. data/lib/active_matrix/memory/conversation_memory.rb +161 -0
  18. data/lib/active_matrix/memory/global_memory.rb +153 -0
  19. data/lib/active_matrix/memory.rb +28 -0
  20. data/lib/{matrix_sdk → active_matrix}/mxid.rb +2 -2
  21. data/lib/{matrix_sdk → active_matrix}/protocols/as.rb +1 -1
  22. data/lib/{matrix_sdk → active_matrix}/protocols/cs.rb +6 -8
  23. data/lib/{matrix_sdk → active_matrix}/protocols/is.rb +1 -1
  24. data/lib/{matrix_sdk → active_matrix}/protocols/msc.rb +6 -8
  25. data/lib/{matrix_sdk → active_matrix}/protocols/ss.rb +2 -2
  26. data/lib/active_matrix/railtie.rb +18 -0
  27. data/lib/{matrix_sdk → active_matrix}/response.rb +2 -2
  28. data/lib/{matrix_sdk → active_matrix}/room.rb +148 -72
  29. data/lib/{matrix_sdk → active_matrix}/rooms/space.rb +3 -7
  30. data/lib/{matrix_sdk → active_matrix}/user.rb +23 -15
  31. data/lib/active_matrix/util/account_data_cache.rb +129 -0
  32. data/lib/active_matrix/util/cacheable.rb +73 -0
  33. data/lib/{matrix_sdk → active_matrix}/util/events.rb +8 -8
  34. data/lib/{matrix_sdk → active_matrix}/util/extensions.rb +6 -15
  35. data/lib/active_matrix/util/state_event_cache.rb +167 -0
  36. data/lib/{matrix_sdk → active_matrix}/util/uri.rb +4 -4
  37. data/lib/active_matrix/version.rb +5 -0
  38. data/lib/active_matrix.rb +81 -0
  39. data/lib/generators/active_matrix/bot/bot_generator.rb +38 -0
  40. data/lib/generators/active_matrix/bot/templates/bot.rb.erb +111 -0
  41. data/lib/generators/active_matrix/bot/templates/bot_spec.rb.erb +68 -0
  42. data/lib/generators/active_matrix/install/install_generator.rb +44 -0
  43. data/lib/generators/active_matrix/install/templates/README +30 -0
  44. data/lib/generators/active_matrix/install/templates/active_matrix.rb +33 -0
  45. data/lib/generators/active_matrix/install/templates/agent_memory.rb +47 -0
  46. data/lib/generators/active_matrix/install/templates/conversation_context.rb +72 -0
  47. data/lib/generators/active_matrix/install/templates/create_agent_memories.rb +17 -0
  48. data/lib/generators/active_matrix/install/templates/create_conversation_contexts.rb +21 -0
  49. data/lib/generators/active_matrix/install/templates/create_global_memories.rb +20 -0
  50. data/lib/generators/active_matrix/install/templates/create_matrix_agents.rb +26 -0
  51. data/lib/generators/active_matrix/install/templates/global_memory.rb +70 -0
  52. data/lib/generators/active_matrix/install/templates/matrix_agent.rb +127 -0
  53. metadata +168 -30
  54. data/lib/matrix_sdk/bot.rb +0 -4
  55. data/lib/matrix_sdk/util/account_data_cache.rb +0 -91
  56. data/lib/matrix_sdk/util/state_event_cache.rb +0 -92
  57. data/lib/matrix_sdk/util/tinycache.rb +0 -140
  58. data/lib/matrix_sdk/util/tinycache_adapter.rb +0 -87
  59. data/lib/matrix_sdk/version.rb +0 -5
  60. data/lib/matrix_sdk.rb +0 -75
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+ require 'concurrent'
5
+
6
+ module ActiveMatrix
7
+ # Thread-safe registry for managing running bot agents
8
+ class AgentRegistry
9
+ include Singleton
10
+ include ActiveMatrix::Logging
11
+
12
+ def initialize
13
+ @agents = Concurrent::Hash.new
14
+ @mutex = Mutex.new
15
+ end
16
+
17
+ # Register a running agent
18
+ def register(agent_record, bot_instance)
19
+ @mutex.synchronize do
20
+ raise AgentAlreadyRunningError, "Agent #{agent_record.name} is already running" if @agents.key?(agent_record.id)
21
+
22
+ @agents[agent_record.id] = {
23
+ record: agent_record,
24
+ instance: bot_instance,
25
+ thread: Thread.current,
26
+ started_at: Time.current
27
+ }
28
+
29
+ logger.info "Registered agent: #{agent_record.name} (#{agent_record.id})"
30
+ end
31
+ end
32
+
33
+ # Unregister an agent
34
+ def unregister(agent_record)
35
+ @mutex.synchronize do
36
+ entry = @agents.delete(agent_record.id)
37
+ logger.info "Unregistered agent: #{agent_record.name} (#{agent_record.id})" if entry
38
+ entry
39
+ end
40
+ end
41
+
42
+ # Get a running agent by ID
43
+ def get(agent_id)
44
+ @agents[agent_id]
45
+ end
46
+
47
+ # Get agent by name
48
+ def get_by_name(name)
49
+ @agents.values.find { |entry| entry[:record].name == name }
50
+ end
51
+
52
+ # Get all running agents
53
+ def all
54
+ @agents.values
55
+ end
56
+
57
+ # Get all agent records
58
+ def all_records
59
+ @agents.values.map { |entry| entry[:record] }
60
+ end
61
+
62
+ # Get all bot instances
63
+ def all_instances
64
+ @agents.values.map { |entry| entry[:instance] }
65
+ end
66
+
67
+ # Check if an agent is running
68
+ def running?(agent_record)
69
+ @agents.key?(agent_record.id)
70
+ end
71
+
72
+ # Get agents by state
73
+ def by_state(state)
74
+ @agents.values.select { |entry| entry[:record].state == state.to_s }
75
+ end
76
+
77
+ # Get agents by bot class
78
+ def by_class(bot_class)
79
+ class_name = bot_class.is_a?(Class) ? bot_class.name : bot_class.to_s
80
+ @agents.values.select { |entry| entry[:record].bot_class == class_name }
81
+ end
82
+
83
+ # Get agents by homeserver
84
+ def by_homeserver(homeserver)
85
+ @agents.values.select { |entry| entry[:record].homeserver == homeserver }
86
+ end
87
+
88
+ # Broadcast to all agents
89
+ def broadcast
90
+ all_instances.each do |instance|
91
+ yield instance
92
+ rescue StandardError => e
93
+ logger.error "Error broadcasting to agent: #{e.message}"
94
+ end
95
+ end
96
+
97
+ # Broadcast to specific agents
98
+ def broadcast_to(selector)
99
+ agents = case selector
100
+ when Symbol
101
+ by_state(selector)
102
+ when String
103
+ by_name_pattern(selector)
104
+ when Class
105
+ by_class(selector)
106
+ when Proc
107
+ @agents.values.select { |entry| selector.call(entry[:record]) }
108
+ else
109
+ []
110
+ end
111
+
112
+ agents.each do |entry|
113
+ yield entry[:instance]
114
+ rescue StandardError => e
115
+ logger.error "Error broadcasting to agent #{entry[:record].name}: #{e.message}"
116
+ end
117
+ end
118
+
119
+ # Get count of running agents
120
+ def count
121
+ @agents.size
122
+ end
123
+
124
+ # Clear all agents (used for testing)
125
+ def clear!
126
+ @mutex.synchronize do
127
+ @agents.clear
128
+ end
129
+ end
130
+
131
+ # Get health status of all agents
132
+ def health_status
133
+ @agents.map do |id, entry|
134
+ {
135
+ id: id,
136
+ name: entry[:record].name,
137
+ state: entry[:record].state,
138
+ thread_alive: entry[:thread]&.alive?,
139
+ uptime: Time.current - entry[:started_at],
140
+ last_active: entry[:record].last_active_at
141
+ }
142
+ end
143
+ end
144
+
145
+ private
146
+
147
+ def by_name_pattern(pattern)
148
+ regex = Regexp.new(pattern, Regexp::IGNORECASE)
149
+ @agents.values.select { |entry| entry[:record].name =~ regex }
150
+ end
151
+ end
152
+
153
+ class AgentAlreadyRunningError < StandardError; end
154
+ end
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'matrix_sdk'
4
-
5
3
  require 'erb'
6
4
  require 'net/http'
7
5
  require 'openssl'
8
6
  require 'uri'
9
7
 
10
- module MatrixSdk
8
+ module ActiveMatrix
11
9
  class Api
12
- extend MatrixSdk::Extensions
13
- include MatrixSdk::Logging
10
+ extend ActiveMatrix::Extensions
11
+ include ActiveMatrix::Logging
14
12
 
15
- USER_AGENT = "Ruby Matrix SDK v#{MatrixSdk::VERSION}"
13
+ USER_AGENT = "Ruby Matrix SDK v#{ActiveMatrix::VERSION}".freeze
16
14
  DEFAULT_HEADERS = {
17
15
  'accept' => 'application/json',
18
16
  'user-agent' => USER_AGENT
@@ -72,7 +70,7 @@ module MatrixSdk
72
70
  self.threadsafe = params.fetch(:threadsafe, :multithread)
73
71
 
74
72
  ([params.fetch(:protocols, [:CS])].flatten - protocols).each do |proto|
75
- self.class.include MatrixSdk::Protocols.const_get(proto)
73
+ self.class.include ActiveMatrix::Protocols.const_get(proto)
76
74
  end
77
75
 
78
76
  login(user: @homeserver.user, password: @homeserver.password) if @homeserver.user && @homeserver.password && !@access_token && !params[:skip_login] && protocol?(:CS)
@@ -84,7 +82,7 @@ module MatrixSdk
84
82
  # This will follow the server discovery spec for client-server and federation
85
83
  #
86
84
  # @example Opening a Matrix API connection to a homeserver
87
- # hs = MatrixSdk::API.new_for_domain 'example.com'
85
+ # hs = ActiveMatrix::API.new_for_domain 'example.com'
88
86
  # hs.connection_address
89
87
  # # => 'matrix.example.com'
90
88
  # hs.connection_port
@@ -97,10 +95,10 @@ module MatrixSdk
97
95
  # @return [API] The API connection
98
96
  def self.new_for_domain(domain, target: :client, keep_wellknown: false, ssl: true, **params)
99
97
  domain, port = domain.split(':')
100
- uri = URI("http#{ssl ? 's' : ''}://#{domain}")
98
+ uri = URI("http#{'s' if ssl}://#{domain}")
101
99
  well_known = nil
102
100
  target_uri = nil
103
- logger = ::Logging.logger[self]
101
+ logger = ActiveMatrix.logger
104
102
  logger.debug "Resolving #{domain}"
105
103
 
106
104
  if !port.nil? && !port.empty?
@@ -171,17 +169,15 @@ module MatrixSdk
171
169
 
172
170
  new(
173
171
  uri,
174
- **params.merge(
175
- address: target_uri.host,
176
- port: target_uri.port
177
- )
172
+ **params, address: target_uri.host,
173
+ port: target_uri.port
178
174
  )
179
175
  end
180
176
 
181
177
  # Get a list of enabled protocols on the API client
182
178
  #
183
179
  # @example
184
- # MatrixSdk::Api.new_for_domain('matrix.org').protocols
180
+ # ActiveMatrix::Api.new_for_domain('matrix.org').protocols
185
181
  # # => [:IS, :CS]
186
182
  #
187
183
  # @return [Symbol[]] An array of enabled APIs
@@ -189,7 +185,7 @@ module MatrixSdk
189
185
  self
190
186
  .class.included_modules
191
187
  .reject { |m| m&.name.nil? }
192
- .select { |m| m.name.start_with? 'MatrixSdk::Protocols::' }
188
+ .select { |m| m.name.start_with? 'ActiveMatrix::Protocols::' }
193
189
  .map { |m| m.name.split('::').last.to_sym }
194
190
  end
195
191
 
@@ -343,7 +339,7 @@ module MatrixSdk
343
339
  logger.error "Received non-parsable data in 200 response; #{response.body.inspect}"
344
340
  raise MatrixConnectionError, response
345
341
  end
346
- return MatrixSdk::Response.new self, data
342
+ return ActiveMatrix::Response.new self, data
347
343
  end
348
344
  raise MatrixRequestError.new_by_code(data, response.code) if data
349
345
 
@@ -394,11 +390,11 @@ module MatrixSdk
394
390
  return unless logger.debug?
395
391
 
396
392
  if http.is_a? Net::HTTPRequest
397
- dir = "#{id ? "#{id} : " : nil}>"
393
+ dir = "#{"#{id} : " if id}>"
398
394
  logger.debug "#{dir} Sending a #{http.method} request to `#{http.path}`:"
399
395
  else
400
- dir = "#{id ? "#{id} : " : nil}<"
401
- logger.debug "#{dir} Received a #{http.code} #{http.message} response:#{duration ? " [#{(duration * 1000).to_i}ms]" : nil}"
396
+ dir = "#{"#{id} : " if id}<"
397
+ logger.debug "#{dir} Received a #{http.code} #{http.message} response:#{" [#{(duration * 1000).to_i}ms]" if duration}"
402
398
  end
403
399
  http.to_hash.map { |k, v| "#{k}: #{k == 'authorization' ? '[ REDACTED ]' : v.join(', ')}" }.each do |h|
404
400
  logger.debug "#{dir} #{h}"
@@ -424,8 +420,8 @@ module MatrixSdk
424
420
  def http
425
421
  return @http if @http&.active?
426
422
 
427
- host = (@connection_address || homeserver.host)
428
- port = (@connection_port || homeserver.port)
423
+ host = @connection_address || homeserver.host
424
+ port = @connection_port || homeserver.port
429
425
 
430
426
  connection = @http unless @threadsafe == :multithread
431
427
  connection ||= if proxy_uri
@@ -2,9 +2,10 @@
2
2
 
3
3
  require 'shellwords'
4
4
 
5
- module MatrixSdk::Bot
5
+ module ActiveMatrix::Bot
6
6
  class Base
7
- extend MatrixSdk::Extensions
7
+ extend ActiveMatrix::Extensions
8
+ include ActiveMatrix::Logging
8
9
 
9
10
  RequestHandler = Struct.new('RequestHandler', :command, :type, :proc, :data) do
10
11
  def command?
@@ -29,14 +30,14 @@ module MatrixSdk::Bot
29
30
 
30
31
  def initialize(hs_url, **params)
31
32
  @client = case hs_url
32
- when MatrixSdk::Api
33
- MatrixSdk::Client.new hs_url
34
- when MatrixSdk::Client
33
+ when ActiveMatrix::Api
34
+ ActiveMatrix::Client.new hs_url
35
+ when ActiveMatrix::Client
35
36
  hs_url
36
37
  when %r{^https?://.*}
37
- MatrixSdk::Client.new hs_url, **params
38
+ ActiveMatrix::Client.new hs_url, **params
38
39
  else
39
- MatrixSdk::Client.new_for_domain hs_url, **params
40
+ ActiveMatrix::Client.new_for_domain hs_url, **params
40
41
  end
41
42
 
42
43
  @client.on_event.add_handler { |ev| _handle_event(ev) }
@@ -59,30 +60,23 @@ module MatrixSdk::Bot
59
60
  end
60
61
 
61
62
  def self.logger
62
- Logging.logger[self].tap do |l|
63
- begin
64
- l.level = :debug if MatrixSdk::Bot::PARAMS_CONFIG[:logging]
65
- rescue NameError
66
- # Not running as instance
67
- end
68
- l.level = settings.log_level unless settings.logging?
69
- end
63
+ @logger ||= ActiveMatrix.logger
70
64
  end
71
65
 
72
66
  # Register a command during runtime
73
67
  #
74
68
  # @param command [String] The command to register
75
69
  # @see Base.command for full parameter information
76
- def register_command(command, **params, &block)
77
- self.class.command(command, **params, &block)
70
+ def register_command(command, **params, &)
71
+ self.class.command(command, **params, &)
78
72
  end
79
73
 
80
74
  # Register an event during runtime
81
75
  #
82
76
  # @param event [String] The event to register
83
77
  # @see Base.event for full parameter information
84
- def register_event(event, **params, &block)
85
- self.class.event(event, **params, &block)
78
+ def register_event(event, **params, &)
79
+ self.class.event(event, **params, &)
86
80
  end
87
81
 
88
82
  # Removes a registered command during runtime
@@ -149,7 +143,7 @@ module MatrixSdk::Bot
149
143
  attr_reader :handlers
150
144
 
151
145
  CALLERS_TO_IGNORE = [
152
- /\/matrix_sdk\/.+\.rb$/, # all MatrixSdk code
146
+ /\/matrix_sdk\/.+\.rb$/, # all ActiveMatrix code
153
147
  /^\(.*\)$/, # generated code
154
148
  /rubygems\/(custom|core_ext\/kernel)_require\.rb$/, # rubygems require hacks
155
149
  /bundler(\/(?:runtime|inline))?\.rb/, # bundler require hacks
@@ -252,16 +246,16 @@ module MatrixSdk::Bot
252
246
  # @note Due to the way blocks are handled, required parameters won't block execution.
253
247
  # If your command requires all parameters to be valid, you will need to check for nil yourself.
254
248
  #
255
- # @note Execution will be performed with a MatrixSdk::Bot::Request object as self.
256
- # To access the bot instance, use MatrixSdk::Bot::Request#bot
249
+ # @note Execution will be performed with a ActiveMatrix::Bot::Request object as self.
250
+ # To access the bot instance, use ActiveMatrix::Bot::Request#bot
257
251
  #
258
252
  # @param command [String] The command to register, will be routed based on the prefix and bot NameError
259
253
  # @param desc [String] A human-readable description for the command
260
254
  # @param only [Symbol,Proc,Array[Symbol,Proc]] What limitations does this command have?
261
255
  # Can use :DM, :Admin, :Mod
262
256
  # @option params
263
- def command(command, desc: nil, notes: nil, only: nil, **params, &block)
264
- args = params[:args] || convert_to_lambda(&block).parameters.map do |type, name|
257
+ def command(command, desc: nil, notes: nil, only: nil, **params, &)
258
+ args = params[:args] || convert_to_lambda(&).parameters.map do |type, name|
265
259
  case type
266
260
  when :req
267
261
  name.to_s.upcase
@@ -281,7 +275,7 @@ module MatrixSdk::Bot
281
275
  desc: desc,
282
276
  notes: notes,
283
277
  only: [only].flatten.compact,
284
- &block
278
+ &
285
279
  )
286
280
  end
287
281
 
@@ -292,14 +286,14 @@ module MatrixSdk::Bot
292
286
  # @param event [String] The ID for the event to register
293
287
  # @param only [Symbol,Proc,Array[Symbol,Proc]] The limitations to when the event should be handled
294
288
  # @option params
295
- def event(event, only: nil, **_params, &block)
289
+ def event(event, only: nil, **_params, &)
296
290
  logger.debug "Registering event #{event}"
297
291
 
298
292
  add_handler(
299
293
  event.to_s,
300
294
  type: :event,
301
295
  only: [only].flatten.compact,
302
- &block
296
+ &
303
297
  )
304
298
  end
305
299
 
@@ -404,7 +398,7 @@ module MatrixSdk::Bot
404
398
  # Starts the bot up
405
399
  #
406
400
  # @param options [Hash] Settings to apply using Base.set
407
- def run!(options = {}, &block)
401
+ def run!(options = {}, &)
408
402
  return if running?
409
403
 
410
404
  set options
@@ -423,7 +417,7 @@ module MatrixSdk::Bot
423
417
  end
424
418
 
425
419
  begin
426
- start_bot(bot_settings, &block)
420
+ start_bot(bot_settings, &)
427
421
  ensure
428
422
  quit!
429
423
  end
@@ -442,9 +436,9 @@ module MatrixSdk::Bot
442
436
 
443
437
  def start_bot(bot_settings, &block)
444
438
  cl = if homeserver =~ %r{^https?://}
445
- MatrixSdk::Client.new homeserver
439
+ ActiveMatrix::Client.new homeserver
446
440
  else
447
- MatrixSdk::Client.new_for_domain homeserver
441
+ ActiveMatrix::Client.new_for_domain homeserver
448
442
  end
449
443
 
450
444
  auth = bot_settings.delete :auth
@@ -476,7 +470,7 @@ module MatrixSdk::Bot
476
470
  begin
477
471
  data = bot.client.api.get_account_data(bot.client.mxid, "dev.ananace.ruby-sdk.#{bot_name}")
478
472
  bot.client.sync_token = data[:sync_token]
479
- rescue MatrixSdk::MatrixNotFoundError
473
+ rescue ActiveMatrix::MatrixNotFoundError
480
474
  # Valid
481
475
  rescue StandardError => e
482
476
  bot.logger.error "Failed to restore old sync token, #{e.class}: #{e}"
@@ -539,7 +533,7 @@ module MatrixSdk::Bot
539
533
  return true if (handler.data[:only] || []).empty?
540
534
 
541
535
  # Avoid modifying input data for a checking method
542
- @event = MatrixSdk::Response.new(client.api, event.dup)
536
+ @event = ActiveMatrix::Response.new(client.api, event.dup)
543
537
  return false if [handler.data[:only]].flatten.compact.any? do |only|
544
538
  if only.is_a? Proc
545
539
  !instance_exec(&only)
@@ -569,7 +563,7 @@ module MatrixSdk::Bot
569
563
  return true if (handler.data[:only] || []).empty?
570
564
 
571
565
  # Avoid modifying input data for a checking method
572
- @event = MatrixSdk::Response.new(client.api, event.dup)
566
+ @event = ActiveMatrix::Response.new(client.api, event.dup)
573
567
  return false if [handler.data[:only]].flatten.compact.any? do |only|
574
568
  if only.is_a? Proc
575
569
  instance_exec(&only)
@@ -640,7 +634,7 @@ module MatrixSdk::Bot
640
634
  return if in_event?
641
635
  return if settings.ignore_own? && client.mxid == event[:sender]
642
636
 
643
- event = event.data if event.is_a? MatrixSdk::MatrixEvent
637
+ event = event.data if event.is_a? ActiveMatrix::MatrixEvent
644
638
 
645
639
  logger.debug "Received event #{event}"
646
640
  return _handle_message(event) if event[:type] == 'm.room.message'
@@ -651,7 +645,7 @@ module MatrixSdk::Bot
651
645
 
652
646
  logger.info "Handling event #{event[:sender]}/#{event[:room_id]} => #{event[:type]}"
653
647
 
654
- @event = MatrixSdk::Response.new(client.api, event)
648
+ @event = ActiveMatrix::Response.new(client.api, event)
655
649
  instance_exec(&handler.proc)
656
650
  # Argument errors are likely to be a "friendly" error, so don't direct the user to the log
657
651
  rescue ArgumentError => e
@@ -703,7 +697,7 @@ module MatrixSdk::Bot
703
697
 
704
698
  logger.info "Handling command #{event[:sender]}/#{event[:room_id]}: #{settings.command_prefix}#{command}"
705
699
 
706
- @event = MatrixSdk::Response.new(client.api, event)
700
+ @event = ActiveMatrix::Response.new(client.api, event)
707
701
  arity = handler.arity
708
702
  case arity
709
703
  when 0
@@ -826,8 +820,17 @@ module MatrixSdk::Bot
826
820
  info += "\n #{handler.data[:notes].split("\n").join("\n ")}" if !command.nil? && handler.data[:notes]
827
821
  info = nil if info.empty?
828
822
 
823
+ prefix = if handler.command == 'help'
824
+ # Help command is always accessible without bot name prefix
825
+ "#{settings.command_prefix}#{handler.command}"
826
+ elsif room.dm?
827
+ "#{settings.command_prefix}#{handler.command}"
828
+ else
829
+ "#{expanded_prefix}#{handler.command}"
830
+ end
831
+
829
832
  [
830
- room.dm? ? "#{settings.command_prefix}#{handler.command}" : "#{expanded_prefix}#{handler.command}",
833
+ prefix,
831
834
  info
832
835
  ].compact
833
836
  end
@@ -840,7 +843,7 @@ module MatrixSdk::Bot
840
843
  room.send_notice("Help for #{command};\n#{commands}")
841
844
  end
842
845
  else
843
- room.send_notice("#{settings.help_preamble? ? "#{settings.help_preamble}\n\n" : ''}Usage:\n\n#{commands}")
846
+ room.send_notice("#{"#{settings.help_preamble}\n\n" if settings.help_preamble?}Usage:\n\n#{commands}")
844
847
  end
845
848
  end
846
849
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MatrixSdk::Bot
3
+ module ActiveMatrix::Bot
4
4
  PARAMS_CONFIG = {} # rubocop:disable Style/MutableConstant Intended
5
5
 
6
6
  require 'optparse'
@@ -21,14 +21,13 @@ module MatrixSdk::Bot
21
21
  PARAMS_CONFIG[:optparse_error] = e
22
22
  end
23
23
 
24
- MatrixSdk.logger.appenders.each do |log|
24
+ ActiveMatrix.logger.appenders.each do |log|
25
25
  log.layout = Logging::Layouts.pattern(
26
26
  pattern: "%d|%.1l %c : %m\n"
27
27
  )
28
28
  end
29
- MatrixSdk.debug! if ENV['MATRIX_DEBUG'] == '1'
29
+ ActiveMatrix.debug! if ENV['MATRIX_DEBUG'] == '1'
30
30
 
31
- require 'matrix_sdk/bot/base'
32
31
  class Instance < Base
33
32
  set :logging, true
34
33
  set :log_level, :info
@@ -76,4 +75,4 @@ module MatrixSdk::Bot
76
75
  end
77
76
  end
78
77
 
79
- extend MatrixSdk::Bot::Delegator # rubocop:disable Style/MixinUsage Intended
78
+ extend ActiveMatrix::Bot::Delegator # rubocop:disable Style/MixinUsage Intended