From e39257df2688137d57d88d502f7198425d5dfcd5 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Tue, 24 Mar 2020 19:03:55 -0300 Subject: Remove JSON::Tiny dependency in test/examples --- examples/bot.p6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/bot.p6 b/examples/bot.p6 index 24ab1e6..8a9d206 100755 --- a/examples/bot.p6 +++ b/examples/bot.p6 @@ -1,7 +1,7 @@ #!/usr/bin/env perl6 use v6; use lib "lib"; -use JSON::Tiny; +use JSON::Fast; use Matrix::Client; use Matrix::Client::Exception; @@ -34,7 +34,7 @@ class Bot { my $sync = { room => timeline => limit => 1 }; my $response = $!client.sync(sync-filter => $sync, since => $since); $since = $response.next-batch; - + for $response.joined-rooms -> $room { for $room.timeline .events -- cgit v1.2.3-70-g09d2 From e50b8fa9e02b19ece80ebeb576051e451d3a7812 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Tue, 24 Mar 2020 19:37:11 -0300 Subject: Rename some things to from perl6 to raku --- META6.json | 2 +- README.md | 4 +-- examples/bot.p6 | 81 --------------------------------------------- examples/bot.raku | 81 +++++++++++++++++++++++++++++++++++++++++++++ examples/doc-test.raku | 19 +++++++++++ examples/get-sync-json.raku | 12 +++++++ examples/rooms.p6 | 12 ------- examples/rooms.raku | 12 +++++++ examples/run.p6 | 21 ------------ examples/run.raku | 21 ++++++++++++ examples/send-message.p6 | 24 -------------- examples/send-message.raku | 24 ++++++++++++++ 12 files changed, 172 insertions(+), 141 deletions(-) delete mode 100755 examples/bot.p6 create mode 100755 examples/bot.raku create mode 100644 examples/doc-test.raku create mode 100644 examples/get-sync-json.raku delete mode 100644 examples/rooms.p6 create mode 100644 examples/rooms.raku delete mode 100644 examples/run.p6 create mode 100644 examples/run.raku delete mode 100644 examples/send-message.p6 create mode 100644 examples/send-message.raku (limited to 'examples') diff --git a/META6.json b/META6.json index d31ee73..bfac3e3 100644 --- a/META6.json +++ b/META6.json @@ -9,7 +9,7 @@ "URI::Encode", "IO::Socket::SSL" ], - "description" : "Matrix client for Perl 6", + "description" : "Matrix client for Raku", "license" : "Artistic-2.0", "name" : "Matrix::Client", "perl" : "6.c", diff --git a/README.md b/README.md index bdb8067..442c8ac 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Matrix::Client -A perl 6 library for [Matrix](https://matrix.org). +A [Raku](https://raku.org) library for [Matrix](https://matrix.org). ## Synopsis @@ -20,7 +20,7 @@ A perl 6 library for [Matrix](https://matrix.org). # Send a message to a random room that I'm in my $room = $client.joined-rooms.pick; say "Sending a message to {$room.name}"; - $room.send("Hello from perl6!"); + $room.send("Hello from Raku!"); ## Description diff --git a/examples/bot.p6 b/examples/bot.p6 deleted file mode 100755 index 8a9d206..0000000 --- a/examples/bot.p6 +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env perl6 -use v6; -use lib "lib"; -use JSON::Fast; -use Matrix::Client; -use Matrix::Client::Exception; - -class Bot { - has $!name = "!d"; - has $!username is required; - has Bool $!register = False; - - has $!on-event; - - has Matrix::Client $!client; - - submethod BUILD(:$username!, :$password!, :$home-server!,:$on-event!) { - $!client = Matrix::Client.new(:home-server($home-server)); - $!username = $username; - $!on-event = $on-event; - - $!client.login($!username, $password); - } - - method shutdown() { - $!client.save-auth-data; - } - - method listen() { - say "Listening"; - my $since = ""; - - loop { - my $sync = { room => timeline => limit => 1 }; - my $response = $!client.sync(sync-filter => $sync, since => $since); - $since = $response.next-batch; - - for $response.joined-rooms -> $room { - for $room.timeline - .events - .grep(*.type eq 'm.room.message') -> $msg { - if $msg.content.match($!name) { - my $bot-msg = $!on-event($msg); - if so $bot-msg { - say "Sending message $bot-msg"; - try { - CATCH { when X::Matrix::Response { .message }} - my $res = $!client.send($room.room-id, ~$bot-msg); - } - } - } - } - } - sleep(10); - } - } -} - -sub MAIN(Str:D $username, Str:D $password, :$home-server = "https://matrix.deprecated.org") { - my $bot = Bot.new: - username => $username, - password => $password, - home-server => $home-server, - on-event => -> $ev { - given $ev.content { - when /"say hi"/ { - say "Someone says {$ev.content}"; - "Hello @ {DateTime.now}" - } - default { say "Dunno what's telling me"; Str } - } - }; - - signal(SIGINT).tap({ - say "Bye"; - $bot.shutdown; - exit 0; - }); - - $bot.listen; -} diff --git a/examples/bot.raku b/examples/bot.raku new file mode 100755 index 0000000..8a9d206 --- /dev/null +++ b/examples/bot.raku @@ -0,0 +1,81 @@ +#!/usr/bin/env perl6 +use v6; +use lib "lib"; +use JSON::Fast; +use Matrix::Client; +use Matrix::Client::Exception; + +class Bot { + has $!name = "!d"; + has $!username is required; + has Bool $!register = False; + + has $!on-event; + + has Matrix::Client $!client; + + submethod BUILD(:$username!, :$password!, :$home-server!,:$on-event!) { + $!client = Matrix::Client.new(:home-server($home-server)); + $!username = $username; + $!on-event = $on-event; + + $!client.login($!username, $password); + } + + method shutdown() { + $!client.save-auth-data; + } + + method listen() { + say "Listening"; + my $since = ""; + + loop { + my $sync = { room => timeline => limit => 1 }; + my $response = $!client.sync(sync-filter => $sync, since => $since); + $since = $response.next-batch; + + for $response.joined-rooms -> $room { + for $room.timeline + .events + .grep(*.type eq 'm.room.message') -> $msg { + if $msg.content.match($!name) { + my $bot-msg = $!on-event($msg); + if so $bot-msg { + say "Sending message $bot-msg"; + try { + CATCH { when X::Matrix::Response { .message }} + my $res = $!client.send($room.room-id, ~$bot-msg); + } + } + } + } + } + sleep(10); + } + } +} + +sub MAIN(Str:D $username, Str:D $password, :$home-server = "https://matrix.deprecated.org") { + my $bot = Bot.new: + username => $username, + password => $password, + home-server => $home-server, + on-event => -> $ev { + given $ev.content { + when /"say hi"/ { + say "Someone says {$ev.content}"; + "Hello @ {DateTime.now}" + } + default { say "Dunno what's telling me"; Str } + } + }; + + signal(SIGINT).tap({ + say "Bye"; + $bot.shutdown; + exit 0; + }); + + $bot.listen; +} diff --git a/examples/doc-test.raku b/examples/doc-test.raku new file mode 100644 index 0000000..0072c94 --- /dev/null +++ b/examples/doc-test.raku @@ -0,0 +1,19 @@ +use v6; +use lib ; +use Matrix::Client; +use Data::Dump::Tree; + +my Matrix::Client $client .= new: + :home-server, + :access-token(%*ENV); + +say $client.presence(“@matias:matrix.deprecated.org”); +#`[ +for ^10 -> $i { + my $presence = $i %% 2 ?? "online" !! "offline"; + say $client.presence.presence; + say "Setting presence $presence"; + $client.set-presence($presence, :status-message); + sleep 3; +} +] diff --git a/examples/get-sync-json.raku b/examples/get-sync-json.raku new file mode 100644 index 0000000..2db9c5a --- /dev/null +++ b/examples/get-sync-json.raku @@ -0,0 +1,12 @@ +use v6; +use Matrix::Client; + +sub MAIN($file? = 'sync.json') { + my $c = Matrix::Client.new(home-server => 'https://matrix.deprecated.org'); + $c.login: 'deprecated_bot', 'deprecatedbot'; + + my $res = $c.sync; + $file.IO.spurt($res.content); + + $c.logout; +} diff --git a/examples/rooms.p6 b/examples/rooms.p6 deleted file mode 100644 index 4f0a0c7..0000000 --- a/examples/rooms.p6 +++ /dev/null @@ -1,12 +0,0 @@ -use v6; -use Matrix::Client; - - -sub MAIN($username, $pass) { - my $c = Matrix::Client.new(home-server => 'https://matrix.deprecated.org'); - $c.login: $username, $pass; - - for $c.joined-rooms -> $room { - $room.say; - } -} diff --git a/examples/rooms.raku b/examples/rooms.raku new file mode 100644 index 0000000..4f0a0c7 --- /dev/null +++ b/examples/rooms.raku @@ -0,0 +1,12 @@ +use v6; +use Matrix::Client; + + +sub MAIN($username, $pass) { + my $c = Matrix::Client.new(home-server => 'https://matrix.deprecated.org'); + $c.login: $username, $pass; + + for $c.joined-rooms -> $room { + $room.say; + } +} diff --git a/examples/run.p6 b/examples/run.p6 deleted file mode 100644 index f78df16..0000000 --- a/examples/run.p6 +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env perl6 -use v6; -use lib ; -use Matrix::Client; - -sub MAIN(Str:D $username, Str:D $password, :$home-server = "https://matrix.deprecated.org") { - my Matrix::Client $client .= new: :$home-server; - $client.login($username, $password); - - my $sup = $client.run(:sleep<5>); - - signal(SIGINT).tap({ - say "Bye"; - $client.logout; - exit 0; - }); - - react whenever $sup -> $ev { - say $ev; - } -} diff --git a/examples/run.raku b/examples/run.raku new file mode 100644 index 0000000..af1b188 --- /dev/null +++ b/examples/run.raku @@ -0,0 +1,21 @@ +#!/usr/bin/env raku +use v6; +use lib ; +use Matrix::Client; + +sub MAIN(Str:D $username, Str:D $password, :$home-server = "https://matrix.deprecated.org") { + my Matrix::Client $client .= new: :$home-server; + $client.login($username, $password); + + my $sup = $client.run(:sleep<5>); + + signal(SIGINT).tap({ + say "Bye"; + $client.logout; + exit 0; + }); + + react whenever $sup -> $ev { + say $ev; + } +} diff --git a/examples/send-message.p6 b/examples/send-message.p6 deleted file mode 100644 index 4824be5..0000000 --- a/examples/send-message.p6 +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env perl6 -use v6; -use lib 'lib'; -use Matrix::Client; - -sub MAIN(:$room-id?, :$room-alias?, *@args) { - unless $room-id.so || $room-alias.so { - fail 'Missing room-id or room-alias'; - } - my Matrix::Client $client .= new: - :home-server(%*ENV), - :access-token($*ENV); - - my $id; - if $room-id.so { - $id = $room-id; - } else { - say "Searching for $room-alias"; - $id = $client.get-room-id($room-alias); - } - - my $event = $client.send($id, @args.join(' ')); - say $event; -} diff --git a/examples/send-message.raku b/examples/send-message.raku new file mode 100644 index 0000000..2a8202a --- /dev/null +++ b/examples/send-message.raku @@ -0,0 +1,24 @@ +#!/usr/bin/env raku +use v6; +use lib 'lib'; +use Matrix::Client; + +sub MAIN(:$room-id?, :$room-alias?, *@args) { + unless $room-id.so || $room-alias.so { + fail 'Missing room-id or room-alias'; + } + my Matrix::Client $client .= new: + :home-server(%*ENV), + :access-token($*ENV); + + my $id; + if $room-id.so { + $id = $room-id; + } else { + say "Searching for $room-alias"; + $id = $client.get-room-id($room-alias); + } + + my $event = $client.send($id, @args.join(' ')); + say $event; +} -- cgit v1.2.3-70-g09d2