]> ruin.nu Git - NDIRC.git/commitdiff
Channels and discord tag
authorMichael Andreen <harv@ruin.nu>
Tue, 5 Feb 2019 21:16:21 +0000 (22:16 +0100)
committerMichael Andreen <harv@ruin.nu>
Sun, 10 Mar 2019 09:15:42 +0000 (10:15 +0100)
Bot.pm
Delling.pm
DiscordContext.pm

diff --git a/Bot.pm b/Bot.pm
index 89ec47d7c1e75ae9d7c3cb397b07e0b92b6a2026..9bf39f9ae09c612b88bdca9100558b1a4f505955 100644 (file)
--- a/Bot.pm
+++ b/Bot.pm
@@ -61,6 +61,12 @@ has discord_id => (
        isa => 'Str'
 );
 
+has discord_channels => (
+       is => 'rw',
+       isa => 'HashRef',
+       default => sub { {} }
+);
+
 # We registered for all events, this will produce some debug info.
 sub _default {
        my ($event, $args) = @_[ARG0 .. $#_];
@@ -329,6 +335,13 @@ sub discord_message_create {
 }
 
 sub discord_guild_create {
+       my $self = shift;
+       my $hash = shift;
+
+       for my $chan (@{$hash->{channels}}) {
+               say localtime(time) . "$chan->{id} - $chan->{name}";
+               $self->discord_channels->{$chan->{id}} = $chan->{name};
+       }
 }
 
 sub parseCommand {
index eb9c929ee9cc98095d6e5c2998ffd6238288323c..178e58b5f1459c1d912085b81659a7c93907ee12 100644 (file)
@@ -225,22 +225,26 @@ after discord_message_create => sub {
        my $author = $hash->{author};
        my $msg = $hash->{content};
        my $channel_id = $hash->{channel_id};
-       my $author_name = $author->{username};
+       my $author_name = $author->{username}.'#'.$author->{discriminator};
        my $author_id = $author->{id};
-       say localtime(time) . "$channel_id $author_name $author_id";
        return if $author->{'id'} eq $self->discord_id; # Ignore my own messages
 
-       my $channel = "#testarlite";
+       my $channel = "pm";
+       if (exists $self->discord_channels->{$channel_id}) {
+               $channel = "#".$self->discord_channels->{$channel_id};
+       }
+
+       say localtime(time) . " - $channel_id $channel $author_name $author_id";
 
        my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
 
-       say localtime(time) . " - $msg";
 
        return 0 unless $self->disp->has_command($command,$channel);
 
+       say localtime(time) . " - $msg";
 
        my $c = NDIRC::DiscordContext->new({
-                       discord_id => $author_id,
+                       discord_id => $author_name,
                        channel_id => $channel_id,
                        channel => $channel,
                        disp => $self->disp,
index 889456552ee8552fd165378c183624b4969f4715..1d7cb58f472b482b6e6af84dc3a89d76311bd78d 100644 (file)
@@ -138,9 +138,9 @@ sub _build_roles {
        my $query = $self->model->prepare(q{
 SELECT role FROM group_roles
 WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid)
-       WHERE hostmask = $1)
+       WHERE discord_id = $1)
                });
-       $query->execute($self->host);
+       $query->execute($self->discord_id);
 
        my @roles;
        while (my $group = $query->fetchrow_hashref){