49 if argname == '': |
51 if argname == '': |
50 continue |
52 continue |
51 |
53 |
52 cmd['argnames'].append (argname) |
54 cmd['argnames'].append (argname) |
53 |
55 |
|
56 if 'hooks' in module.ModuleData: |
|
57 for key, hooks in module.ModuleData['hooks'].iteritems(): |
|
58 for hook in hooks: |
|
59 if key not in Hooks: |
|
60 Hooks[key] = [] |
|
61 |
|
62 Hooks[key].append ({'name': hook, 'func': getattr (module, hook)}) |
|
63 numHooks += 1 |
|
64 |
54 print "Loaded module %s" % fn |
65 print "Loaded module %s" % fn |
55 |
66 |
56 print 'Loaded %d commands in %d modules' % (len (Commands), len (Modules)) |
67 print ('Loaded %d commands and %d hooks in %d modules' % |
|
68 (len (Commands), numHooks, len (Modules))) |
57 |
69 |
58 # |
70 # |
59 # command_error (message) |
71 # command_error (message) |
60 # |
72 # |
61 # Raises a command error |
73 # Raises a command error |
176 |
188 |
177 match = re.compile (cmd['regex']).match (message) |
189 match = re.compile (cmd['regex']).match (message) |
178 |
190 |
179 if match == None: |
191 if match == None: |
180 # didn't match |
192 # didn't match |
181 print "regex: %s" % cmd['regex'] |
|
182 command_error ('invalid arguments\nusage: %s %s' % (cmd['name'], cmd['args'])) |
193 command_error ('invalid arguments\nusage: %s %s' % (cmd['name'], cmd['args'])) |
183 |
194 |
184 # .more is special as it is an interface to the page system. |
195 # .more is special as it is an interface to the page system. |
185 # Anything else resets it. |
196 # Anything else resets it. |
186 if cmdname != 'more': |
197 if cmdname != 'more': |
203 commandObject['confirm'] = confirm_function |
214 commandObject['confirm'] = confirm_function |
204 commandObject['confirmed'] = 0 |
215 commandObject['confirmed'] = 0 |
205 commandObject['commandObject'] = commandObject |
216 commandObject['commandObject'] = commandObject |
206 commandObject['info'] = cmd |
217 commandObject['info'] = cmd |
207 commandObject['module'] = cmd['module'] |
218 commandObject['module'] = cmd['module'] |
|
219 commandObject['error'] = command_error |
208 exec_command (commandObject) |
220 exec_command (commandObject) |
209 |
221 |
210 # Print the first page of responses. |
222 # Print the first page of responses. |
211 if cmdname != 'more': |
223 if cmdname != 'more': |
212 print_responses (commandObject) |
224 print_responses (commandObject) |
|
225 |
|
226 def call_hook (bot, hookname, **kvargs): |
|
227 global g_responsePages |
|
228 global g_responsePageNum |
|
229 hookObject = kvargs |
|
230 hookObject['bot'] = bot |
|
231 g_responsePages = [[]] |
|
232 g_responsePageNum = 0 |
|
233 |
|
234 if 'replyto' in hookObject: |
|
235 hookObject['reply'] = response_function |
|
236 |
|
237 if hookname in Hooks: |
|
238 for hook in Hooks[hookname]: |
|
239 hook['func'] (**hookObject) |
|
240 |
|
241 print_responses (hookObject) |
213 |
242 |
214 def confirm (cmd, yes): |
243 def confirm (cmd, yes): |
215 global g_confirmCommand |
244 global g_confirmCommand |
216 |
245 |
217 if g_confirmCommand == None: |
246 if g_confirmCommand == None: |