From: Michael Andreen Date: Sun, 21 Jun 2020 15:04:45 +0000 (+0200) Subject: Add dm replies for commands on discord X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=commitdiff_plain;h=3b7dbc35e153a4a3922f98daf365fe76245e35e4 Add dm replies for commands on discord --- diff --git a/Bot.pm b/Bot.pm index 078563d..1c54701 100644 --- a/Bot.pm +++ b/Bot.pm @@ -371,7 +371,7 @@ sub discord_channel_create { sub handleCommand { my ($self, $c, $msg) = @_; - my ($p,$command,$args) = ($msg =~ /^([.])(\S+)(?: (.+))?/); + my ($p,$command,$args) = ($msg =~ /^([.!])(\S+)(?: (.+))?/); if ($msg =~ m{https?://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){ if (!$command || $command =~ m{^https?://}){ @@ -381,6 +381,8 @@ sub handleCommand { } } + $c->dm_reply(1) if $p eq '!'; + return 0 unless $self->disp->has_command($command,$c->channel); say localtime(time) . " - $msg"; diff --git a/Delling.pm b/Delling.pm index fea261e..bed84f4 100644 --- a/Delling.pm +++ b/Delling.pm @@ -239,6 +239,7 @@ after discord_message_create => sub { my $c = NDIRC::DiscordContext->new({ discord_id => $author_name, channel_id => $channel_id, + author_id => $author_id, channel => $channel, disp => $self->disp, model => DB(), diff --git a/DiscordContext.pm b/DiscordContext.pm index c6e4959..f8a0a08 100644 --- a/DiscordContext.pm +++ b/DiscordContext.pm @@ -38,17 +38,39 @@ has channel_id => ( required => 1 ); +has author_id => ( + is => 'ro', + isa => 'Str', + required => 1 +); + has discord => ( is => 'ro', isa => 'Object', required => 1 ); +has dm_reply => ( + is => 'rw', + isa => 'Bool', + required => 0, + default => 0 +); + sub reply { my ($self,$msg) = @_; - $self->message($self->channel_id, $msg); + if ($self->dm_reply) + { + $msg =~ s`(.*?)`**$1**`gi; + $msg =~ s`(.*?)`*$2*`gi; + $self->discord->send_dm($self->author_id, $msg); + } + else + { + $self->message($self->channel_id, $msg); + } } sub message {