From c56f8b4359f2730bb9e8bccd40bf2c9fa840f433 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 23:20:01 -0400 Subject: First working rewrite --- lib/IRC/Client/Grammar.pm6 | 4 ++-- lib/IRC/Client/Grammar/Actions.pm6 | 18 ++++++++++++------ lib/IRC/Client/Message.pm6 | 25 ++++++++++++++++++++----- lib/IRC/Client/Plugin.pm6 | 4 ++++ 4 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 lib/IRC/Client/Plugin.pm6 (limited to 'lib/IRC/Client') diff --git a/lib/IRC/Client/Grammar.pm6 b/lib/IRC/Client/Grammar.pm6 index a258e56..feec9fd 100644 --- a/lib/IRC/Client/Grammar.pm6 +++ b/lib/IRC/Client/Grammar.pm6 @@ -1,6 +1,6 @@ unit grammar IRC::Client::Grammar; -token TOP { + } -token leftovers { \N* } +token TOP { + } +token left-overs { \N* } token SPACE { ' '+ } token message { [':' ]? \n } token prefix { diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index 6ebe33d..cf702f8 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -40,8 +40,8 @@ method message ($match) { irc => $!irc, nick => %args//'', server => $!server, + usermask => ~($match//''), username => %args//''; - . = . ~ '!' ~ . ~ '@' ~ . given %msg-args; my $msg; given %msg-args { @@ -53,11 +53,17 @@ method message ($match) { :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 } + when 'PART' { + $msg = IRC::Client::Message::Part.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 } + when 'QUIT' { $msg = IRC::Client::Message::Quit.new: |%msg-args } + default { $msg = IRC::Client::Message::Unknown.new: |%msg-args } } $match.make: $msg; diff --git a/lib/IRC/Client/Message.pm6 b/lib/IRC/Client/Message.pm6 index 4abb718..1b38d23 100644 --- a/lib/IRC/Client/Message.pm6 +++ b/lib/IRC/Client/Message.pm6 @@ -10,7 +10,7 @@ role IRC::Client::Message { has Str:D $.server is required; has @.args is required; - method Str { "$.command @.args[]" } + method Str { ":$!usermask $!command @!args[]" } } constant M = IRC::Client::Message; @@ -23,11 +23,26 @@ role Mode does M { has @.modes; } role Mode::Channel does Mode { has $.channel; } role Mode::Me does Mode { } role Numeric does M { } -role Privmsg does M { has $.text; } -role Privmsg::Channel does Privmsg { has $.channel; } -role Privmsg::Me does Privmsg { } -role Unknown does M { method Str { "❚⚠❚ $.command @.args[]" } } +role Part does M { has $.channel; } +role Quit does M { } +role Unknown does M { + method Str { "❚⚠❚ :$.usermask $.command @.args[]" } +} role Ping does M { method reply { $.irc.send-cmd: 'PONG', @.args; } } + +role Privmsg does M { has $.text; } +role Privmsg::Channel does Privmsg { + has $.channel; + method reply ($text, :$where) { + $.irc.send-cmd: 'PRIVMSG', $where // $.channel, $text; + } +} +role Privmsg::Me does Privmsg { + method reply ($text, :$where) { + $where //= $.nick; + $.irc.send-cmd: 'PRIVMSG', $where, $text; + } +} diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6 new file mode 100644 index 0000000..2493c3f --- /dev/null +++ b/lib/IRC/Client/Plugin.pm6 @@ -0,0 +1,4 @@ +unit role IRC::Client::Plugin; + +has $.IRC_HANDLED = my class IRC_FLAG_HANDLED {}; +has $.IRC_NOT_HANDLED = my class IRC_FLAG_NOT_HANDLED {}; -- cgit v1.1