]> ruin.nu Git - NDIRC.git/commitdiff
Webbie messages
authorMichael Andreen <harv@ruin.nu>
Sat, 23 Feb 2019 22:04:08 +0000 (23:04 +0100)
committerMichael Andreen <harv@ruin.nu>
Thu, 21 Mar 2019 15:47:50 +0000 (16:47 +0100)
Bot.pm
Delling.pm
Dispatcher.pm

diff --git a/Bot.pm b/Bot.pm
index 0a65f8fbafc11c7f84f7774579bb36e9818f1dd2..0d517867f3dd39869ec9a4e542ca0afee753b0c6 100644 (file)
--- a/Bot.pm
+++ b/Bot.pm
@@ -26,6 +26,7 @@ use Moose;
 
 use POE::Component::IRC::Common qw/irc_to_utf8/;
 use POE::Session;
+use POE::Kernel;
 use POE::Component::IRC::Plugin::Logger;
 use POE::Component::IRC::Plugin::BotTraffic;
 use POE::Component::IRC::Plugin::Connector;
@@ -67,6 +68,12 @@ has discord_channels => (
        default => sub { {} }
 );
 
+has targets => (
+       is => 'ro',
+       isa => 'HashRef[ArrayRef[Str]]',
+       default => sub{ {} },
+);
+
 # We registered for all events, this will produce some debug info.
 sub _default {
        my ($event, $args) = @_[ARG0 .. $#_];
@@ -235,13 +242,16 @@ sub _build_disp {
                $disp->load(@commands);
        }
 
+       %{$self->targets} = ();
        my $channels = new IO::File 'channels' or die $!;;
        while (<$channels>){
                my ($chan, @types) = split /\s+/;
                say "$chan - @types";
                if ($chan =~ /^(.*):(.*)$/){
                        $chan = $1;
-                       $disp->set_target($2,$chan);
+                       $self->targets->{$2} = [] unless exists $self->targets->{$2};
+                       push @{$self->targets->{$2}},$chan;
+                       say "$2 - @{$self->targets->{$2}}";
                }
                $disp->add_channel($chan,\@types);
        }
@@ -400,4 +410,24 @@ sub parseCommand {
        return $self->disp->run_command($c,$command,$args);
 }
 
+sub toTarget {
+       my ($self, $target, $msg) = @_;
+
+       return unless exists $self->targets->{$target};
+
+       my $session = $poe_kernel->get_active_session();
+       my $heap = $session->get_heap();
+       my $irc = $heap->{irc};
+
+
+       for (@{$self->targets->{$target}}) {
+               when (/^#/) {
+                       $irc->yield(privmsg => $_, $msg);
+               }
+               when (/^d-(\d+)/i) {
+                       $self->discord->send_message($1, $msg );
+               }
+       }
+}
+
 1;
index 1eb4824d98f1d263ff27f39b6c0ce46bd0239ee3..96ff5ba9ebe4ae111ab4d93ae7a81a86ef357917 100644 (file)
@@ -103,7 +103,7 @@ WHERE u.hostmask = $1 AND channel = $2 AND flag IN ('o','v');
                $irc->yield(mode => $channel, $mode, @who) if $mode;
        }
 
-       if (lc $channel ~~ lc $disp->targets->{members}){
+       if (lc $channel ~~ lc $self->targets->{members}){
                if (time - $last_announcement < 1){
                        $last_announcement = time;
                        return;
@@ -115,14 +115,14 @@ FROM users u WHERE hostmask = ?
                }, undef, $address);
                if ($user){
                        unless ($user->{password}) {
-                               $irc->yield(privmsg => $disp->targets->{members}, "$nick: Get a new random password with /msg delling !getpass . If you don't know your username, then you can get it with .points");
+                               $irc->yield(privmsg => $self->targets->{members}, "$nick: Get a new random password with /msg delling !getpass . If you don't know your username, then you can get it with .points");
                        }
                        if ($tick > 12 && not defined $user->{pid}){
-                               $irc->yield(privmsg => $disp->targets->{members}, "$nick: go to https://nd.ruin.nu/ and enter your coords.");
+                               $irc->yield(privmsg => $self->targets->{members}, "$nick: go to https://nd.ruin.nu/ and enter your coords.");
                        }
 
                        if (not defined $user->{last_forum_visit}){
-                               $irc->yield(privmsg => $disp->targets->{members}, "$nick: Go read the forum! https://nd.ruin.nu/forum");
+                               $irc->yield(privmsg => $self->targets->{members}, "$nick: Go read the forum! https://nd.ruin.nu/forum");
                        }else {
                                my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
                                if ($unread && $unread->{new}){
@@ -170,21 +170,21 @@ sub refresh {
        my @row = $dbh->selectrow_array(q{SELECT tick(), max(tick) FROM planet_stats});
        if ($tick != $row[0]){
                $tick = $row[0];
-               $irc->yield(privmsg => $disp->targets->{def}, "New tick: $tick");
+               $self->toTarget(def => "New tick: $tick");
        }
        if (defined $row[1] && $stattick != $row[1]){
                $stattick = $row[1];
-               $irc->yield(privmsg => $disp->targets->{members}, "New tick: $stattick");
+               $self->toTarget(members => "New tick: $stattick");
        }
        my $ircreqs = $dbh->prepare(q{SELECT id,username,message,channel FROM irc_requests NATURAL JOIN users WHERE not sent});
        my $upircreq = $dbh->prepare(q{UPDATE irc_requests SET sent = TRUE WHERE id = ?});
        $ircreqs->execute;
        while (my $req = $ircreqs->fetchrow_hashref){
                if ($req->{channel} eq 'def'){
-                       $irc->yield(privmsg => $disp->targets->{def}, chr(3)."04 ## $req->{username} via webbie ## >> $req->{message}");
-                       $self->parseCommand("~report_incs $req->{message}",$irc,$req->{username},' BATCH ',$disp->targets->{def},$dbh);
-               }elsif(exists $disp->targets->{$req->{channel}}){
-                       $irc->yield(privmsg => $disp->targets->{$req->{channel}}, "<$req->{username} via webbie> $req->{message}");
+                       $self->toTarget(def => chr(3)."04 ## $req->{username} via webbie ## >> $req->{message}");
+                       #$self->parseCommand("~report_incs $req->{message}",$irc,$req->{username},' BATCH ',$disp->targets->{def},$dbh);
+               }else{
+                       $self->toTarget($req->{channel} => "<$req->{username} via webbie> $req->{message}");
                }
                $upircreq->execute($req->{id});
        }
@@ -204,7 +204,7 @@ GROUP BY username,call,tick,dm.fleet,p.value
        my $updefmis = $dbh->prepare(q{UPDATE defense_missions SET announced = TRUE WHERE fleet = ?});
        $defmissions->execute();
        while (my $mission = $defmissions->fetchrow_hashref){
-               $irc->yield(privmsg => $disp->targets->{def}, chr(3)."06 $mission->{username} sent def to call $mission->{call}, $mission->{value}% of value (tick $mission->{tick}) https://nd.ruin.nu/calls/edit/$mission->{call}");
+               $self->toTarget(def => chr(3)."06 $mission->{username} sent def to call $mission->{call}, $mission->{value}% of value (tick $mission->{tick}) https://nd.ruin.nu/calls/edit/$mission->{call}");
                $updefmis->execute($mission->{fleet});
        }
 
index 6705349b8081b4da430edc43ee3e48d12adf0217..76beef574c6687127d2fe3cb1bcc05501d4c40dd 100644 (file)
@@ -46,11 +46,6 @@ has channels => (
        default => sub{ {} },
 );
 
-has targets => (
-       is => 'ro',
-       isa => 'HashRef[Str]',
-       default => sub{ {} },
-);
 
 my $DISP;
 
@@ -107,11 +102,6 @@ sub has_command {
        return $self->channels->{$channel}->has($command->type);
 }
 
-sub set_target {
-       my ($self,$label,$target) = @_;
-       $self->targets->{$label} = $target;
-}
-
 sub run_command {
        my ($self,$c,$command,$args) = @_;