aboutsummaryrefslogtreecommitdiff
path: root/lib/IRC/Client/Grammar/Actions.pm6
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IRC/Client/Grammar/Actions.pm6')
-rw-r--r--lib/IRC/Client/Grammar/Actions.pm674
1 files changed, 63 insertions, 11 deletions
diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6
index 54943bd..6ebe33d 100644
--- a/lib/IRC/Client/Grammar/Actions.pm6
+++ b/lib/IRC/Client/Grammar/Actions.pm6
@@ -1,6 +1,6 @@
unit class IRC::Client::Grammar::Actions;
-use IRC::Client::Message::Numeric;
+use IRC::Client::Message;
has $.irc;
has $.server;
@@ -23,9 +23,8 @@ method message ($match) {
my $p = $match<params>;
loop {
- if ( $p<middle>.defined ) {
- %args<params>.append: ~$p<middle>;
- }
+ %args<params>.append: ~$p<middle> if $p<middle>.defined;
+
if ( $p<trailing>.defined ) {
%args<params>.append: ~$p<trailing>;
last;
@@ -35,22 +34,75 @@ method message ($match) {
}
my %msg-args =
+ command => $match<command>.uc,
+ args => %args<params>,
+ host => %args<who><host>//'',
irc => $!irc,
nick => %args<who><nick>//'',
- username => %args<who><user>//'',
- host => %args<who><host>//'',
- server => $!server;
+ server => $!server,
+ username => %args<who><user>//'';
.<usermask> = .<nick> ~ '!' ~ .<username> ~ '@' ~ .<host> given %msg-args;
my $msg;
- given ~$match<command> {
+ given %msg-args<command> {
when /^ $<command>=(<[0..9]>**3) $/ {
- $msg = IRC::Client::Message::Numeric.new:
- :command( ~$<command> ),
- :args( %args<params> ),
+ $msg = IRC::Client::Message::Numeric.new: |%msg-args;
+ }
+ when 'JOIN' {
+ $msg = IRC::Client::Message::Join.new:
+ :channel( %args<params>[0] ),
|%msg-args;
}
+ when 'NOTICE' { $msg = msg-notice %args, %msg-args }
+ when 'MODE' { $msg = msg-mode %args, %msg-args }
+ when 'PING' { $msg = IRC::Client::Message::Ping.new: |%msg-args; }
+ when 'PRIVMSG' { $msg = msg-privmsg %args, %msg-args }
+ default { $msg = IRC::Client::Message::Unknown.new: |%msg-args }
}
$match.make: $msg;
}
+
+sub msg-privmsg (%args, %msg-args) {
+ %args<params>[0] ~~ /^<[#&]>/
+ and return IRC::Client::Message::Privmsg::Channel.new:
+ :channel( %args<params>[0] ),
+ :text( %args<params>[1] ),
+ |%msg-args;
+
+ return IRC::Client::Message::Privmsg::Me.new:
+ :text( %args<params>[1] ),
+ |%msg-args;
+}
+
+sub msg-notice (%args, %msg-args) {
+ %args<params>[0] ~~ /^<[#&]>/
+ and return IRC::Client::Message::Notice::Channel.new:
+ :channel( %args<params>[0] ),
+ :text( %args<params>[1] ),
+ |%msg-args;
+
+ return IRC::Client::Message::Notice::Me.new:
+ :text( %args<params>[1] ),
+ |%msg-args;
+}
+
+sub msg-mode (%args, %msg-args) {
+ if %args<params>[0] ~~ /^<[#&]>/ {
+ my @modes;
+ for %args<params>[1..*-1].join.comb: /\S/ {
+ state $sign;
+ /<[+-]>/ and $sign = $_ and next;
+ @modes.push: $sign => $_;
+ };
+ return IRC::Client::Message::Mode::Channel.new:
+ :channel( %args<params>[0] ),
+ :modes( @modes ),
+ |%msg-args;
+ }
+ else {
+ return IRC::Client::Message::Mode::Me.new:
+ :modes( %args<params>[1..*-1].join.comb: /<[a..zA..Z]>/ ),
+ |%msg-args;
+ }
+}