From 036bfadee395d5ec8bfa4e00b05077a90a8d232a Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 5 Feb 2019 22:16:21 +0100 Subject: [PATCH] Channels and discord tag --- Bot.pm | 13 +++++++++++++ Delling.pm | 14 +++++++++----- DiscordContext.pm | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Bot.pm b/Bot.pm index 89ec47d..9bf39f9 100644 --- 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 { diff --git a/Delling.pm b/Delling.pm index eb9c929..178e58b 100644 --- a/Delling.pm +++ b/Delling.pm @@ -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, diff --git a/DiscordContext.pm b/DiscordContext.pm index 8894565..1d7cb58 100644 --- a/DiscordContext.pm +++ b/DiscordContext.pm @@ -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){ -- 2.39.2