Skip to content

Commit e695f11

Browse files
committed
Merge remote-tracking branch 'origin/python3.4' into python3.4
2 parents e2a58bd + cb3e1d9 commit e695f11

9 files changed

Lines changed: 71 additions & 75 deletions

File tree

cloudbot/bot.py

Lines changed: 63 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -195,72 +195,68 @@ def process(self, event):
195195
"""
196196
:type event: Event
197197
"""
198-
try:
199-
run_before_tasks = []
200-
tasks = []
201-
command_prefix = event.conn.config.get('command_prefix', '.')
202-
203-
# Raw IRC hook
204-
for raw_hook in self.plugin_manager.catch_all_triggers:
205-
# run catch-all coroutine hooks before all others - TODO: Make this a plugin argument
206-
if not raw_hook.threaded:
207-
run_before_tasks.append(
208-
self.plugin_manager.launch(raw_hook, Event(hook=raw_hook, base_event=event)))
198+
run_before_tasks = []
199+
tasks = []
200+
command_prefix = event.conn.config.get('command_prefix', '.')
201+
202+
# Raw IRC hook
203+
for raw_hook in self.plugin_manager.catch_all_triggers:
204+
# run catch-all coroutine hooks before all others - TODO: Make this a plugin argument
205+
if not raw_hook.threaded:
206+
run_before_tasks.append(
207+
self.plugin_manager.launch(raw_hook, Event(hook=raw_hook, base_event=event)))
208+
else:
209+
tasks.append(self.plugin_manager.launch(raw_hook, Event(hook=raw_hook, base_event=event)))
210+
if event.irc_command in self.plugin_manager.raw_triggers:
211+
for raw_hook in self.plugin_manager.raw_triggers[event.irc_command]:
212+
tasks.append(self.plugin_manager.launch(raw_hook, Event(hook=raw_hook, base_event=event)))
213+
214+
# Event hooks
215+
if event.type in self.plugin_manager.event_type_hooks:
216+
for event_hook in self.plugin_manager.event_type_hooks[event.type]:
217+
tasks.append(self.plugin_manager.launch(event_hook, Event(hook=event_hook, base_event=event)))
218+
219+
if event.type is EventType.message:
220+
# Commands
221+
if event.chan.lower() == event.nick.lower(): # private message, no command prefix
222+
command_re = r'(?i)^(?:[{}]?|{}[,;:]+\s+)(\w+)(?:$|\s+)(.*)'.format(command_prefix, event.conn.nick)
223+
else:
224+
command_re = r'(?i)^(?:[{}]|{}[,;:]+\s+)(\w+)(?:$|\s+)(.*)'.format(command_prefix, event.conn.nick)
225+
226+
cmd_match = re.match(command_re, event.content)
227+
228+
if cmd_match:
229+
command = cmd_match.group(1).lower()
230+
if command in self.plugin_manager.commands:
231+
command_hook = self.plugin_manager.commands[command]
232+
command_event = CommandEvent(hook=command_hook, text=cmd_match.group(2).strip(),
233+
triggered_command=command, base_event=event)
234+
tasks.append(self.plugin_manager.launch(command_hook, command_event))
209235
else:
210-
tasks.append(self.plugin_manager.launch(raw_hook, Event(hook=raw_hook, base_event=event)))
211-
if event.irc_command in self.plugin_manager.raw_triggers:
212-
for raw_hook in self.plugin_manager.raw_triggers[event.irc_command]:
213-
tasks.append(self.plugin_manager.launch(raw_hook, Event(hook=raw_hook, base_event=event)))
214-
215-
# Event hooks
216-
if event.type in self.plugin_manager.event_type_hooks:
217-
for event_hook in self.plugin_manager.event_type_hooks[event.type]:
218-
tasks.append(self.plugin_manager.launch(event_hook, Event(hook=event_hook, base_event=event)))
219-
220-
if event.type is EventType.message:
221-
# Commands
222-
if event.chan.lower() == event.nick.lower(): # private message, no command prefix
223-
command_re = r'(?i)^(?:[{}]?|{}[,;:]+\s+)(\w+)(?:$|\s+)(.*)'.format(command_prefix, event.conn.nick)
236+
potential_matches = []
237+
for potential_match, plugin in self.plugin_manager.commands.items():
238+
if potential_match.startswith(command):
239+
potential_matches.append((potential_match, plugin))
240+
if potential_matches:
241+
if len(potential_matches) == 1:
242+
command_hook = potential_matches[0][1]
243+
command_event = CommandEvent(hook=command_hook, text=cmd_match.group(2).strip(),
244+
triggered_command=command, base_event=event)
245+
tasks.append(self.plugin_manager.launch(command_hook, command_event))
246+
else:
247+
event.notice("Possible matches: {}".format(
248+
formatting.get_text_list([command for command, plugin in potential_matches])))
249+
250+
# Regex hooks
251+
for regex, regex_hook in self.plugin_manager.regex_hooks:
252+
if not regex_hook.run_on_cmd and cmd_match:
253+
pass
224254
else:
225-
command_re = r'(?i)^(?:[{}]|{}[,;:]+\s+)(\w+)(?:$|\s+)(.*)'.format(command_prefix, event.conn.nick)
226-
227-
cmd_match = re.match(command_re, event.content)
228-
229-
if cmd_match:
230-
command = cmd_match.group(1).lower()
231-
if command in self.plugin_manager.commands:
232-
command_hook = self.plugin_manager.commands[command]
233-
command_event = CommandEvent(hook=command_hook, text=cmd_match.group(2).strip(),
234-
triggered_command=command, base_event=event)
235-
tasks.append(self.plugin_manager.launch(command_hook, command_event))
236-
else:
237-
potential_matches = []
238-
for potential_match, plugin in self.plugin_manager.commands.items():
239-
if potential_match.startswith(command):
240-
potential_matches.append((potential_match, plugin))
241-
if potential_matches:
242-
if len(potential_matches) == 1:
243-
command_hook = potential_matches[0][1]
244-
command_event = CommandEvent(hook=command_hook, text=cmd_match.group(2).strip(),
245-
triggered_command=command, base_event=event)
246-
tasks.append(self.plugin_manager.launch(command_hook, command_event))
247-
else:
248-
event.notice("Possible matches: {}".format(
249-
formatting.get_text_list([command for command, plugin in potential_matches])))
250-
251-
# Regex hooks
252-
for regex, regex_hook in self.plugin_manager.regex_hooks:
253-
if not regex_hook.run_on_cmd and cmd_match:
254-
pass
255-
else:
256-
regex_match = regex.search(event.content)
257-
if regex_match:
258-
regex_event = RegexEvent(hook=regex_hook, match=regex_match, base_event=event)
259-
tasks.append(self.plugin_manager.launch(regex_hook, regex_event))
260-
261-
# Run the tasks
262-
yield from asyncio.gather(*run_before_tasks, loop=self.loop)
263-
yield from asyncio.gather(*tasks, loop=self.loop)
264-
265-
except:
266-
logger.exception("Error while processing event")
255+
regex_match = regex.search(event.content)
256+
if regex_match:
257+
regex_event = RegexEvent(hook=regex_hook, match=regex_match, base_event=event)
258+
tasks.append(self.plugin_manager.launch(regex_hook, regex_event))
259+
260+
# Run the tasks
261+
yield from asyncio.gather(*run_before_tasks, loop=self.loop)
262+
yield from asyncio.gather(*tasks, loop=self.loop)

cloudbot/hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,4 @@ def _on_start_hook(func):
298298

299299

300300
# this is temporary, to ease transition
301-
onload = on_start
301+
onload = on_start

cloudbot/util/dictionaries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def __getitem__(self, k): # real signature unknown; restored from __doc__
4040

4141
def __setitem__(self, k, v): # real signature unknown
4242
""" Set self[key] to value. """
43-
return super().__setitem__(k.lower() if k is not None else k, v)
43+
return super().__setitem__(k.lower() if k is not None else k, v)

cloudbot/util/test/test_timeformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def test_timeuntil():
3535
# basic
3636
assert timeuntil(future, now) == "1 month and 2 days"
3737
# count
38-
assert timeuntil(future, now, count=3) == "1 month, 2 days and 13 hours"
38+
assert timeuntil(future, now, count=3) == "1 month, 2 days and 13 hours"

cloudbot/util/timeformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ def format_time(seconds, count=3, accuracy=6, simple=False):
125125
if simple:
126126
return " ".join(strings)
127127
else:
128-
return formatting.get_text_list(strings, "and")
128+
return formatting.get_text_list(strings, "and")

plugins/core_tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ def on_join(conn, chan, target):
9090
:type nick: str
9191
"""
9292
if target == conn.nick:
93-
bot_joined_channel(conn, chan)
93+
bot_joined_channel(conn, chan)

plugins/ignore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ def global_unignore(text, db, conn, notice):
144144
notice("{} is not globally ignored.".format(target))
145145
else:
146146
notice("{} has been globally un-ignored.".format(target))
147-
remove_ignore(db, conn.name, "*", target)
147+
remove_ignore(db, conn.name, "*", target)

plugins/lastfm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ def lastfmcompare(text, bot):
125125
artist_string = "\x02In Common:\x02 " + ", ".join(artists) if artists else ""
126126

127127
return "Musical compatibility between \x02{}\x02 and \x02{}\x02: {} (\x02{}%\x02)".format(user1, user2, level,
128-
score), artist_string
128+
score), artist_string

plugins/twitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ def twuser(text):
174174

175175
return "{}@\x02{}\x02 ({}){} has \x02{:,}\x02 tweets and \x02{:,}\x02 followers.{}" \
176176
"".format(prefix, user.screen_name, user.name, loc_str, user.statuses_count, user.followers_count,
177-
desc_str)
177+
desc_str)

0 commit comments

Comments
 (0)