]> ruin.nu Git - NDIRC.git/commitdiff
Universal scan parsing discord
authorMichael Andreen <harv@ruin.nu>
Thu, 21 Mar 2019 22:07:47 +0000 (23:07 +0100)
committerMichael Andreen <harv@ruin.nu>
Thu, 21 Mar 2019 22:07:47 +0000 (23:07 +0100)
Bot.pm
Commands/Scans.pm
Delling.pm
Dispatcher.pm

diff --git a/Bot.pm b/Bot.pm
index cbc0c5cd90332910e76871d705cd398bbe36cb4c..363531217864018f1faf26ab54ec00a37cbeae9d 100644 (file)
--- a/Bot.pm
+++ b/Bot.pm
@@ -370,6 +370,26 @@ sub discord_channel_create {
        $self->discord_channels->{$chan->{id}} = $chan;
 }
 
+sub handleCommand {
+       my ($self, $c, $msg) = @_;
+
+       my ($p,$command,$args) = ($msg =~ /^([.])(\S+)(?: (.+))?/);
+
+       if ($msg =~ m{https?://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
+               if (!$command || $command =~ m{^https?://}){
+                       ($p,$command,$args) = ('.','addscan',$msg);
+               }elsif($command ne 'addscan'){
+                       $self->handleCommand ($c, ".addscan $msg")
+               }
+       }
+
+       return 0 unless $self->disp->has_command($command,$c->channel);
+
+       say localtime(time) . " - $msg";
+
+       return $self->disp->run_command($c,$command,$args);
+}
+
 sub parseCommand {
        my ($self, $msg, $server, $nick, $address, $channel, $model) = @_;
 
index 319e38cfef6eded49488b59bd855bff36f3414f9..193e486c46b80b6c094988876338415e689040be 100644 (file)
@@ -201,6 +201,7 @@ SELECT ship,amount FROM fleet_ships WHERE fid = $1 ORDER BY num
 
 command addscan => {
        help => q(syntax: .addscan list of scans),
+       type => q(universal),
 }, class extends NDIRC::Command {
        method execute($c,$msg) {
                my $dbh = $c->model;
@@ -213,7 +214,7 @@ WHERE groupscan = $1 AND scan_id = LOWER($2) AND tick >= tick() - 168
 INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER($1),tick(),$2,COALESCE($3,-1))
                        });
                my $user = $dbh->selectrow_hashref(q{SELECT uid,username, scan_points, tick()
-                       FROM users WHERE uid = ? },undef,$c->uid);
+                       FROM users WHERE uid = ? AND uid > 0 },undef,$c->uid);
                my $groupscans = 0;
                my $scans = 0;
                eval {
index fe35fe131562ee1fecbb8d3f25b3cc82ad0a5ce2..e04619015f4fdb8e8a5fafc39dfb79c75a5f7580 100644 (file)
@@ -237,13 +237,6 @@ after discord_message_create => sub {
 
        say localtime(time) . " - $channel_id $channel $author_name $author_id";
 
-       my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
-
-
-       return 0 unless $self->disp->has_command($command,$channel);
-
-       say localtime(time) . " - $msg";
-
        my $c = NDIRC::DiscordContext->new({
                        discord_id => $author_name,
                        channel_id => $channel_id,
@@ -254,7 +247,7 @@ after discord_message_create => sub {
                        discord => $self->discord,
                });
 
-       return $self->disp->run_command($c,$command,$args);
+       return $self->handleCommand($c,$msg);
 
 };
 
index 76beef574c6687127d2fe3cb1bcc05501d4c40dd..a11ae53cda91800f387dcd4fae40c874a2a9b045 100644 (file)
@@ -87,6 +87,7 @@ sub add_channel {
        my ($self,$channel,$types) = @_;
 
        $types = Set::Object->new(@{$types});
+       $types->insert('universal');
        $self->channels->{lc $channel} = $types;
 }
 
@@ -96,9 +97,10 @@ sub has_command {
 
        return 0 unless defined $command && defined $channel;
        return 0 unless exists $self->commands->{$command};
+       $command = $self->commands->{$command};
+       return 1 if $command->type eq 'universal';
        return 0 unless exists $self->channels->{$channel};
 
-       $command = $self->commands->{$command};
        return $self->channels->{$channel}->has($command->type);
 }