Skip to content

Commit

Permalink
Added some patchwork to make this work with nom
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarrod committed Oct 22, 2011
1 parent 47c259e commit 1e6a243
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
11 changes: 8 additions & 3 deletions lib/Net/IRC/Bot.pm
Expand Up @@ -53,6 +53,7 @@ class Net::IRC::Bot {
but role {
method sendln(Str $string){self.send($string~"\c13\c10")}
};
say 'conn made';

#Send PASS if needed
$conn.sendln("PASS $password") if $password;
Expand All @@ -62,6 +63,7 @@ class Net::IRC::Bot {
#USER Parameters: <username> <hostname> <servername> <realname>
$conn.sendln("NICK $nick");
$conn.sendln("USER $username abc.xyz.net $server :$realname");
say 'sent thing to srvr';
%state<connected> = True;
}

Expand All @@ -81,28 +83,31 @@ class Net::IRC::Bot {
my $line = $conn.get
or die "Connection error.";

my $event = RawEvent.parse($line)
my $event = Net::IRC::Parser::RawEvent.parse($line)
or $*ERR.say("Could not parse the following IRC event: $line") and next;

say ~$event if $debug;
self!dispatch($event);
}
}

multi method !dispatch($raw) {
method !dispatch($raw) {
#Make an event object and fill it as much as we can.
#XXX: Should I just use a single cached Event to save memory?
my $who = ($raw<user> || $raw<server>);
$who does role { method Str { self<nick> || self<host> } };

#XXX Stupid workaround.
my $l = $raw<params>.elems;

my $event = Net::IRC::Event.new(
:raw($raw),
:command(~$raw<command>),
:conn($conn),
:state(%state),
:who($who),
:where(~$raw<params>[0]),
:what(~$raw<params>[*-1]),
:what(~$raw<params>[$l ?? $l-1 !! 0]),
);


Expand Down
2 changes: 1 addition & 1 deletion lib/Net/IRC/Event.pm
Expand Up @@ -25,7 +25,7 @@ class Net::IRC::Event {
#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);
$line = $line.substr($index+1);
}
$.conn.sendln($prepend~$line);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Net/IRC/Modules/ACME.pm
@@ -1,7 +1,7 @@
use v6;
module Modules::ACME;
module Net::IRC::Modules::ACME;

class Eightball {
class Net::IRC::Modules::ACME::Eightball {
my @replies = "Probably not", "Nope", "Never", "Not a chance", "Doubt it", "No",
"Answer hazy.. Oh wait there it is. It's a no.", "Yes.. Haha just kidding. No.",
"No.", "Aww hell naw";
Expand All @@ -11,7 +11,7 @@ class Eightball {
}
}

class Unsmith {
class Net::IRC::Modules::ACME::Unsmith {
has @replies = open('Net/IRC/Modules/unsmith').lines;
my regex sad {
[ ^|\s ]
Expand Down
4 changes: 2 additions & 2 deletions lib/Net/IRC/Modules/Autoident.pm
@@ -1,7 +1,7 @@
use v6;
module Modules::Autoident;
module Net::IRC::Modules::Autoident;

class Autoident {
class Net::IRC::Modules::Autoident {
has $password = die "Need no tell Autoident your password if you want it to work!";
multi method connected($ev) {
say "Identifying with nickserv..";
Expand Down
4 changes: 2 additions & 2 deletions lib/Net/IRC/Modules/Tell.pm
@@ -1,5 +1,5 @@
use v6;
class Tell {
class Net::IRC::Modules::Tell {
class Message {
has $.sender;
has $.message;
Expand Down Expand Up @@ -65,7 +65,7 @@ class Tell {
$hours ?? (", $hours hour" ~
($hours != 1 ?? 's' !! '') ) !! '';
}
dafault {
default {
my $days = ($elapsed / 60 / 60 / 24).round;
return "$days day"~($days != 1 ?? 's' !! '');
}
Expand Down
52 changes: 25 additions & 27 deletions lib/Net/IRC/Parser.pm
@@ -1,35 +1,33 @@
use v6;

class Net::IRC::Parser {
grammar RawEvent {
token TOP {
^
[':' [<user>|<server=host>] <.space> || <?>]
<command>
[ <.space>+ [':'$<params>=(.*)$ || $<params>=<-space>+] ]*
$
}
module Net::IRC::Parser;
grammar RawEvent {
token TOP {
^
[':' [<user>|<server=host>] <.space> || <?>]
<command>
[ <.space>+ [':'$<params>=(.*)$ || $<params>=<-space>+] ]*
$
}

token user {
$<nick>=<-[:!]>+ '!' $<ident>=<-[@]>+ '@' <host>
}
token user {
$<nick>=<-[:!]>+ '!' $<ident>=<-[@]>+ '@' <host>
}

token host {
#[ <-space - [. $ @ !]>+ ] ** '.'
#Due to some IRC servers/services allowing anything as a host format,
#I've decided to define a 'host' as 'anything but a space'. Bah.
<-space>+
}
token host {
#[ <-space - [. $ @ !]>+ ] ** '.'

#Due to some IRC servers/services allowing anything as a host format,
#I've decided to define a 'host' as 'anything but a space'. Bah.
<-space>+
}

token command {
<.alpha>+ | \d\d\d
}
token command {
<.alpha>+ | \d\d\d
}

token params {
[ ':'.*$ | <-space>+ ]
}
token params {
[ ':'.*$ | <-space>+ ]
}


}

0 comments on commit 1e6a243

Please sign in to comment.