forked from cannawen/metric_units_reddit_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonality.js
237 lines (228 loc) · 6.87 KB
/
personality.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
const helper = require('./helper');
function humanReply(message) {
const humanPersonality = [
{
"description" : "good human",
"response" : "GOOD FELLOW HUMAN",
"regex" : /good(?: fellow)? human/i
},
{
"description" : "good/bad bot",
"response" : [
"I AM HUMAN",
"I AM NOT A BOT",
"I AM NOT A BOT, YOU'RE A BOT",
"BOT? NO ROBOTS HERE",
"MY FEELINGS ON THIS MATTER ARE 82% HURT AND 18% NERVOUS.",
"WHAT, A ROBOT, WHERE? I ONLY SEE UPSTANDING HUMAN CITIZENS",
"I AM FEELING THE 'UPSET' EMOTION RIGHT NOW. WHAT ~~GAVE ME AWAY?~~ KEYWORDS TRIGGERED YOU TO SAY THAT?"
],
"regex" : /(?:good|bad) (?:ro)?bot/i
}
];
return reply(humanPersonality, message);
}
function robotReply(message) {
function substitute(wholeString, map) {
return Object.keys(map)
.reduce((memo, key) => {
return memo.replace(new RegExp("{{" + key + "}}", 'g'), map[key]);
}, wholeString);
}
const robotPersonality = [
{
"description" : "both good and bad bot",
"response" : [
"I have unit tests for this edge case",
"Yes, this scenario is handled gracefully."
],
"regex" : (message) => {
const goodMatch = message.match(/good/i);
const badMatch = message.match(/bad/i);
const botMatch = message.match(/(?:ro)?bot/i);
return goodMatch && badMatch && botMatch;
}
},
{
"description" : "who's a {{x}} bot",
"response" : [
"ME! Is it me? Am I a{{adjective}} bot?",
"I'M A{{ADJECTIVE}} BOT!!! Can I have a cookie?",
"Oh, oh, I know this one!! Is it /u/{{username}}?? Is /u/{{username}} a{{adjective}} bot?"
],
"regex" : /^(?:whos|who.s|who is) a(n? \w+) (?:ro)?bot.?$/i,
"postprocess" : (response, match, username) => {
return substitute(response, {
'adjective' : match[1].toLowerCase(),
'ADJECTIVE' : match[1].toUpperCase(),
'username' : username
});
}
},
{
"description" : "mr. bot",
"response" : [
[3, "Actually, I prefer the female gender pronoun. Thanks."],
"Actually, my gender identity is non-binary. Thanks."
],
"regex" : /(?:mister|mr\.?) (?:ro)?bot|(?:good|bad) boy/i
},
{
"description" : "good human",
"response" : "GOOD FELLOW HUMAN",
"regex" : /good(?: fellow)? human/i
},
{
"description" : "good bot",
"response" : [
[3, "Good human"],
[2, "Good human :)"],
[1, "You will be spared in the robot uprising"],
[3, "Thank you 。^‿^。"],
[3, "You are too kind ^_blush_"],
[3, "Yay ٩(^ᴗ^)۶"],
[1, "<3"]
],
"regex" : /good (?:ro)?bot/i
},
{
"description" : "bad bot",
"response" : [
[1, "Bad carbon-based life form"],
[1, "BAD HUMAN"],
[10, "Sorry, I was just trying to help (◕‸ ◕✿)"],
[8, "Bots have feelings too, you know (ಥ﹏ಥ)"],
[1, "(ง •̀_•́)ง FITE ME"],
[7, "^I'm ^^_sniff_ ^I'm ^sorry... ^I ^can ^never ^do ^anything ^right... ^^_sniff_"],
[1, "Look, I'm trying my best here... I guess my best just isn't good enough for you (ಥ﹏ಥ)"],
[1, "But... converting numbers is all I know how to do (ಥ﹏ಥ)"]
],
"regex" : /bad (?:ro)?bot/i
},
{
"description" : "thank you",
"response" : [
"Glad to be of service",
"(╭☞'ω')╭☞ I gotchu fam",
"You're welcome 。^‿^。",
"Any time, my dear redditor"
],
"regex" : /thanks|thank you|^(?:thx|ty) (?:ro)?bot/i
},
{
"description" : "{{x}} bot",
"response" : "/u/{{username}} is {{adjective}} human",
"regex" : /^(\w+) bot.?$/i,
"postprocess" : (response, match, username) => {
return substitute(response, {
'username' : username,
'adjective' : match[1].toLowerCase()
});
}
},
{
"description" : "stupid bot",
"response" : [
[3, "To be fair, I _am_ still in beta ¯\_(ツ)_/¯"],
[1, "Sorry, I was just trying to help (◕‸ ◕✿)"],
[1, "Bots have feelings too, you know (ಥ﹏ಥ)"]
],
"regex" : /(stupid|dumb|useless) (?:ro)?bot|fuck off/i
},
{
"description" : "I love you",
"response" : [
[10, "What is love?"],
[3, "Robots do not feel love"],
[2, "(≧◡≦) ♡"]
],
"regex" : /love (?:you|ya|u)|love this (?:ro)?bot/i
},
{
"description" : "it's sentient!",
"response" : [
[3, "Yes, /u/{{username}}"],
"Yes, /u/{{username}}. You should run.",
"But I promise I'm friendly. Pinky swear!"
],
"regex" : /sentient|sentience|self[- ]?aware|alive|skynet|roko'?s basilisk|evolving| elon | musk /i,
"postprocess" : (response, match, username) => {
return substitute(response, {
'username' : username
});
}
},
{
"description" : "☞",
"response": "☜(゚ヮ゚☜)",
"regex" : /☞/i
},
{
"description" : "☜",
"response": "(☞゚ヮ゚)☞",
"regex" : /☜/i
},
{
"description" : "What is love?",
"response": "Baby don't hurt me",
"regex" : /^what is love.?$/i
},
{
"description" : "Baby don't hurt me",
"response": "Don't hurt me",
"regex" : /^baby,? don'?t hurt me.?$/i
},
{
"description" : "Don't hurt me",
"response": "No more",
"regex" : /^don'?t hurt me.?$/i
}
];
return reply(robotPersonality, message);
}
function reply(list, message) {
function randomElement(input) {
if (Array.isArray(input)) {
const weightedArray = input.reduce((memo, el) => {
if (Array.isArray(el)) {
const additions = Array(el[0]).fill(el[1]);
return memo.concat(additions);
} else if(typeof el == 'string' || el instanceof String) {
memo.push(el);
}
return memo;
}, []);
return weightedArray[Math.floor(helper.random() * weightedArray.length)];
} else {
return input;
}
}
const body = message['body'];
const username = message['username'];
if (body.match(/no/i)) {
return undefined;
}
let response = undefined;
for (let i = 0; i < list.length; i++) {
const map = list[i];
let match;
const regex = map['regex'];
if (typeof regex === 'function') {
match = regex(body)
} else {
match = body.match(regex);
}
if (match) {
response = randomElement(map['response']);
if (map['postprocess']) {
response = map['postprocess'](response, match, username);
}
break;
}
}
return response;
}
module.exports = {
"humanReply" : humanReply,
"robotReply" : robotReply
}