aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2015-12-06 18:07:19 -0500
committerZoffix Znet <cpan@zoffix.com>2015-12-06 18:07:19 -0500
commitd2da9fcd250533bee5df17bd182648a8cea0d7b0 (patch)
treefca0431ce3639d5a2ac85a69c4fe9f05717be789 /lib
parentba793ec6d1d4c66300f40cbced25f9ffd23ec792 (diff)
Prerelease
Diffstat (limited to 'lib')
-rw-r--r--lib/IRC/Client.pm616
-rw-r--r--lib/IRC/Client/Plugin.pm68
-rw-r--r--lib/IRC/Client/Plugin/Debugger.pm69
-rw-r--r--lib/IRC/Client/Plugin/HNY.pm626
-rw-r--r--lib/IRC/Client/Plugin/PingPong.pm610
-rw-r--r--lib/IRC/Grammar/Actions.pm69
6 files changed, 28 insertions, 50 deletions
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index dcf0fcb..a27c18d 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -1,5 +1,6 @@
use v6;
use IRC::Parser; # parse-irc
+use IRC::Client::Plugin::PingPong;
role IRC::Client::Plugin { ... }
class IRC::Client:ver<1.001001> {
has Bool:D $.debug = False;
@@ -11,8 +12,10 @@ class IRC::Client:ver<1.001001> {
has Str:D $.userreal = 'Perl6 IRC Client';
has Str:D @.channels = ['#perl6bot'];
has IO::Socket::Async $.sock;
- has IRC::Client::Plugin @.plugins = [];
- has IRC::Client::Plugin @.plugins-essential = [];
+ has @.plugins = [];
+ has @.plugins-essential = [
+ IRC::Client::Plugin::PingPong.new
+ ];
method run {
await IO::Socket::Async.connect( $!host, $!port ).then({
@@ -27,10 +30,11 @@ class IRC::Client:ver<1.001001> {
react {
whenever $!sock.Supply -> $str is copy {
$!debug and $str.say;
- # say parse-irc($str).WHAT;
- my $x = parse-irc $str;
- @!plugins[0].msg(self, $x);
- .msg(self, $x) for @!plugins.grep(*.msg);
+ my $messages = parse-irc $str;
+ for @$messages -> $message {
+ .msg(self, $message)
+ for (@!plugins-essential, @!plugins).flat.grep(*.msg);
+ }
}
}
diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6
deleted file mode 100644
index 724447e..0000000
--- a/lib/IRC/Client/Plugin.pm6
+++ /dev/null
@@ -1,8 +0,0 @@
-use v6;
-use IRC::Client;
-unit role IRC::Client::Plugin:ver<1.001001>;
-
-multi method inverval ( ) { 0 }
-multi method inverval (IRC::Client) { ... }
-multi method msg ( ) { False }
-multi method msg (IRC::Client) { ... }
diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6
index 20a2283..dabb353 100644
--- a/lib/IRC/Client/Plugin/Debugger.pm6
+++ b/lib/IRC/Client/Plugin/Debugger.pm6
@@ -1,15 +1,14 @@
use v6;
-use IRC::Client;
-use IRC::Client::Plugin;
-unit class IRC::Client::Plugin::Debugger:ver<1.001001> does IRC::Client::Plugin;
+use Data::Dump;
+unit class IRC::Client::Plugin::Debugger:ver<1.001001>;
multi method msg () { True }
multi method msg ($irc, $msg) {
- $msg.say;
+ say Dump $msg, :indent(4);
}
multi method interval ( ) { 6 }
-multi method interval (IRC::Client $irc) {
+multi method interval ($irc) {
$irc.privmsg(
$irc.channels[0], "5 seconds passed. Time is now " ~ now
);
diff --git a/lib/IRC/Client/Plugin/HNY.pm6 b/lib/IRC/Client/Plugin/HNY.pm6
deleted file mode 100644
index ce7154d..0000000
--- a/lib/IRC/Client/Plugin/HNY.pm6
+++ /dev/null
@@ -1,26 +0,0 @@
-use v6;
-use JSON::Tiny;
-use IRC::Client;
-use IRC::Client::Plugin;
-
-unit class IRC::Client::Plugin::HNY:ver<1.001001> does IRC::Client::Plugin;
-
-
-get_UTC_offsets();
-
-multi method interval ( ) { 6 }
-multi method interval (IRC::Client $irc) {
- $irc.privmsg(
- $irc.channels[0], "5 seconds passed. Time is now " ~ now
- );
-}
-
-
-
-sub get_UTC_offsets {
- my $times = from-json 'tzs.json'.IO.slurp;
-
- for $times -> $zone {
- say "Offset is $zone<offset>";
- }
-}
diff --git a/lib/IRC/Client/Plugin/PingPong.pm6 b/lib/IRC/Client/Plugin/PingPong.pm6
new file mode 100644
index 0000000..7ba977d
--- /dev/null
+++ b/lib/IRC/Client/Plugin/PingPong.pm6
@@ -0,0 +1,10 @@
+use v6;
+unit class IRC::Client::Plugin::PingPong:ver<1.001001>;
+
+multi method msg () { True }
+multi method msg ($irc, $msg) {
+ return unless $msg<command> eq 'PING';
+ my $res = "PONG {$irc.nick} $msg<params>[0]";
+ $irc.debug and say $res;
+ $irc.ssay($res);
+}
diff --git a/lib/IRC/Grammar/Actions.pm6 b/lib/IRC/Grammar/Actions.pm6
index 7093b99..74a8f11 100644
--- a/lib/IRC/Grammar/Actions.pm6
+++ b/lib/IRC/Grammar/Actions.pm6
@@ -3,12 +3,11 @@ method TOP ($/) { $/.make: $<message>>>.made }
method message ($/) {
my $pref = $/<prefix>;
my %args = command => ~$/<command>;
- if ( $pref<servername>.defined ) {
- %args<who><host> = ~$pref<servername>;
- }
- else {
- %args<who><nick user host> = $pref<nick user host>ยป.Str;
+ for qw/nick user host/ {
+ $pref{$_}.defined or next;
+ %args<who>{$_} = $pref{$_}.Str;
}
+ %args<who><host> = ~$pref<servername> if $pref<servername>.defined;
my $p = $/<params>;
loop {