]> ruin.nu Git - NDIRC.git/commitdiff
Add dm replies for commands on discord
authorMichael Andreen <harv@ruin.nu>
Sun, 21 Jun 2020 15:04:45 +0000 (17:04 +0200)
committerMichael Andreen <harv@ruin.nu>
Sun, 21 Jun 2020 15:04:45 +0000 (17:04 +0200)
Bot.pm
Delling.pm
DiscordContext.pm

diff --git a/Bot.pm b/Bot.pm
index 078563d8bdfa3e85e0f78da7c48d5cbd30b35799..1c54701f3251829af9c333e29a12b81d001ed031 100644 (file)
--- 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";
index fea261ed48246afc4200fede1883a350f1246534..bed84f4bf3843cf3c3e2a2450aeab82603aee99a 100644 (file)
@@ -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(),
index c6e4959a2343c2e700661dc33c8f5096da0f142e..f8a0a089ea6a5427f4d53834b17725840538bf43 100644 (file)
@@ -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`<b>(.*?)</b>`**$1**`gi;
+               $msg =~ s`<c(\d+)>(.*?)</c>`*$2*`gi;
+               $self->discord->send_dm($self->author_id, $msg);
+       }
+       else
+       {
+               $self->message($self->channel_id, $msg);
+       }
 }
 
 sub message {