Skip to content
Snippets Groups Projects
Verified Commit db8534da authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Implement tombstone following in bot DSL

parent b86ac836
No related branches found
No related tags found
No related merge requests found
Pipeline #97248 failed
...@@ -651,8 +651,15 @@ module MatrixSdk::Bot ...@@ -651,8 +651,15 @@ module MatrixSdk::Bot
logger.info "Handling event #{event[:sender]}/#{event[:room_id]} => #{event[:type]}" logger.info "Handling event #{event[:sender]}/#{event[:room_id]} => #{event[:type]}"
@event = MatrixSdk::Response.new(client.api, event) clean_event = MatrixSdk::Response.new(client.api, event)
instance_exec(&handler.proc) arity = handler.arity
case arity
when 0
@event = clean_event
instance_exec(&handler.proc)
else
instance_exec(clean_event, &handler.proc)
end
# Argument errors are likely to be a "friendly" error, so don't direct the user to the log # Argument errors are likely to be a "friendly" error, so don't direct the user to the log
rescue ArgumentError => e rescue ArgumentError => e
logger.error "#{e.class} when handling #{event[:type]}: #{e}\n#{e.backtrace[0, 10].join("\n")}" logger.error "#{e.class} when handling #{event[:type]}: #{e}\n#{e.backtrace[0, 10].join("\n")}"
...@@ -752,6 +759,8 @@ module MatrixSdk::Bot ...@@ -752,6 +759,8 @@ module MatrixSdk::Bot
set :require_fullname, false set :require_fullname, false
# Sets a text to display before the usage information in the built-in help command # Sets a text to display before the usage information in the built-in help command
set :help_preamble, nil set :help_preamble, nil
# Should the bot automaticall follow tombstone events, when rooms are upgraded
set :follow_tombstones, true
## Sync token handling ## Sync token handling
# Token specified by the user # Token specified by the user
...@@ -843,5 +852,14 @@ module MatrixSdk::Bot ...@@ -843,5 +852,14 @@ module MatrixSdk::Bot
room.send_notice("#{settings.help_preamble? ? "#{settings.help_preamble}\n\n" : ''}Usage:\n\n#{commands}") room.send_notice("#{settings.help_preamble? ? "#{settings.help_preamble}\n\n" : ''}Usage:\n\n#{commands}")
end end
end end
#
# Default events
#
event('m.room.tombstone', only: -> { follow_tombstones }) do |tombstone|
logger.info "Received tombstone, following: #{tombstone.content.body}"
client.join_room tombstone.content.replacement_room
end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment