Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/crab2313/Net--IRC

Conflicts:
	lib/Net/IRC/Bot.pm
  • Loading branch information...
commit b8c8a0466bfda89a29f11bed6d3db616c6a86ae3 2 parents 7af1fb4 + 91e0054
@TiMBuS authored
View
17 README.pod
@@ -6,14 +6,7 @@ Elegant. Simple. Probably compiles.
use Net::IRC::Bot;
use Net::IRC::Modules::Autoident;
-
- class AnnoyUsers does ExtraAnnoying {
- #Will be called when the bot gets a join event
- multi method joined ($e) {
- $e.reply("Hi there, {$e.who<nick>}!");
- }
- }
-
+
#Roles can let you break up large event handler modules into smaller ones.
role ExtraAnnoying {
has %enemies = ('bob', 'sam', 'chanserv') X=> 1;
@@ -23,6 +16,14 @@ Elegant. Simple. Probably compiles.
}
}
+
+ class AnnoyUsers does ExtraAnnoying {
+ #Will be called when the bot gets a join event
+ multi method joined ($e) {
+ $e.reply("Hi there, {$e.who<nick>}!");
+ }
+ }
+
Net::IRC::Bot.new(
nick => 'KickMe',
View
6 lib/Net/IRC/Bot.pm
@@ -1,5 +1,5 @@
use v6;
-use Net::IRC::DefaultHandlers;
+use Net::IRC::Handlers::Default;
use Net::IRC::Parser;
use Net::IRC::Event;
@@ -31,7 +31,7 @@ class Net::IRC::Bot {
method new(|$) {
my $obj = callsame();
- $obj.modules.push(Net::IRC::DefaultHandlers.new);
+ $obj.modules.push(Net::IRC::Handlers::Default.new);
$obj
}
@@ -109,6 +109,7 @@ class Net::IRC::Bot {
:what(~$raw<params>[$l ?? $l-1 !! 0]),
);
+
# Dispatch to the raw event handlers.
@.modules>>.*"irc_{ lc $event.command }"($event);
given uc $event.command {
@@ -165,3 +166,4 @@ class Net::IRC::Bot {
}
}
+# vim: ft=perl6 sw=4 expandtab
View
83 lib/Net/IRC/Event.pm
@@ -1,46 +1,49 @@
use v6;
class Net::IRC::Event {
- #EVERY event has to have these:
- has $.raw is rw;
- has $.command is rw;
- has $.conn is rw;
- has $.state is rw;
-
- #Most events can have these.
- has $.who is rw;
- has $.what is rw;
- has $.where is rw;
-
- ##Utility methods
- method msg($text, $to = $.where) {
- ##IRC RFC specifies 510 bytes as the maximum allowed to send per line.
- #I'm going with 480, as 510 seems to get cut off on some servers.
+ #EVERY event has to have these:
+ has $.raw is rw;
+ has $.command is rw;
+ has $.conn is rw;
+ has $.state is rw;
+
+ #Most events can have these.
+ has $.who is rw;
+ has $.what is rw;
+ has $.where is rw;
- my $prepend = "PRIVMSG $to :";
- my $maxlen = 480-$prepend.bytes;
- for $text.split(/\c13?\c10/) -> $line is rw {
- while $line.bytes > $maxlen {
- #Break up the line using a nearby space if possible.
- my $index = $line.rindex(" ", $maxlen) || $maxlen;
- $.conn.sendln($prepend~$line.substr(0, $index));
- $line = $line.substr($index+1);
- }
- $.conn.sendln($prepend~$line);
- }
- }
-
- method act($text, $to = $.where) {
- $.conn.sendln("PRIVMSG $to :\c01ACTION $text\c01")
- }
-
- method send_ctcp($text, $to = $.where) {
- $.conn.sendln("NOTICE $to :\c01$text\c01");
- }
-
-
- method Str {
- $.what ?? ~$.what !! $.raw;
- }
+
+ ##Utility methods
+ method msg($text, $to = $.where) {
+ ##IRC RFC specifies 510 bytes as the maximum allowed to send per line.
+ #I'm going with 480, as 510 seems to get cut off on some servers.
+
+ my $prepend = "PRIVMSG $to :";
+ my $maxlen = 480-$prepend.bytes;
+ for $text.split(/\c13?\c10/) -> $line is rw {
+ while $line.bytes > $maxlen {
+ #Break up the line using a nearby space if possible.
+ my $index = $line.rindex(" ", $maxlen) || $maxlen;
+ $.conn.sendln($prepend~$line.substr(0, $index));
+ $line = $line.substr($index+1);
+ }
+ $.conn.sendln($prepend~$line);
+ }
+ }
+
+ method act($text, $to = $.where) {
+ $.conn.sendln("PRIVMSG $to :\c01ACTION $text\c01")
+ }
+
+ method send_ctcp($text, $to = $.where) {
+ $.conn.sendln("NOTICE $to :\c01$text\c01");
+ }
+
+
+ method Str {
+ $.what ?? ~$.what !! $.raw;
+ }
}
+
+# vim: ft=perl6 expandtab sw=4
View
4 lib/Net/IRC/DefaultHandlers.pm → lib/Net/IRC/Handlers/Default.pm
@@ -1,6 +1,6 @@
use v6;
-class Net::IRC::DefaultHandlers {
+class Net::IRC::Handlers::Default {
##Some default handler methods
#Error handler
@@ -96,3 +96,5 @@ class Net::IRC::DefaultHandlers {
}
}
+# vim: ft=perl6 sw=4 expandtab
+
Please sign in to comment.
Something went wrong with that request. Please try again.