Browse Source

Some refactoring.

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
d30d984f05
3 changed files with 11 additions and 12 deletions
  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 View File

@@ -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 View File

@@ -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 View File

@@ -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"]:


Loading…
Cancel
Save