我正在創建一個連接到Matrix服務器的bot。爲此,我使用Net::Async::Matrix。Perl:發佈祝福對象
代碼:
#!/usr/bin/perl
use strict;
use warnings;
use Net::Async::Matrix;
use Net::Async::Matrix::Utils qw (parse_formatted_message);
use IO::Async::Loop;
use Data::Dumper;
my $loop = IO::Async::Loop->new;
my $matrix = Net::Async::Matrix->new(
server => 'matrix.server.net',
on_error => sub {
my (undef, $message) = @_;
warn "error: $message\n";
},
);
$loop->add($matrix);
$matrix->login(
user_id => '@bot:matrix.server.net',
password => 'password',
)->get;
my $room = $matrix->join_room('#Lobby:matrix.server.net')->get;
$room->configure(
on_message => sub {
my (undef, $member, $content, $event) = @_;
my $msg = parse_formatted_message($content);
my $sendername = $member->displayname;
print Dumper $sendername;
&sendmsg("$sendername said: $msg");
},
);
my $stream = $matrix->start;
sub sendmsg {
my $input = shift;
if ($input) {
$room->send_message(
type => "m.text",
body => $input,
),
}
}
$loop->run;
基本上,我想機器人呼應說了些什麼。
我獲得以下的輸出:
$ VAR1 = 'm1ndgames'; Longpoll失敗 - 遇到對象'm1ndgames 說:test',但既不allow_blessed,convert_blessed也不允許 允許allow_tags設置(或TO_JSON/FREEZE方法丟失) /usr/local/share/perl/5.24.1/Net/Async /Matrix.pm line 292.
我不明白這一點。當我在身體中輸入像test
這樣的字符串時,它會被髮送到房間。
謝謝!這是原因! – m1ndgames