-
Notifications
You must be signed in to change notification settings - Fork 2
/
lighthouse.py
188 lines (140 loc) · 4.69 KB
/
lighthouse.py
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
#!/usr/bin/env python
# Copyright (C) 2011 Michael Ranieri <michael.d.ranieri at gmail.com>
# input to methods will be a tuple (Message from irc, user who sent msg, channel, known channel users)
# Must return a location or None
# The first string is the relative location of the isle from the settings.PATH_TO_ISLE
# return None when you don't want the Isle to be called
# NOTE: some messages beginning with {nickname}: are reserved for internal functions
# Try to avoid using {nickname}: so you don't have any name conflicts with internal functions
# System imports
import re
# Misty imports
import settings_local as settings
# Core Isles
# Grabs wiki page
def wikipedia(params):
"""'.wik' & term | Searches wikipedia for term"""
msg, user, channel, users = params
if msg.startswith('.wik'):
return "core/wikipedia.py"
else:
return None
# Calculates user input
def calculate(params):
"""'.c' || Calculates any argument after '.c'"""
msg, user, channel, users = params
if msg.startswith('.c'):
return "core/calculate.py"
else:
return None
# Searches google and returns top hit
def search(params):
"""'.g' or '.gc' or '.gcs' || Searches google with any argument after command."""
msg, user, channel, users = params
if msg.startswith('.g') \
or msg.startswith('.gc') \
or msg.startswith('.gcs'):
return "core/search.py"
else:
return None
# Report last time Misty saw a user
def seen(params):
"""'.seen' & user || Report last time Misty saw a user."""
msg, user, channel, users = params
if msg.startswith('.seen'):
return "core/seen.py"
else:
return None
# Stores a message to send to another user
def store_tell(params):
"""'offline_user: message' || Stores a message to give to offline user."""
msg, user, channel, users = params
if re.match('([\w-]+): .+', msg):
return "core/store_tell.py"
else:
return None
# Gives message to user on first message from receiver
def send_tell(params):
return "core/send_tell.py"
# Shows all outbound messages from user
def outbox(params):
"""'.outbox' (-c or --clear) || Shows outbound messages that have yet to be received"""
msg, user, channel, user = params
if msg.startswith('.outbox'):
return "core/outbox.py"
else:
return None
# API Isles (Require an api key from respective companies)
# Checks for bugs on Lighthouse Issue Tracking
def lighthouse(params):
""".lighthouse* or .bug* || Return the Lighthouse Tracker URL of the best match."""
msg, user, channel, users = params
if (msg.startswith('.bug') \
or msg.startswith('.lighthouse')) \
and settings.LIGHTHOUSE_KEY:
return "api/lighthouseTracking.py"
else:
return None
# Checks Pingdom status of servers.
def pingdom(params):
""".pingdom || Returns the status of Pingdom checks."""
msg, user, channel, users = params
if msg.startswith('.pingdom') and settings.PINGDOM_KEY:
return "api/pingdom.py"
else:
return None
# Searches rackspace for msg terms and returns more information about server
def rackspace(params):
""".rackspace & (*ip* or *name*) || Return information about rackspace server."""
msg, user, channel, users = params
if msg.startswith('.rackspace') and settings.RACKSPACE_KEY:
return "api/rackspace.py"
else:
return None
# Searches Pivotal Tracker project for stories in msg and return a url to it
def pivotalTracker(params):
""".pivotal *terms* || Return the Pivotal Tracker URL of the best match story."""
msg, user, channel, users = params
if msg.startswith('.pivotal') and settings.PIVOTAL_KEY:
return "api/pivotalTracker.py"
else:
return None
# Example Isles
# Responds when someone says misty
def mistyComment(params):
msg, user, channel, users = params
if re.search('misty', msg, re.IGNORECASE):
return "examples/mistyComment.py"
else:
return None
# Echo a message 10 seconds later
def subprocess(params):
msg, user, channel, users = params
if re.search('example', msg, re.IGNORECASE):
return "examples/subprocess.py"
else:
return None
# Echo the json parameters that would be sent to an Isle
def json_arg(params):
msg, user, channel, users = params
if re.search('example', msg, re.IGNORECASE):
return "examples/json_arg.py"
else:
return None
# Make sure to add your Isle method to isles[]
isles = [
wikipedia,
calculate,
search,
seen,
store_tell,
send_tell,
outbox,
lighthouse,
pingdom,
rackspace,
pivotalTracker,
#mistyComment,
#subprocess,
#json_arg,
]