aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2015-12-06 15:05:29 -0500
committerZoffix Znet <cpan@zoffix.com>2015-12-06 15:05:29 -0500
commitba793ec6d1d4c66300f40cbced25f9ffd23ec792 (patch)
treebc419699af8499c4b90026d605f72aa832325ef5 /lib
parente0b2a598b9475edcfca40b7cb4faa7746232a30c (diff)
Debug
Diffstat (limited to 'lib')
-rw-r--r--lib/IRC/Client.pm631
-rw-r--r--lib/IRC/Client/Plugin/Debugger.pm616
-rw-r--r--lib/IRC/Grammar.pm621
-rw-r--r--lib/IRC/Grammar/Actions.pm630
-rw-r--r--lib/IRC/Parser.pm67
5 files changed, 67 insertions, 38 deletions
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index 4635301..dcf0fcb 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -1,16 +1,18 @@
use v6;
+use IRC::Parser; # parse-irc
role IRC::Client::Plugin { ... }
class IRC::Client:ver<1.001001> {
- has Bool:D $.debug = False;
- has Str:D $.host = 'localhost';
- has Int:D $.port where 0 <= $_ <= 65535 = 6667;
- has Str:D $.nick = 'Perl6IRC';
- has Str:D $.username = 'Perl6IRC';
- has Str:D $.userhost = 'localhost';
- has Str:D $.userreal = 'Perl6 IRC Client';
- has Str:D @.channels = ['#perl6bot'];
- has IRC::Client::Plugin @.plugins = [];
+ has Bool:D $.debug = False;
+ has Str:D $.host = 'localhost';
+ has Int:D $.port where 0 <= $_ <= 65535 = 6667;
+ has Str:D $.nick = 'Perl6IRC';
+ has Str:D $.username = 'Perl6IRC';
+ has Str:D $.userhost = 'localhost';
+ 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 = [];
method run {
await IO::Socket::Async.connect( $!host, $!port ).then({
@@ -19,13 +21,16 @@ class IRC::Client:ver<1.001001> {
$.ssay("USER $!username $!userhost $!host :$!userreal\n");
$.ssay("JOIN $_\n") for @!channels;
- Supply.interval( .interval ).tap({ $OUTER::_.interval(self) })
- for @!plugins.grep(*.interval);
+ # Supply.interval( .interval ).tap({ $OUTER::_.interval(self) })
+ # for @!plugins.grep(*.interval);
react {
whenever $!sock.Supply -> $str is copy {
- "[$str]".perl.say;
- .msg(self, $str) for @!plugins.grep(so *.msg);
+ $!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);
}
}
diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6
new file mode 100644
index 0000000..20a2283
--- /dev/null
+++ b/lib/IRC/Client/Plugin/Debugger.pm6
@@ -0,0 +1,16 @@
+use v6;
+use IRC::Client;
+use IRC::Client::Plugin;
+unit class IRC::Client::Plugin::Debugger:ver<1.001001> does IRC::Client::Plugin;
+
+multi method msg () { True }
+multi method msg ($irc, $msg) {
+ $msg.say;
+}
+
+multi method interval ( ) { 6 }
+multi method interval (IRC::Client $irc) {
+ $irc.privmsg(
+ $irc.channels[0], "5 seconds passed. Time is now " ~ now
+ );
+}
diff --git a/lib/IRC/Grammar.pm6 b/lib/IRC/Grammar.pm6
index 46d71cc..d26a3dc 100644
--- a/lib/IRC/Grammar.pm6
+++ b/lib/IRC/Grammar.pm6
@@ -1,6 +1,5 @@
-# use Grammar::Debugger;
unit grammar IRC::Grammar:ver<1.001001>;
-token TOP { <message> }
+token TOP { <message>+ }
token SPACE { ' '+ }
token message { [':' <prefix> <SPACE> ]? <command> <params> \n }
token prefix {
@@ -19,21 +18,3 @@ token message { [':' <prefix> <SPACE> ]? <command> <params> \n }
token letter { <[a..zA..Z]> }
token number { <[0..9]> }
token special { <[-\[\]\\`^{}]> }
-
-# unit class IRC::Grammar::Actions:ver<1.001001>;
-# method TOP ($/) { $/.make: $<message>».made }
-# method message ($/) { $/.make:
-# prefix => $<prefix> .made,
-# command => $<command>.made,
-# params => $<params .made,
-# }
-# method prefix ($/) { [<servername> | <nick>] [ '!' <user> ]? [ '@' <host> ]? }
-# method command ($/) { <letter>+ | <number>**3 }
-# method params ($/) { ' '+ [ ':' <trailing> | <middle> <params> ]? }
-# method middle ($/) { <-[: \0\r\n]> <-[ \0\r\n]>+ }
-# method trailing ($/) { <-[\0\r\n]> }
-#
-# method class ($/) { $/.make: ~$/ }
-# method rules ($/) { $/.make: ~$/ }
-# method pair ($/) { $/.make: $<class>.made => $<rules>.made }
-# method TOP ($/) { $/.make: $<pair>».made }
diff --git a/lib/IRC/Grammar/Actions.pm6 b/lib/IRC/Grammar/Actions.pm6
index 039f11e..7093b99 100644
--- a/lib/IRC/Grammar/Actions.pm6
+++ b/lib/IRC/Grammar/Actions.pm6
@@ -1,6 +1,26 @@
-class IRC::Grammar::Actions {
- method class ($/) { $/.make: ~$/ }
- method rules ($/) { $/.make: ~$/ }
- method pair ($/) { $/.make: $<class>.made => $<rules>.made }
- method TOP ($/) { $/.make: $<pair>».made }
+unit class IRC::Grammar::Actions:ver<1.001001>;
+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;
+ }
+
+ my $p = $/<params>;
+ loop {
+ if ( $p<middle>.defined ) {
+ %args<params>.append: ~$p<middle>;
+ }
+ if ( $p<trailing>.defined ) {
+ %args<params>.append: ~$p<trailing>;
+ last;
+ }
+ $p = $p<params>;
+ }
+
+ $/.make: %args;
}
diff --git a/lib/IRC/Parser.pm6 b/lib/IRC/Parser.pm6
new file mode 100644
index 0000000..aa87fa7
--- /dev/null
+++ b/lib/IRC/Parser.pm6
@@ -0,0 +1,7 @@
+use IRC::Grammar;
+use IRC::Grammar::Actions;
+unit class IRC::Parser:ver<1.001001>;
+
+sub parse-irc (Str:D $input) is export {
+ IRC::Grammar.parse($input, actions => IRC::Grammar::Actions).made // [];
+}