From ca16ec27b8d56988edfb1536fb1a09d8efed7602 Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@cervoi.se> Date: Sun, 28 Nov 2021 16:13:37 +0100 Subject: [PATCH] Use the PlayBot API to parse site --- PlayBot/sessions/irc.pm | 1 + PlayBot/sites.pm | 25 ++++++++++++++++++++++++- README.md | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/PlayBot/sessions/irc.pm b/PlayBot/sessions/irc.pm index f78870b..2a9c21a 100644 --- a/PlayBot/sessions/irc.pm +++ b/PlayBot/sessions/irc.pm @@ -120,6 +120,7 @@ sub setConf $PlayBot::sites::irc = $irc; $PlayBot::sites::log = $log; + $PlayBot::sites::playbot_api_key = $conf->{'playbot_api_key'}; $PlayBot::sites::soundcloud::clientSecret = $conf->{'soundcloud_secret'}; } diff --git a/PlayBot/sites.pm b/PlayBot/sites.pm index 4e36d00..8ee207d 100644 --- a/PlayBot/sites.pm +++ b/PlayBot/sites.pm @@ -4,6 +4,8 @@ use strict; use warnings; use utf8; +use LWP::UserAgent; +use JSON; use Module::Pluggable sub_name => 'sites', search_path => ['PlayBot::sites'], require => 1; use Storable qw(dclone); @@ -15,12 +17,33 @@ use PlayBot::commands::parser; our $irc; our $log; our $regex; +our $playbot_api_key; sub parse { my ($kernel, $user, $chan, $msg, $playlist) = @_; my ($nick,$mask) = split(/!/,$user); + my $ua = LWP::UserAgent->new( + timeout => 2, + env_proxy => 0, + ); + my $response = $ua->post( + "http://cloud.cervoi.se:12345/rpc", + "X-PLAYBOT-KEY" => $playbot_api_key, + Content => encode_json {"channel" => $chan, "user" => $nick, "value" => $msg}, + ); + if ($response->is_success) + { + $log->info("Handled by scala"); + $irc->yield(privmsg => $chan => $response->decoded_content); + return; + } + else + { + $log->info($response->code. " still perl job"); + } + my $chan_conf = PlayBot::utils::db::chan->new($chan); my %content; @@ -106,7 +129,7 @@ sub insert_content ); }; if ($@) { - # seems to be already present in database + # seems to be already present in database $new = 0; my $sth = $dbh->prepare(' diff --git a/README.md b/README.md index ff7c183..09d5d0d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # PlayBot +## DEPRECATED + +Tous les commits après le tag v1.0.0 visent à migrer progressivement les features du PlayBot en Perl vers une réécriture en Scala. + ## Description -- GitLab