use POE::Component::IRC::Common qw/irc_to_utf8/;
use POE::Session;
+use POE::Kernel;
use POE::Component::IRC::Plugin::Logger;
use POE::Component::IRC::Plugin::BotTraffic;
use POE::Component::IRC::Plugin::Connector;
use POE::Component::IRC::Plugin::AutoJoin;
use POE::Component::IRC::Plugin::NickReclaim;
+use Mojo::Discord;
+use Mojo::IOLoop;
+
use NDIRC::Dispatcher;
-use NDIRC::Context;
+use NDIRC::IrcContext;
use IO::File;
lazy_build => 1
);
+has discord => (
+ is => 'rw',
+ isa => 'Object'
+);
+
+has discord_name => (
+ is => 'rw',
+ isa => 'Str'
+);
+
+has discord_id => (
+ is => 'rw',
+ isa => 'Str'
+);
+
+has discord_channels => (
+ is => 'rw',
+ isa => 'HashRef',
+ default => sub { {} }
+);
+
+has targets => (
+ is => 'ro',
+ isa => 'HashRef[ArrayRef[Str]]',
+ default => sub{ {} },
+);
+
# We registered for all events, this will produce some debug info.
sub _default {
my ($event, $args) = @_[ARG0 .. $#_];
}
sub _start {
- my ($kernel,$heap,$session) = @_[KERNEL,HEAP,SESSION];
+ my ($self,$kernel,$heap,$session) = @_[OBJECT,KERNEL,HEAP,SESSION];
# retrieve our component's object from the heap where we stashed it
my $irc = $heap->{irc};
$irc->yield( connect => { server => 'irc.netgamers.org' } );
$kernel->delay( refresh => 60 );
+
+ if (my $f = new IO::File 'discord'){
+ my $user = <$f>;
+ chomp $user;
+ my $token = <$f>;
+ chomp $token;
+
+ $self->discord(Mojo::Discord->new(
+ 'token' => $token,
+ '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,
+ ));
+ $self->discord->init();
+ }
return;
}
$disp->load(@commands);
}
+ %{$self->targets} = ();
my $channels = new IO::File 'channels' or die $!;;
while (<$channels>){
my ($chan, @types) = split /\s+/;
say "$chan - @types";
if ($chan =~ /^(.*):(.*)$/){
$chan = $1;
- $disp->set_target($2,$chan);
+ $self->targets->{$2} = [] unless exists $self->targets->{$2};
+ push @{$self->targets->{$2}},$chan;
+ say "$2 - @{$self->targets->{$2}}";
}
$disp->add_channel($chan,\@types);
}
sub irc_join {
}
+sub discord_ready {
+ my $self = shift;
+ my $hash = shift;
+ $self->discord_id($hash->{user}{id});
+ $self->discord_name($hash->{user}{username});
+
+ say localtime(time) . " - Connected to Discord. $self->{discord_id}";
+}
+
+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;
+ }
+}
+
+sub discord_channel_create {
+ my $self = shift;
+ my $chan = shift;
+
+ for my $key (keys %{$chan}) {
+ say localtime(time) . " - $key - $chan->{$key}";
+ }
+ $self->discord_channels->{$chan->{id}} = $chan;
+}
+
sub parseCommand {
my ($self, $msg, $server, $nick, $address, $channel, $model) = @_;
}
$address =~ s/.*@(.*)/$1/;
- my $c = NDIRC::Context->new({
+ my $c = NDIRC::IrcContext->new({
host => $address,
nick => $nick,
channel => $channel,
return $self->disp->run_command($c,$command,$args);
}
+sub toTarget {
+ my ($self, $target, $msg) = @_;
+
+ return unless exists $self->targets->{$target};
+
+ my $session = $poe_kernel->get_active_session();
+ my $heap = $session->get_heap();
+ my $irc = $heap->{irc};
+
+
+ for (@{$self->targets->{$target}}) {
+ when (/^#/) {
+ $irc->yield(privmsg => $_, $msg);
+ }
+ when (/^d-(\d+)/i) {
+ $self->discord->send_message($1, $msg );
+ }
+ }
+}
+
1;