Jelajahi Sumber

A bit more work, still very much WIP

Andy Baugh 5 tahun lalu
induk
melakukan
6e656e78c7

+ 4 - 1
Makefile

@@ -43,7 +43,10 @@ depend-irc:
 depend-xmpp:
 	perl -MNet::XMPP -MMozilla::CA -e 'exit 0;' || sudo cpan -i Net::XMPP Mozilla::CA
 
-depend-all: depend-xmpp depend-irc
+depend-telegram:
+	perl -MWWW::Telegram::BotAPI -e 'exit 0;' || sudo cpan -i WWW::Telegram::BotAPI
+
+depend-all: depend-xmpp depend-irc depend-telegram
 
 depend-test:
 	perl -MTest::More -MTest::Fatal -MTest::MockModule -MTest::Deep -MConfig::Simple -MHTTP::Tiny::UA -MHTTP::Tiny::UA::Response -e 'exit 0;' || sudo cpan -i Test::More Test::Fatal Test::MockModule Test::Deep Config::Simple HTTP::Tiny::UA HTTP::Tiny::UA::Response

+ 19 - 5
lib/Cpanel/iContact/Provider/Schema/Telegram.pm

@@ -62,8 +62,8 @@ Telegram Bot Token: Token created for sending notifications to the bot you confi
 HALP
     return {
         'CONTACTTELEGRAM' => {
-            'name'     => 'Telegram',
-            'shadow'   => 1,
+            'name'     => 'Telegram Destinations',
+            'shadow'   => 0,
             'type'     => 'text',
             'checkval' => sub {
                 my $value = shift();
@@ -71,14 +71,28 @@ HALP
 
                 return $value if $value eq q{};
 
+                return $value;
+            },
+            'label' => 'Telegram Destinations',
+            'help'  => "The group(s)/user(s) you wish your Telegram bot to notify, separated by comma.",
+        },
+        'TELEGRAMBOTTOKEN' => {
+            'name'     => 'Telegram Bot Token',
+            'label'    => 'Telegram Bot Token',
+            'help'     => $help,
+            'shadow'   => 1,
+            'checkval' => sub {
+                my $value = shift();
+                $value =~ s/^\s+|\s+$//g; # Trim
+
+                return $value if $value eq q{};
+
                 if($value !~ m/^[0-9]+:[A-Z]{3}-[A-Z]{3}[A-Za-z0-9]+-[A-Za-z0-9]+$/ ) {
                     die "Bogus value, neener neener";
                 }
                 return $value;
             },
-            'label' => 'Telegram Bot Token',
-            'help'  => $help,
-        }
+        },
     };
 }
 

+ 7 - 7
lib/Cpanel/iContact/Provider/Telegram.pm

@@ -1,4 +1,4 @@
-package Cpanel::iContact::Provider::Discord;
+package Cpanel::iContact::Provider::Telegram;
 
 use strict;
 use warnings;
@@ -11,25 +11,25 @@ use Try::Tiny;
 
 =head1 NAME
 
-Cpanel::iContact::Provider::Discord - Backend for the Discord iContact module
+Cpanel::iContact::Provider::Telegram - Backend for the Telegram iContact module
 
 =head1 SYNOPSIS
 
-    use Cpanel::iContact::Provider::Discord;
+    use Cpanel::iContact::Provider::Telegram;
 
-    my $notifier = Cpanel::iContact::Provider::Discord->new();
+    my $notifier = Cpanel::iContact::Provider::Telegram->new();
     $notifier->send();
 
 
 =head1 DESCRIPTION
 
-Provide backend accessor for the Discord iContact module.
+Provide backend accessor for the Telegram iContact module.
 
 =cut
 
 =head2 send
 
-Sends off the notification over to your Discord channel/user
+Sends off the notification over to your Telegram channel/user
 
 =over 2
 
@@ -69,7 +69,7 @@ sub send {
 
     require Cpanel::AdminBin::Serializer;
 
-    # GitHub issue #18 -- Discord max message length is 2000 chars.
+    # GitHub issue #18 -- Telegram max message length is 2000 chars.
     # As such , truncate at 1996, add ellipsis (3 chars).
     # Why not 1997? I want to avoid fencepost errors.
     my $message_json = Cpanel::AdminBin::Serializer::Dump(

+ 3 - 2
t/Cpanel-iContact-Provider-Schema-Telegram.t

@@ -13,7 +13,7 @@ use Cpanel::iContact::Provider::Schema::Telegram ();
 plan tests => 2;
 
 subtest "Settings getter method performs as expected" => sub {
-    my $model = [ 'CONTACTTELEGRAM' ];
+    my $model = [ 'CONTACTTELEGRAM', 'TELEGRAMBOTTOKEN' ];
     my $settings = Cpanel::iContact::Provider::Schema::Telegram::get_settings();
     is_deeply( [ sort keys( %{$settings} ) ], $model, "Settings returned look OK so far" );
     foreach my $key (@$model) {
@@ -22,7 +22,8 @@ subtest "Settings getter method performs as expected" => sub {
             '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11', "Valid values passed to checkval subroutine of '$key' assumed GreatSuccess"
         ) if ref $settings->{$key}{'checkval'} eq 'CODE';
     }
-    is( $settings->{'CONTACTTELEGRAM'}{'checkval'}->('    '), '', "Invalid values passed to checkval subroutine of 'CONTACTTELEGRAM' engaged Maximum NO" );
+    is( $settings->{'CONTACTTELEGRAM'}{'checkval'}->('    '), '', "Invalid values passed to checkval subroutine of 'CONTACTTELEGRAM' silently got smashed" );
+    is( eval { $settings->{'TELEGRAMBOTTOKEN'}{'checkval'}->(' NeenerNeenerNotAToken') }, undef, "Invalid values passed to checkval subroutine of 'CONTACTTELEGRAM' engaged Maximum NO" );
 };
 
 my $config_model = { 'default_level' => 'All', 'display_name' => 'Telegram', 'icon' => ignore() };

+ 1 - 1
t/Cpanel-iContact-Provider-Telegram.t

@@ -34,7 +34,7 @@ subtest "Provider bits work as expected ('unit' test)" => sub {
 
 subtest "Can send a message to somewhere (systems level/integration test)" => sub {
     SKIP: {
-        my $conf_file = abs_path( dirname(__FILE__) . "/../.discordtestrc" );
+        my $conf_file = abs_path( dirname(__FILE__) . "/../.telegramtestrc" );
         skip "Skipping functional testing, needful not supplied", 1 if !$ENV{'AUTHOR_TESTS'} || !-f $conf_file;
         my $test_conf = { Config::Simple->import_from($conf_file)->vars() };
         my $text_body = "This is a test of Cpanel::iContact::Provider::Telegram. Please Ignore";