X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Bot.pm;h=3cb565ff7638dcd4e9159003607229332327a4b3;hb=faaa3329a3df738727b7ff63831c195a3c81ad09;hp=e20412974d739aed53fcab70262188d564a3bc3f;hpb=c9251f1bab067759546d60d35782731360ad70df;p=NDIRC.git diff --git a/Bot.pm b/Bot.pm index e204129..3cb565f 100644 --- 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,17 @@ 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('MESSAGE_UPDATE' => 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; @@ -239,16 +240,16 @@ sub sig_usr2 { sub _build_disp { my ($self) = @_; - my $disp = new NDIRC::Dispatcher; + my $disp = NDIRC::Dispatcher->new; - if (my $commands = new IO::File 'commands'){ + if (my $commands = IO::File->new('commands')){ my @commands = split /\W+/, do{local $/; <$commands>}; say "Loading commands from: @commands"; $disp->load(@commands); } %{$self->targets} = (); - my $channels = new IO::File 'channels' or die $!;; + my $channels = IO::File->new('channels') or die $!;; while (<$channels>){ my ($chan, @types) = split /\s+/; say "$chan - @types"; @@ -339,8 +340,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 +352,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 +361,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 +372,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?://}){ @@ -387,6 +386,8 @@ sub handleCommand { say localtime(time) . " - $msg"; + $c->dm_reply(1) if $p eq '!'; + return $self->disp->run_command($c,$command,$args); }