]> ruin.nu Git - NDIRC.git/blobdiff - Bot.pm
Add dm replies for commands on discord
[NDIRC.git] / Bot.pm
diff --git a/Bot.pm b/Bot.pm
index 363531217864018f1faf26ab54ec00a37cbeae9d..1c54701f3251829af9c333e29a12b81d001ed031 100644 (file)
--- a/Bot.pm
+++ b/Bot.pm
@@ -121,13 +121,12 @@ sub _start {
        ));
 
        $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(
-               servers => [['irc.netgamers.org'], ['underworld.no.eu.netgamers.org']
-                       ,['firefly.no.eu.netgamers.org'], ['underworld.ca.us.netgamers.org'] ]
+               servers => [['chronos.fr.eu.netgamers.org'], ['underworld.no.eu.netgamers.org']]
        );
        $irc->plugin_add( 'Connector' => $heap->{connector} );
 
        $irc->yield( register => 'all' );
-       $irc->yield( connect => { server => 'irc.netgamers.org' } );
+       #$irc->yield( connect => { server => 'chronos.fr.eu.netgamers.org' } );
 
        $kernel->delay( refresh => 60 );
 
@@ -142,15 +141,16 @@ sub _start {
                                'name'      => $user,
                                'url'       => 'https://nd.ruin.nu',
                                'version'   => '1.0',
-                               'callbacks' => {
-                                       'READY'          => sub { $self->discord_ready(@_) },
-                                       'MESSAGE_CREATE' => sub { $self->discord_message_create(@_) },
-                                       'GUILD_CREATE' => sub { $self->discord_guild_create(@_) },
-                                       'CHANNEL_CREATE' => sub { $self->discord_channel_create(@_) },
-                               },
                                'reconnect' => 1,
                                'verbose'   => 1,
+                               'logdir'   => '/tmp',
                        ));
+
+               $self->discord->gw->on('MESSAGE_CREATE' => sub { $self->discord_message_create(@_) });
+               $self->discord->gw->on('READY'          => sub { $self->discord_ready(@_) });
+               $self->discord->gw->on('GUILD_CREATE'   => sub { $self->discord_guild_create(@_) });
+               $self->discord->gw->on('CHANNEL_CREATE' => sub { $self->discord_channel_create(@_) });
+
                $self->discord->init();
        }
        return;
@@ -255,7 +255,7 @@ sub _build_disp {
                if ($chan =~ /^(.*):(.*)$/){
                        $chan = $1;
                        $self->targets->{$2} = [] unless exists $self->targets->{$2};
-                       push @{$self->targets->{$2}},$chan;
+                       push @{$self->targets->{$2}},lc $chan;
                        say "$2 - @{$self->targets->{$2}}";
                }
                $disp->add_channel($chan,\@types);
@@ -339,8 +339,8 @@ sub irc_join {
 }
 
 sub discord_ready {
-       my $self = shift;
-       my $hash = shift;
+       my ($self, $gw, $hash) = @_;
+
        $self->discord_id($hash->{user}{id});
        $self->discord_name($hash->{user}{username});
 
@@ -351,8 +351,7 @@ sub discord_message_create {
 }
 
 sub discord_guild_create {
-       my $self = shift;
-       my $hash = shift;
+       my ($self, $gw, $hash) = @_;
 
        for my $chan (@{$hash->{channels}}) {
                say localtime(time) . " - $chan->{id} - $chan->{name}";
@@ -361,8 +360,7 @@ sub discord_guild_create {
 }
 
 sub discord_channel_create {
-       my $self = shift;
-       my $chan = shift;
+       my ($self, $gw, $chan) = @_;
 
        for my $key (keys %{$chan}) {
                say localtime(time) . " - $key - $chan->{$key}";
@@ -373,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?://}){
@@ -383,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";
@@ -449,7 +449,7 @@ sub message {
        my ($self, $msg, @targets) = @_;
 
        for (@targets) {
-               when (/^D-(\d+)$/) {
+               when (/^D-(\d+)$/i) {
                        $self->discordMessage($1, $msg);
                }
                default {