From 5a2196b2c8f2ac2eacb3ddaf40b3e75b9c38bb62 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 19:18:31 -0400 Subject: Stuff --- lib/IRC/Client/Grammar/Actions.pm6 | 74 ++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 11 deletions(-) (limited to 'lib/IRC/Client/Grammar') 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; loop { - if ( $p.defined ) { - %args.append: ~$p; - } + %args.append: ~$p if $p.defined; + if ( $p.defined ) { %args.append: ~$p; last; @@ -35,22 +34,75 @@ method message ($match) { } my %msg-args = + command => $match.uc, + args => %args, + host => %args//'', irc => $!irc, nick => %args//'', - username => %args//'', - host => %args//'', - server => $!server; + server => $!server, + username => %args//''; . = . ~ '!' ~ . ~ '@' ~ . given %msg-args; my $msg; - given ~$match { + given %msg-args { when /^ $=(<[0..9]>**3) $/ { - $msg = IRC::Client::Message::Numeric.new: - :command( ~$ ), - :args( %args ), + $msg = IRC::Client::Message::Numeric.new: |%msg-args; + } + when 'JOIN' { + $msg = IRC::Client::Message::Join.new: + :channel( %args[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[0] ~~ /^<[#&]>/ + and return IRC::Client::Message::Privmsg::Channel.new: + :channel( %args[0] ), + :text( %args[1] ), + |%msg-args; + + return IRC::Client::Message::Privmsg::Me.new: + :text( %args[1] ), + |%msg-args; +} + +sub msg-notice (%args, %msg-args) { + %args[0] ~~ /^<[#&]>/ + and return IRC::Client::Message::Notice::Channel.new: + :channel( %args[0] ), + :text( %args[1] ), + |%msg-args; + + return IRC::Client::Message::Notice::Me.new: + :text( %args[1] ), + |%msg-args; +} + +sub msg-mode (%args, %msg-args) { + if %args[0] ~~ /^<[#&]>/ { + my @modes; + for %args[1..*-1].join.comb: /\S/ { + state $sign; + /<[+-]>/ and $sign = $_ and next; + @modes.push: $sign => $_; + }; + return IRC::Client::Message::Mode::Channel.new: + :channel( %args[0] ), + :modes( @modes ), + |%msg-args; + } + else { + return IRC::Client::Message::Mode::Me.new: + :modes( %args[1..*-1].join.comb: /<[a..zA..Z]>/ ), + |%msg-args; + } +} -- cgit v1.1