aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--META6.json1
-rw-r--r--lib/Matrix/Bot.pm619
-rw-r--r--lib/Matrix/Bot/EventWrapper/RoomTopicChange.pm637
-rw-r--r--lib/Matrix/Bot/Plugin.pm63
5 files changed, 65 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 64bb17f..a51d438 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ Versioning](http://semver.org/spec/v2.0.0.html).
## [UNRELEASED]
+### Added
+
+- The `Matrix::Bot::Plugin` base class has been given a `handle-room-topic`
+ method. This method receives topic change events.
+
### Removed
- `Matrix::Bot` no longer tries to log all messages it has received. This is
diff --git a/META6.json b/META6.json
index 6b359a1..97493ca 100644
--- a/META6.json
+++ b/META6.json
@@ -18,6 +18,7 @@
"Matrix::Bot::EventWrapper::InitialSync": "lib/Matrix/Bot/EventWrapper/InitialSync.pm6",
"Matrix::Bot::EventWrapper::RoomInvite": "lib/Matrix/Bot/EventWrapper/RoomInvite.pm6",
"Matrix::Bot::EventWrapper::RoomTextMessage": "lib/Matrix/Bot/EventWrapper/RoomTextMessage.pm6",
+ "Matrix::Bot::EventWrapper::RoomTopicChange": "lib/Matrix/Bot/EventWrapper/RoomTopicChange.pm6",
"Matrix::Bot::Plugin": "lib/Matrix/Bot/Plugin.pm6",
"Matrix::Bot::Subsets": "lib/Matrix/Bot/Subsets.pm6"
},
diff --git a/lib/Matrix/Bot.pm6 b/lib/Matrix/Bot.pm6
index 7dccb32..45a44e6 100644
--- a/lib/Matrix/Bot.pm6
+++ b/lib/Matrix/Bot.pm6
@@ -9,6 +9,7 @@ use Text::Markdown;
use Matrix::Bot::EventWrapper::InitialSync;
use Matrix::Bot::EventWrapper::RoomInvite;
use Matrix::Bot::EventWrapper::RoomTextMessage;
+use Matrix::Bot::EventWrapper::RoomTopicChange;
use Matrix::Bot::Plugin;
#| A small framework to build Matrix bots upon.
@@ -198,6 +199,24 @@ method run ()
}
})
}
+
+ whenever $event-handler
+ .Supply
+ .grep(* ~~ Matrix::Response::StateEvent)
+ .grep(*.type eq "m.room.topic")
+ -> $event
+ {
+ self!distribute("handle-room-topic", sub ($plugin) {
+ my $wrapper = Matrix::Bot::EventWrapper::RoomTopicChange.new(
+ bot => self,
+ room => $event.room_id,
+ topic => $event.content<topic>,
+ :$event,
+ );
+
+ $plugin.handle-room-topic($wrapper);
+ })
+ }
}
}
diff --git a/lib/Matrix/Bot/EventWrapper/RoomTopicChange.pm6 b/lib/Matrix/Bot/EventWrapper/RoomTopicChange.pm6
new file mode 100644
index 0000000..314b8fe
--- /dev/null
+++ b/lib/Matrix/Bot/EventWrapper/RoomTopicChange.pm6
@@ -0,0 +1,37 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+use Matrix::Bot::Subsets;
+
+unit class Matrix::Bot::EventWrapper::RoomTopicChange;
+
+#| The room ID that had its topic changed.
+has Matrix::RoomID $.room is required;
+
+#| The new topic of the room.
+has Str $.topic is required;
+
+#| The full event details.
+has $.event is required;
+
+#| The core Matrix::Bot object.
+has $.bot is required;
+
+=begin pod
+
+=NAME Matrix::Bot::EventWrapper::RoomTopicChange
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+=VERSION 0.2.0
+
+=head1 Synopsis
+
+=head1 Description
+
+=head1 Examples
+
+=head1 See also
+
+=end pod
+
+# vim: ft=perl6 noet
diff --git a/lib/Matrix/Bot/Plugin.pm6 b/lib/Matrix/Bot/Plugin.pm6
index ccf2ceb..de30c3a 100644
--- a/lib/Matrix/Bot/Plugin.pm6
+++ b/lib/Matrix/Bot/Plugin.pm6
@@ -16,6 +16,9 @@ multi method handle-event ($) { }
#| non-empty Str, this will be sent to back to the room.
multi method handle-room-text ($ --> Str) { Str }
+#| Receives only topic changes.
+multi method handle-room-topic ($) { }
+
#| Receives only invites to rooms. If the method returns True, the room will be
#| joined.
multi method handle-invite ($ --> Bool) { Bool }