|
7 | 7 |
|
8 | 8 | from cloudbot.client import Client |
9 | 9 | from cloudbot.event import Event, EventType, IrcOutEvent |
10 | | -from cloudbot.util.parsers.irc import Message |
| 10 | +from cloudbot.util import async_util |
11 | 11 |
|
12 | 12 | logger = logging.getLogger("cloudbot") |
13 | 13 |
|
|
19 | 19 | irc_bad_chars = ''.join([chr(x) for x in list(range(0, 1)) + list(range(4, 32)) + list(range(127, 160))]) |
20 | 20 | irc_clean_re = re.compile('[{}]'.format(re.escape(irc_bad_chars))) |
21 | 21 |
|
| 22 | + |
22 | 23 | def irc_clean(dirty): |
23 | | - return irc_clean_re.sub('',dirty) |
| 24 | + return irc_clean_re.sub('', dirty) |
| 25 | + |
24 | 26 |
|
25 | 27 | irc_command_to_event_type = { |
26 | 28 | "PRIVMSG": EventType.message, |
@@ -219,8 +221,7 @@ def _send(self, line): |
219 | 221 | :type line: str |
220 | 222 | """ |
221 | 223 | logger.info("[{}] >> {}".format(self.name, line)) |
222 | | - asyncio.async(self._protocol.send(line), loop=self.loop) |
223 | | - |
| 224 | + async_util.wrap_future(self._protocol.send(line), loop=self.loop) |
224 | 225 |
|
225 | 226 | @property |
226 | 227 | def connected(self): |
@@ -273,14 +274,14 @@ def connection_lost(self, exc): |
273 | 274 | # we've been closed intentionally, so don't reconnect |
274 | 275 | return |
275 | 276 | logger.error("[{}] Connection lost: {}".format(self.conn.name, exc)) |
276 | | - asyncio.async(self.conn.connect(), loop=self.loop) |
| 277 | + async_util.wrap_future(self.conn.connect(), loop=self.loop) |
277 | 278 |
|
278 | 279 | def eof_received(self): |
279 | 280 | self._connected = False |
280 | 281 | # create a new connected_future for when we are connected. |
281 | 282 | self._connected_future = asyncio.Future(loop=self.loop) |
282 | 283 | logger.info("[{}] EOF received.".format(self.conn.name)) |
283 | | - asyncio.async(self.conn.connect(), loop=self.loop) |
| 284 | + async_util.wrap_future(self.conn.connect(), loop=self.loop) |
284 | 285 | return True |
285 | 286 |
|
286 | 287 | @asyncio.coroutine |
@@ -370,7 +371,7 @@ def data_received(self, data): |
370 | 371 | # Reply to pings immediately |
371 | 372 |
|
372 | 373 | if command == "PING": |
373 | | - asyncio.async(self.send("PONG " + command_params[-1]), loop=self.loop) |
| 374 | + async_util.wrap_future(self.send("PONG " + command_params[-1]), loop=self.loop) |
374 | 375 |
|
375 | 376 | # Parse the command and params |
376 | 377 |
|
@@ -437,13 +438,4 @@ def data_received(self, data): |
437 | 438 | irc_prefix=prefix, irc_command=command, irc_paramlist=command_params, irc_ctcp_text=ctcp_text) |
438 | 439 |
|
439 | 440 | # handle the message, async |
440 | | - asyncio.async(self.bot.process(event), loop=self.loop) |
441 | | - |
442 | | -# Channel Commands |
443 | | -# NOTICE #chan :Text |
444 | | -# PRIVMSG #chan :Text |
445 | | -# KICK #chan nick :reason |
446 | | -# JOIN #chan |
447 | | -# PART #chan :reason |
448 | | -# MODE #chan +<modes> |
449 | | -# INVITE nick :#chan |
| 441 | + async_util.wrap_future(self.bot.process(event), loop=self.loop) |
0 commit comments