-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.coffee
More file actions
178 lines (168 loc) · 4.14 KB
/
helper.coffee
File metadata and controls
178 lines (168 loc) · 4.14 KB
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
# The helper class with shared functions used by many scripts
# Do not delete!
_ = require 'lomath'
# the command regex
typedCmd =
"fun":
"chuck norris": [
/(chuck norris)( me )?(.*)/i
]
"coding love": [
/(donne moi de la )?joie( bordel)?/i
/derni[èe]re joie/i
/((give me|spread) some )?(joy|love)( asshole)?/i
/last (joy|love)/i
/reply to (.+)/i
]
"meme": [
/Y U NO (.+)/i
/aliens guy (.+)/i
/iron price (.+)/i
/brace yourself (.+)/i
/(.*) (ALL the .*)/i
/(I DON'?T ALWAYS .*) (BUT WHEN I DO,? .*)/i
/(.*)(SUCCESS|NAILED IT.*)/i
/(.*) (\w+\sTOO DAMN .*)/i
/(NOT SURE IF .*) (OR .*)/i
/(YO DAWG .*) (SO .*)/i
/(All your .*) (are belong to .*)/i
/(.*)\s*BITCH PLEASE\s*(.*)/i
/(.*)\s*COURAGE\s*(.*)/i
/ONE DOES NOT SIMPLY (.*)/i
/(IF YOU .*\s)(.* GONNA HAVE A BAD TIME)/i
/(.*)TROLLFACE(.*)/i
/(IF .*), ((ARE|CAN|DO|DOES|HOW|IS|MAY|MIGHT|SHOULD|THEN|WHAT|WHENHE|WHICH|WHO|WHY|WILL|WON\'T|WOULD)[ \'N].*)/i
/(.*)(AND IT\'S GONE.*)/i
/WHAT IF I TOLD YOU (.*)/i
/(WHY THE (FUCK|FRIEND)) (.*)/i
/WTF (.*)/i
/(IF .*)(THAT'D BE GREAT)/i
/(MUCH .*) ((SO|VERY) .*)/i
/(.*)(EVERYWHERE.*)/i
]
"do it": [
/just do it/i
]
"trump": [
/trump/i
]
"cat": [
/cat me/i
/cat bomb( (\d+))?/i
/how many cats are there/i
]
"pug": [
/pug me/i
/pug bomb( (\d+))?/i
/how many pugs are there/i
]
"ship": [
/ship(ping|z|s|ped)?\s*it/i
/ship\s*it/i
]
"victory": [
/victory\b/i
]
"reply": [
/reply to (.+)/i
]
"flirt": [
/flirt with @?(.+)/i
]
"image": [
/(image|img)( me)? (.*)/i
/animate( me)? (.*)/i
/(?:mo?u)?sta(?:s|c)h(?:e|ify)?(?: me)? (.*)/i
]
"bot":
"reply": [
/PING$/i
/ADAPTER$/i
/ECHO (.*)$/i
/TIME$/i
/help\s*(.*)?$/i
]
"util":
"google": [
/(g|google) (.*)/i
/(?:youtube|yt)(?: me)?\s(.*)/i
]
"translate": [
/translate|say/i
]
"map": [
/((driving|walking|bike|biking|bicycling) )?directions from (.+) t(.+)/i
/(?:(satellite|terrain|hybrid)[- ])?map( me)? (.+)/i
]
"news": [
/hn (\d*)/i
]
"twitter": [
/twitter (\S+)\s*(.+)?/i
]
"where": [
/time( at)? ?(.+)?/i
/((?:(?!is).)*) is (in|at) (.*)/i
/I\'*\’*m (in|at) (.*)/i
/I am (in|at) (.*)/i
/where is (.+)/i
/where am I/i
/weather( at)? ?(.+)?/i
],
"remind": [
/reminder(s?)/i
/(rm|remove) reminder (\d+)/i
/remind ((?:(?!to).)*) to (.*)/i
],
"todo": [
/todo\s*((?:(?!add).)*) add (.*)/i
/todo\s*(.*)(show|list)/i
/todo\s*((?:(?!rm|remove).)*) (rm|remove)(.*)/i
/todo\s+(.*)clear/i
],
"lomath": [
/_\.(\w+)(.*)$/i
],
"alias": [
/I am(?! in| at) (.*)/i
/I\'*\’*m(?! in| at) (.*)/i
/My name is(?! in| at) (.*)/i
/who is (.*)/i
/who am I/i
/clear alias for (.*)/i
],
"sentiment": [
/sa\s*(\d*)\s*(.*)/i
],
"tradier": [
/td\s+((\w+\,\s*)*\w+)\s*(.*)/i
]
# given an alias, return the first name that contains the alias
findName = (robot, alias) ->
_.findKey robot.brain.data.aliases, (aliasArr) ->
_.includes aliasArr, alias.toLowerCase()
# The userId parser
# if 'me'/i, return 'me'
# else try alias
# else try fuzzy username
# else return undefined
userId = (robot, userName, msg) ->
try
userName = _.trim userName.replace(/\@/g, '')
if userName.toLowerCase() is 'me' or userName is ''
candidate = msg.message.user.name
else
candidate = findName(robot, userName) or robot.brain.usersForFuzzyName(userName)[0].name
return candidate
catch error
undefined
# the admins field, array of admin emails
admins = process.env.ADMINS.split(',')
# boolean function to see if msg is sent by admin
isAdmin = (msg) ->
email = msg.envelope.user.email_address
return _.includes admins, email
module.exports =
"typedCmd": typedCmd
"userId": userId
"isAdmin": isAdmin