From ef0a9de8eb4a8c1bf3e82d18b1dadd54637a7c98 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Wed, 25 Nov 2015 13:32:59 -0500 Subject: Intermediary --- DESIGN-NOTES.md | 25 +++++++++++++++++++++++++ examples/bot.pl6 | 9 +++++++++ lib/IRC/Client.pm6 | 42 +++++++++++++++++++++++++++++++++++++++++- lib/IRC/Client/Plugin.pm6 | 8 ++++++++ lib/IRC/Client/Plugin/HNY.pm6 | 8 ++++++++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 DESIGN-NOTES.md create mode 100644 lib/IRC/Client/Plugin.pm6 create mode 100644 lib/IRC/Client/Plugin/HNY.pm6 diff --git a/DESIGN-NOTES.md b/DESIGN-NOTES.md new file mode 100644 index 0000000..b91ec73 --- /dev/null +++ b/DESIGN-NOTES.md @@ -0,0 +1,25 @@ +## Just some notes jotted down while reading RFCs + +#### RFC 1459 + +http://irchelp.org/irchelp/rfc/rfc.html + +Nicks can only be 9-chars long max. + +Channels names are strings (beginning with a ‘&’ or ‘#’ character) of length up +to 200 characters. Apart from the the requirement that the first character being +either ‘&’ or ‘#’; the only restriction on a channel name is that it may not +contain any spaces (’ ‘), a control G (^G or ASCII 7), or a comma (‘,’ which is +used as a list item separator by the protocol). + +A channel operator is identified by the ‘@’ symbol next to their nickname +whenever it is associated with a channe + +Because of IRC’s scandanavian origin, the characters {}| are considered to be +the lower case equivalents of the characters []\, respectively. This is a +critical issue when determining the equivalence of two nicknames. + +Each IRC message may consist of up to three main parts: the prefix (optional), +the command, and the command parameters (of which there may be up to 15). The +prefix, command, and all parameters are separated by one (or more) ASCII space +character(s) (0x20). diff --git a/examples/bot.pl6 b/examples/bot.pl6 index 4840fab..f2b69ea 100644 --- a/examples/bot.pl6 +++ b/examples/bot.pl6 @@ -1,2 +1,11 @@ use v6; +use lib 'lib'; use IRC::Client; +use IRC::Client::Plugin::HNY; +say "42"; +my $irc = IRC::Client.new( + :host('10.10.11.12'), + plugins => [ + IRC::Client::Plugin::HNY.new, + ] +).run; diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index ff0243a..d4a00ca 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -1,2 +1,42 @@ use v6; -unit package IRC::Client:version<1.001001>; +class IRC::Client::Plugin { ... } +class IRC::Client:ver<1.001001> { + + has Str $.host = 'localhost'; + has Int $.port where 0 <= $_ <= 65535 = 6667; + has Str $.nick where 1 <= .chars <= 9 = 'Perl6IRC'; + has Str $.username = 'Perl6IRC'; + has Str $.userhost = 'localhost'; + has Str $.userreal = 'Perl6 IRC Client'; + has Str @.channels = ['#perl6bot']; + has IO::Socket::Async $.sock; + has IRC::Client::Plugin @.plugins = []; + + method run { + await IO::Socket::Async.connect( $!host, $!port ).then({ + $!sock = .result; + $.ssay("NICK $!nick\n"); + $.ssay("USER $!username $!userhost $!host :$!userreal\n"); + $.ssay("JOIN $_\n") for @!channels; + + Supply.interval( .interval ).tap({ $OUTER::_.interval(self) }) + for @!plugins.grep(*.interval); + + react { + whenever $!sock.chars-supply -> $str is copy { + $str.say; + .msg(self, $str) for @!plugins.grep(so *.msg); + } + } + + say "Closing connection"; + $!sock.close; + }); + } + + method ssay (Str:D $msg) { + $!sock.print("$msg\n"); + + self; + } +} diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6 new file mode 100644 index 0000000..724447e --- /dev/null +++ b/lib/IRC/Client/Plugin.pm6 @@ -0,0 +1,8 @@ +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/HNY.pm6 b/lib/IRC/Client/Plugin/HNY.pm6 new file mode 100644 index 0000000..7f52302 --- /dev/null +++ b/lib/IRC/Client/Plugin/HNY.pm6 @@ -0,0 +1,8 @@ +use v6; +use IRC::Client; +use IRC::Client::Plugin; +unit class IRC::Client::Plugin::HNY:ver<1.001001> does IRC::Client::Plugin; +multi method interval ( ) { 2 } +multi method interval (IRC::Client $irc) { + $irc.ssay("5 seconds passed. Time is now " ~ now); +} -- cgit v1.1