@@ -31,23 +31,41 @@ method help($msg) {
31
31
‘ Like this: .tell AlexDaniel your bot is broken’
32
32
}
33
33
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
+
34
51
# | listen for messages
35
52
multi method irc-privmsg-channel ($ msg ) {
53
+ my $ normalized = normalize-weirdly $ msg . nick;
36
54
$ db-seen . read-write: {
37
- . {$ msg . nick } = {
55
+ . {$ normalized } = {
38
56
text => $ msg . text,
39
57
channel => $ msg . channel,
40
58
timestamp => timestampish,
41
59
nick => $ msg . nick,
42
60
}
43
61
}
44
62
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 {
47
65
my $ text = sprintf ‘ %s %s <%s> %s’ , . <timestamp channel from text >;
48
66
$ msg . irc. send-cmd: ' PRIVMSG' , $ msg . channel, $ text , : server($ msg . server)
49
67
}
50
- % mail {$ msg . nick }: delete;
68
+ % mail {$ normalized }: delete;
51
69
$ db-tell . write : % mail ;
52
70
}
53
71
$ . NEXT
@@ -89,27 +107,28 @@ multi method irc-to-me($msg where { m:r/^ \s* [seen \s+]?
89
107
$ < who > =<.& irc - nick > <[ :, ] >* \s * $ / }) {
90
108
my $ who = ~ $ < who > ;
91
109
my % seen := $ db-seen . read ;
92
- my $ entry = % seen {$ who };
110
+ my $ entry = % seen {normalize-weirdly $ who };
93
111
without $ entry {
94
112
return “ I haven't seen $ who around”
95
113
~ maybe ‘ , did you mean %s?’ , did-you-mean-seen $ who , % seen
96
114
}
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>”
98
116
}
99
117
100
118
# | tell
101
119
multi method irc-to-me ($ msg where { m :r /^ \s * [[to| tell| ask] \s + ]?
102
120
$ < who > =<.& irc - nick > <[ :, ] >* \s + .* $ / }) {
103
121
my $ who = ~ $ < who > ;
122
+ my $ normalized = normalize-weirdly $ who ;
104
123
return ‘ Thanks for the message’ if $ who eq $ msg . server. current-nick;
105
124
return ‘ I'll pass that message to your doctor’ if $ who eq $ msg . nick and not % * ENV <TESTABLE >;
106
125
my % seen := $ db-seen . read ;
107
- without % seen {$ who } {
126
+ without % seen {$ normalized } {
108
127
return “ I haven't seen $ who around”
109
128
~ maybe ‘ , did you mean %s?’ , did-you-mean-seen $ who , % seen
110
129
}
111
130
$ db-tell . read-write: {
112
- . {$ who }. push : {
131
+ . {$ normalized }. push : {
113
132
text => $ msg . text,
114
133
channel => $ msg . channel,
115
134
timestamp => timestampish,
0 commit comments