Skip to content

Commit de3270c

Browse files
committed
Add some normalization in Tellable
1 parent 17fb275 commit de3270c

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

xbin/Tellable.p6

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,41 @@ method help($msg) {
3131
Like this: .tell AlexDaniel your bot is broken
3232
}
3333

34+
#| normalize nicknames, somewhat
35+
sub normalize-weirdly($_ is copy) {
36+
# We knowingly ignore CASEMAPPING and its bullshit rules.
37+
# Instead we'll do our own crazy stuff in order to DWIM.
38+
# These rules are based on messages that were never delivered.
39+
40+
# XXX not using s/// because there's a sub s (rakudo/rakudo#3111)
41+
$_ .= fc;
42+
$_ = S/‘[m]’$//; # matrix users
43+
$_ = S/\W+$//; # garbage at the end
44+
$_ = S/^\W+//; # garbage at the beginning
45+
$_ = S:g/‘-’//; # hyphens
46+
$_ = S/^(.*?)\d+/$0/; # numbers at the end
47+
$_ = S:g/(.)$0/$0/; # accidentally doubled letters
48+
$_
49+
}
50+
3451
#| listen for messages
3552
multi method irc-privmsg-channel($msg) {
53+
my $normalized = normalize-weirdly $msg.nick;
3654
$db-seen.read-write: {
37-
.{$msg.nick} = {
55+
.{$normalized} = {
3856
text => $msg.text,
3957
channel => $msg.channel,
4058
timestamp => timestampish,
4159
nick => $msg.nick,
4260
}
4361
}
4462
my %mail = $db-tell.read;
45-
if %mail{$msg.nick} {
46-
for %mail{$msg.nick}.list {
63+
if %mail{$normalized} {
64+
for %mail{$normalized}.list {
4765
my $text = sprintf %s %s <%s> %s, .<timestamp channel from text>;
4866
$msg.irc.send-cmd: 'PRIVMSG', $msg.channel, $text, :server($msg.server)
4967
}
50-
%mail{$msg.nick}:delete;
68+
%mail{$normalized}:delete;
5169
$db-tell.write: %mail;
5270
}
5371
$.NEXT
@@ -89,27 +107,28 @@ multi method irc-to-me($msg where { m:r/^ \s* [seen \s+]?
89107
$<who>=<.&irc-nick> <[:,]>* \s* $/ }) {
90108
my $who = ~$<who>;
91109
my %seen := $db-seen.read;
92-
my $entry = %seen{$who};
110+
my $entry = %seen{normalize-weirdly $who};
93111
without $entry {
94112
return I haven't seen $who around
95113
~ maybe , did you mean %s?, did-you-mean-seen $who, %seen
96114
}
97-
I saw $who $entry<timestamp> in $entry<channel>: <$who> $entry<text>
115+
I saw $who $entry<timestamp> in $entry<channel>: <$entry<nick>> $entry<text>
98116
}
99117

100118
#| tell
101119
multi method irc-to-me($msg where { m:r/^ \s* [[to|tell|ask] \s+]?
102120
$<who>=<.&irc-nick> <[:,]>* \s+ .* $/ }) {
103121
my $who = ~$<who>;
122+
my $normalized = normalize-weirdly $who;
104123
return Thanks for the message if $who eq $msg.server.current-nick;
105124
return I'll pass that message to your doctor if $who eq $msg.nick and not %*ENV<TESTABLE>;
106125
my %seen := $db-seen.read;
107-
without %seen{$who} {
126+
without %seen{$normalized} {
108127
return I haven't seen $who around
109128
~ maybe , did you mean %s?, did-you-mean-seen $who, %seen
110129
}
111130
$db-tell.read-write: {
112-
.{$who}.push: {
131+
.{$normalized}.push: {
113132
text => $msg.text,
114133
channel => $msg.channel,
115134
timestamp => timestampish,

0 commit comments

Comments
 (0)