For now, catch all the UTF-8 exceptions until I can fix it properly.

This commit is contained in:
Jonathan Harker 2010-10-20 14:01:18 +01:00
parent a187045c0c
commit 45dcb7d7f3

View file

@ -10,6 +10,7 @@ Useful bot for folks stuck behind censor walls at work
Logs a channel and collects URLs for later. Logs a channel and collects URLs for later.
""" """
try:
import sys, string, random, time import sys, string, random, time
from ircbot import SingleServerIRCBot, OutputManager from ircbot import SingleServerIRCBot, OutputManager
from irclib import nm_to_n, nm_to_h, irc_lower from irclib import nm_to_n, nm_to_h, irc_lower
@ -22,6 +23,9 @@ import getopt
from sqlalchemy import MetaData, Table, Column, String, Text, Integer, DateTime, engine_from_config from sqlalchemy import MetaData, Table, Column, String, Text, Integer, DateTime, engine_from_config
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
except ImportError:
print "Some modules could not be loaded: Lolbot relies on Mechanize and SQLAlchemy.\n"
sys.exit
# Exclamations - wrong input # Exclamations - wrong input
exclamations = [ exclamations = [
@ -37,7 +41,6 @@ exclamations = [
ponderings = [ ponderings = [
"Hi, can I have a medium lamb roast, with just potatoes.", "Hi, can I have a medium lamb roast, with just potatoes.",
"Can I slurp on your Big Cock?", "Can I slurp on your Big Cock?",
"Your Mum likes it two in the pink one in the stink.",
"Quentin Tarantino is so awesome I want to have his babies.", "Quentin Tarantino is so awesome I want to have his babies.",
"No it's a week night 8pm is past my bedtime.", "No it's a week night 8pm is past my bedtime.",
] ]
@ -193,6 +196,7 @@ class LolBot(SingleServerIRCBot):
return datetime.today().strftime("%Y-%m-%d %H:%M:%S") return datetime.today().strftime("%Y-%m-%d %H:%M:%S")
def save_url(self, nickname, url): def save_url(self, nickname, url):
try:
db = self.get_session() db = self.get_session()
if not db.query(Url).filter(Url.url == url).count(): if not db.query(Url).filter(Url.url == url).count():
theurl = Url(nickname, url) theurl = Url(nickname, url)
@ -201,19 +205,25 @@ class LolBot(SingleServerIRCBot):
else: else:
try: try:
theurl = db.query(Url).filter(Url.url == url).one() theurl = db.query(Url).filter(Url.url == url).one()
print theurl
return theurl.title
except MultipleResultsFound, ex: except MultipleResultsFound, ex:
print ex #wtf print ex #wtf
except NoResultsFound, ex: except NoResultsFound, ex:
print ex #wtf print ex #wtf
print theurl except Exception, ex:
return theurl.title print "Exception caught saving URL: %s" % ex
return ""
def log_event(self, nick, text): def log_event(self, nick, text):
try:
entry = Log(nick, text) entry = Log(nick, text)
db = self.get_session() db = self.get_session()
db.add(entry) db.add(entry)
db.commit() db.commit()
print entry print entry
except Exception, ex:
print "Exception caught logging event: %s" % ex
def on_nicknameinuse(self, connection, event): def on_nicknameinuse(self, connection, event):
self.nickname = connection.get_nickname() + "_" self.nickname = connection.get_nickname() + "_"
@ -280,6 +290,7 @@ class LolBot(SingleServerIRCBot):
else: else:
target = from_private.strip() target = from_private.strip()
try:
if cmd == 'help': if cmd == 'help':
self.reply(self.helptext, target) self.reply(self.helptext, target)
@ -303,6 +314,10 @@ class LolBot(SingleServerIRCBot):
else: else:
self.reply(self.exclaim(), target) self.reply(self.exclaim(), target)
except Exception, ex:
print "Exception caught processing command: %s" % ex
print " command was '%s' from %s" % (cmd, target)
def usage(): def usage():
print """Run a lolbot. print """Run a lolbot.