aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2019-07-16 11:29:55 +0200
committerPatrick Spek <p.spek@tyil.nl>2019-07-16 11:29:55 +0200
commit2dd14b56e266831714af5ada30310d67d61b15a3 (patch)
treede80a608a8afe3692a754f6c97fa608b45be93d2
parent0502aa04bc2003043f60480f6e73d3f88184d89e (diff)
downloadMatrix::Bot-2dd14b56e266831714af5ada30310d67d61b15a3.tar.gz
Matrix::Bot-2dd14b56e266831714af5ada30310d67d61b15a3.tar.bz2
Pass a bot instead of a client instance to Plugin methods
-rw-r--r--CHANGELOG.md6
-rw-r--r--lib/Matrix/Bot.pm68
-rw-r--r--lib/Matrix/Bot/EventWrapper/RoomTextMessage.pm64
3 files changed, 11 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 787729c..ddbf991 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,12 @@ Versioning](http://semver.org/spec/v2.0.0.html).
- [matiaslina](https://gitlab.com/matiaslina)
+- `handle-room-text` no longer receives a `Matrix::Client` instance, but
+ instead receives a `Matrix::Bot` instance, stored in `$e.bot`. The
+ `Matrix::Client` is still available in the `Matrix::Bot` instance. This
+ change is intended to provide more power to the event handling methods of a
+ plugin.
+
## [0.1.0] - 2019-07-15
- Initial release
diff --git a/lib/Matrix/Bot.pm6 b/lib/Matrix/Bot.pm6
index 0107e6b..a1176f5 100644
--- a/lib/Matrix/Bot.pm6
+++ b/lib/Matrix/Bot.pm6
@@ -152,8 +152,8 @@ method run ()
self!distribute(-> $plugin {
my %data =
bot => self,
- event => $event,
room => $event.room-id,
+ :$event,
;
for $event.events -> $meta {
@@ -197,12 +197,12 @@ method run ()
{
self!distribute(-> $plugin {
my $wrapper = Matrix::Bot::EventWrapper::RoomTextMessage.new(
+ bot => self,
+ message => $event.content<body>,
+ room => $event.room_id,
time => DateTime.new($event.origin_server_ts / 1000),
user => $event.sender,
- room => $event.room_id,
- message => $event.content<body>,
:$event,
- :$!client,
);
my $reply = $plugin.handle-room-text($wrapper);
diff --git a/lib/Matrix/Bot/EventWrapper/RoomTextMessage.pm6 b/lib/Matrix/Bot/EventWrapper/RoomTextMessage.pm6
index b1f463c..596fe45 100644
--- a/lib/Matrix/Bot/EventWrapper/RoomTextMessage.pm6
+++ b/lib/Matrix/Bot/EventWrapper/RoomTextMessage.pm6
@@ -2,8 +2,6 @@
use v6.d;
-use Matrix::Client;
-
#| A wrapper to make handling text messages sent to a room easier for
#| end-users.
unit class Matrix::Bot::EventWrapper::RoomTextMessage;
@@ -24,7 +22,7 @@ has Str $.message is required;
has $.event is required;
#| The client object to fancy stuff with.
-has Matrix::Client $.client is required;
+has $.bot is required;
=begin pod