Explorar el Código

Some refactoring.

tags/v0.1^2
Ben Kurtovic hace 12 años
padre
commit
d30d984f05
Se han modificado 3 ficheros con 11 adiciones y 12 borrados
  1. +11
    -1
      earwigbot/irc/connection.py
  2. +0
    -5
      earwigbot/irc/frontend.py
  3. +0
    -6
      earwigbot/irc/watcher.py

+ 11
- 1
earwigbot/irc/connection.py Ver fichero

@@ -89,6 +89,12 @@ class IRCConnection(object):
else:
self._send("QUIT")

def _process_defaults(self, line):
"""Default process hooks for lines received on IRC."""
self._last_recv = time()
if line[0] == "PING": # If we are pinged, pong back
self.pong(line[1])

@property
def host(self):
"""The hostname of the IRC server, like ``"irc.freenode.net"``."""
@@ -175,10 +181,11 @@ class IRCConnection(object):
self._is_running = False
break

self._last_recv = time()
lines = read_buffer.split("\n")
read_buffer = lines.pop()
for line in lines:
line = line.strip().split()
self._process_defaults(line)
self._process_message(line)
if self.is_stopped():
break
@@ -190,9 +197,12 @@ class IRCConnection(object):
now = time()
if now - self._last_recv > 60:
if self._last_ping < self._last_recv:
log = "Last message was received over 60 seconds ago. Pinging."
self.logger.debug(log)
self.ping(self.host)
self._last_ping = now
elif now - self._last_ping > 60:
self.logger.debug("No ping response in 60 seconds. Stopping.")
self.stop()

def stop(self, msg=None):


+ 0
- 5
earwigbot/irc/frontend.py Ver fichero

@@ -49,8 +49,6 @@ class Frontend(IRCConnection):

def _process_message(self, line):
"""Process a single message from IRC."""
line = line.strip().split()

if line[1] == "JOIN":
data = Data(self.bot, self.nick, line, msgtype="JOIN")
self.bot.commands.call("join", data)
@@ -63,9 +61,6 @@ class Frontend(IRCConnection):
self.bot.commands.call("msg_public", data)
self.bot.commands.call("msg", data)

elif line[0] == "PING": # If we are pinged, pong back
self.pong(line[1])

elif line[1] == "376": # On successful connection to the server
# If we're supposed to auth to NickServ, do that:
try:


+ 0
- 6
earwigbot/irc/watcher.py Ver fichero

@@ -50,8 +50,6 @@ class Watcher(IRCConnection):

def _process_message(self, line):
"""Process a single message from IRC."""
line = line.strip().split()

if line[1] == "PRIVMSG":
chan = line[2]

@@ -65,10 +63,6 @@ class Watcher(IRCConnection):
rc.parse() # Parse a message into pagenames, usernames, etc.
self._process_rc_event(rc)

# If we are pinged, pong back:
elif line[0] == "PING":
self.pong(line[1])

# When we've finished starting up, join all watcher channels:
elif line[1] == "376":
for chan in self.bot.config.irc["watcher"]["channels"]:


Cargando…
Cancelar
Guardar