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.
"""
try:
import sys, string, random, time
from ircbot import SingleServerIRCBot, OutputManager
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.orm import sessionmaker
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 = [
@ -37,7 +41,6 @@ exclamations = [
ponderings = [
"Hi, can I have a medium lamb roast, with just potatoes.",
"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.",
"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")
def save_url(self, nickname, url):
try:
db = self.get_session()
if not db.query(Url).filter(Url.url == url).count():
theurl = Url(nickname, url)
@ -201,19 +205,25 @@ class LolBot(SingleServerIRCBot):
else:
try:
theurl = db.query(Url).filter(Url.url == url).one()
print theurl
return theurl.title
except MultipleResultsFound, ex:
print ex #wtf
except NoResultsFound, ex:
print ex #wtf
print theurl
return theurl.title
except Exception, ex:
print "Exception caught saving URL: %s" % ex
return ""
def log_event(self, nick, text):
try:
entry = Log(nick, text)
db = self.get_session()
db.add(entry)
db.commit()
print entry
except Exception, ex:
print "Exception caught logging event: %s" % ex
def on_nicknameinuse(self, connection, event):
self.nickname = connection.get_nickname() + "_"
@ -280,6 +290,7 @@ class LolBot(SingleServerIRCBot):
else:
target = from_private.strip()
try:
if cmd == 'help':
self.reply(self.helptext, target)
@ -303,6 +314,10 @@ class LolBot(SingleServerIRCBot):
else:
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():
print """Run a lolbot.