Subscribed unsubscribe Subscribe Subscribe

AnySan::Provider::Lingr

soh335/AnyEvent-WebService-Lingr · GitHub
使うのに毎回同じような内容書くのがあれだったのでAnySanにobserveとかreconnectとかまとめて実装した
soh335/AnySan-Provider-Lingr · GitHub

use strict;
use warnings;

use AnySan::Provider::Lingr;
use Config::Pit;
use Encode qw/encode_utf8/;
use Log::Minimal;
use Path::Class;
use File::Spec;

my $config = pit_get("lingr.com", require => {
    user => "user",
    password => "password",
});

my $file = file(File::Spec->tmpdir, "anysan-lingr-session");

my %params = (
    %$config,
    session_create_cb => sub {
        my $json = shift;
        my $fh = $file->openw or die $!;
        $fh->print($json->{session});
        $fh->close;
        infof "session created";
    },
);

$params{session} = $file->slurp if -e $file;

my $lingr = lingr %params;

AnySan->register_listener(
    $_ => {
        event => $_,
        cb => sub {
            my $receive = shift;
            infof encode_utf8 sprintf "%s from:%s in:%s",
                $receive->message, $receive->from_nickname, $receive->attribute->{obj}{room};
        },
    },
) for qw/message presence/;

AnySan->run;

In general, it's recommended to start with bots as they are actually a webhook with a single URL, and creating a bot is pretty simple.

Lingr Developer Resources · lingr/lingr Wiki · GitHub
ボットを書くときは使わなくても大丈夫なので特に使う機会がなさそう。