more db work!

This commit is contained in:
Luke Rogers 2014-02-15 19:17:53 +13:00
parent 99487b66c6
commit 91b6d1d8f1
3 changed files with 12 additions and 7 deletions

View file

@ -128,12 +128,12 @@ class Bot(threading.Thread):
if conf['connection'].get('ssl'):
self.connections.append(irc.SSLIRC(name, server, nick, config=conf,
port=port, channels=conf['channels'],
port=port, logger=self.logger, channels=conf['channels'],
ignore_certificate_errors=conf['connection'].get('ignore_cert', True)))
self.logger.debug("({}) Created SSL connection.".format(name))
else:
self.connections.append(irc.IRC(name, server, nick, config=conf,
port=port, channels=conf['channels']))
port=port, logger=self.logger, channels=conf['channels']))
self.logger.debug("({}) Created connection.".format(name))
def stop(self, reason=None):

View file

@ -106,7 +106,6 @@ class SendThread(threading.Thread):
def run(self):
while not self.shutdown:
line = self.output_queue.get().splitlines()[0][:500]
print u"{}> {}".format(self.conn_name, line)
self.output_buffer += line.encode('utf-8', 'replace') + '\r\n'
while self.output_buffer:
sent = self.socket.send(self.output_buffer)
@ -205,12 +204,13 @@ class SSLIRCConnection(IRCConnection):
class IRC(object):
"""handles the IRC protocol"""
def __init__(self, name, server, nick, port=6667, channels=[], config={}):
def __init__(self, name, server, nick, port=6667, logger=None, channels=[], config={}):
self.name = name
self.channels = channels
self.config = config
self.server = server
self.port = port
self.logger = logger
self.nick = nick
self.vars = {}
@ -280,14 +280,19 @@ class IRC(object):
self.send(command)
def send(self, string):
try:
self.logger.info(u"{} >> {}".format(self.name.upper(), string))
except:
# if this doesn't work, no big deal
pass
self.output_queue.put(string)
class SSLIRC(IRC):
def __init__(self, name, server, nick, port=6667, channels=[], config={},
def __init__(self, name, server, nick, port=6667, logger=None, channels=[], config={},
ignore_certificate_errors=True):
self.ignore_cert_errors = ignore_certificate_errors
IRC.__init__(self, name, server, nick, port, channels, config)
IRC.__init__(self, name, server, nick, port, logger, channels, config)
def create_connection(self):
return SSLIRCConnection(self.name, self.server, self.port, self.input_queue,

View file

@ -49,7 +49,7 @@ def horoscope(inp, db=None, notice=None, nick=None):
return "Could not get the horoscope for {}.".format(inp)
if inp and not dontsave:
db.execute("insert or replace into horoscope(nick, sign) values (:nick,:sign)",
db.execute("insert or replace into horoscope(nick, sign) values (:nick,:signS)",
{'nick':nick.lower(), 'sign': sign})
db.commit()