Skip to content

Commit b1e7958

Browse files
committed
Add :alias feature
Closes #22
1 parent 8bb81d2 commit b1e7958

File tree

7 files changed

+44
-11
lines changed

7 files changed

+44
-11
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Revision history for IRC::Client
22

3+
3.006001 2016-08-07
4+
- Add `:alias` feature (#22)
5+
36
3.005001 2016-08-07
47
- Make addressed regex more restrictive (#21)
58

META6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"perl" : "6.c",
33
"name" : "IRC::Client",
4-
"version" : "3.005001",
4+
"version" : "3.006001",
55
"description" : "Extendable Internet Relay Chat client",
66
"depends" : [
77
],

docs/02-event-reference.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ irc-addressed ▶ irc-to-me ▶ irc-notice-channel ▶ irc-notice ▶
8383

8484
This event chain is triggered when the client is addressed in a channel either
8585
via a `PRIVMSG` or `NOTICE` IRC message. 'Addressed' means the message line
86-
starts with the current nickname of the client, followed by `;` or `,`
86+
starts with the current nickname of the client or one of its aliases,
87+
followed by `;` or `,`
8788
characters, followed by any number of whitespace; or
88-
in regex terms, matches `/^ $nick <[,:]> \s* /`. This prefix portion will be
89+
in regex terms, matches `/^ [$nick | @aliases] <[,:]> \s* /`.
90+
This prefix portion will be
8991
**stripped** from the actual message.
9092

9193
Possible message objects received by event handler:
@@ -140,8 +142,8 @@ irc-mentioned ▶ irc-notice-channel ▶ irc-notice ▶ irc-all
140142

141143
This event chain is triggered when the client is mentioned in a channel either
142144
via a `PRIVMSG` or `NOTICE` IRC message. Being mentioned means the message
143-
contains our nick delimited by word boundaries on both sides; or in regex
144-
terms, matches `/ << $nick >> /`.
145+
contains our nick or one of the aliases delimited by word boundaries on both
146+
sides; or in regex terms, matches `/ << [$nick | @aliases] >> /`.
145147

146148
Possible message objects received by event handler:
147149
* `IRC::Client::Message::Privmsg::Channel`
@@ -306,8 +308,8 @@ irc-addressed ▶ irc-to-me ▶ irc-notice-channel ▶ irc-notice ▶
306308
This event chain is triggered when the client is addressed in a channel via
307309
a `PRIVMSG` or `NOTICE` IRC message or receives a private or notice
308310
message directly. In cases where the trigger happened due to being addressed
309-
in channel, the prefix used for addressing (nick + `,` or `.` + whitespace)
310-
will be stripped from the message.
311+
in channel, the prefix used for addressing (nick|aliases + `,` or `.` +
312+
whitespace) will be stripped from the message.
311313

312314
Possible message objects received by event handler:
313315
* `IRC::Client::Message::Privmsg::Channel`

docs/03-method-reference.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ the channel and the value is its password.
354354
A list of nicks the client uses on this server. If one nick is
355355
taken, next one in the list will be attempted to be used.
356356

357+
#### `.alias`
358+
359+
A list of aliases on this server.
360+
357361
#### `.host`
358362

359363
The host of the server.
@@ -445,6 +449,7 @@ my $irc = IRC::Client.new:
445449
:password<s3cret>
446450
:channels<#perl #perl6 #rust-lang>
447451
:nick<MahBot>
452+
:alias('foo', /b.r/)
448453
:username<MahBot>
449454
:userhost<localhost>
450455
:userreal('Mah awesome bot!')
@@ -515,8 +520,22 @@ generate three additional nicknames that have underscores appended
515520
If one of the given nicks is in use, the client will attempt to use the
516521
next one in the list.
517522

523+
##### `:alias`
524+
518525
**Defaults to:** `P6Bot`
519526

527+
```perl6
528+
:alias('foo', /b.r/)
529+
```
530+
531+
A list of `Str` or `Regex` objects that in the context of
532+
`irc-addressed`, `irc-to-me`, and `irc-mentioned` events will be used
533+
as alternative nicks. In other words, specifying `'bot'` as alias will allow
534+
you to address the bot using `bot` nick, regardless of the actual nick the
535+
bot is currently using.
536+
537+
**Defaults to:** empty list
538+
520539
##### `:password`
521540

522541
The server password to use. On some networks (like Freenode), the server

examples/02-trickster-bot.p6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class BFF { method irc-to-me ($ where /'♥'/) { 'I ♥ YOU!' } }
1313

1414
.run with IRC::Client.new:
1515
:nick<MahBot>
16+
:alias('foo', /b.r/)
1617
:host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
1718
:channels<#zofbot>
1819
:debug

lib/IRC/Client.pm6

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ submethod BUILD (
4141
Str :$password,
4242
Str:D :$host = 'localhost',
4343
:$nick = ['P6Bot'],
44+
:$alias = [],
4445
Str:D :$username = 'Perl6IRC',
4546
Str:D :$userhost = 'localhost',
4647
Str:D :$userreal = 'Perl6 IRC Client',
@@ -50,7 +51,7 @@ submethod BUILD (
5051
@!plugins = @$plugins;
5152
my %servers = %$servers;
5253

53-
my %all-conf = :$port, :$password, :$host, :$nick,
54+
my %all-conf = :$port, :$password, :$host, :$nick, :$alias,
5455
:$username, :$userhost, :$userreal, :$channels;
5556

5657
%servers = '_' => {} unless %servers;
@@ -61,6 +62,7 @@ submethod BUILD (
6162
:$label,
6263
:channels( @($conf<channels> // %all-conf<channels>) ),
6364
:nick[ |($conf<nick> // %all-conf<nick>) ],
65+
:alias[ |($conf<alias> // %all-conf<alias>) ],
6466
|%(
6567
<host password port username userhost userreal>
6668
.map: { $_ => $conf{$_} // %all-conf{$_} }
@@ -234,11 +236,16 @@ method !handle-event ($e) {
234236
my @events = flat gather {
235237
given $event-name {
236238
when 'irc-privmsg-channel' | 'irc-notice-channel' {
237-
my $nick = $s.current-nick;
238-
if $e.text.subst-mutate: /^ $nick <[,:]> \s* /, '' {
239+
my $nick = $s.current-nick;
240+
my @aliases = $s.alias;
241+
if $e.text.subst-mutate:
242+
/^ [ $nick | @aliases ] <[,:]> \s* /, ''
243+
{
239244
take 'irc-addressed', ('irc-to-me' if $s.is-connected);
240245
}
241-
elsif $e.text ~~ / << $nick >> / and $s.is-connected {
246+
elsif $e.text ~~ / << [ $nick | @aliases ] >> /
247+
and $s.is-connected
248+
{
242249
take 'irc-mentioned';
243250
}
244251
take $event-name, $event-name eq 'irc-privmsg-channel'

lib/IRC/Client/Server.pm6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ unit class IRC::Client::Server;
22

33
has @.channels where .all ~~ Str|Pair;
44
has @.nick where .all ~~ Str;
5+
has @.alias where .all ~~ Str|Regex;
56
has Int $.port where 0 <= $_ <= 65535;
67
has Str $.label;
78
has Str $.host;

0 commit comments

Comments
 (0)