From c9c9e83da024d15fc1245bf456c197c119f23cf4 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 21 Mar 2019 23:07:47 +0100 Subject: [PATCH] Universal scan parsing --- Bot.pm | 20 ++++++++++++++++++++ Commands/Scans.pm | 3 ++- Delling.pm | 9 +-------- Dispatcher.pm | 4 +++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Bot.pm b/Bot.pm index cbc0c5c..3635312 100644 --- 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) = @_; diff --git a/Commands/Scans.pm b/Commands/Scans.pm index 319e38c..193e486 100644 --- a/Commands/Scans.pm +++ b/Commands/Scans.pm @@ -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 { diff --git a/Delling.pm b/Delling.pm index fe35fe1..e046190 100644 --- a/Delling.pm +++ b/Delling.pm @@ -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); }; diff --git a/Dispatcher.pm b/Dispatcher.pm index 76beef5..a11ae53 100644 --- a/Dispatcher.pm +++ b/Dispatcher.pm @@ -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); } -- 2.39.2