Commit 45dcb7d7 authored by Jonathan Harker's avatar Jonathan Harker

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

parent a187045c
......@@ -10,18 +10,22 @@ Useful bot for folks stuck behind censor walls at work
Logs a channel and collects URLs for later.
"""
import sys, string, random, time
from ircbot import SingleServerIRCBot, OutputManager
from irclib import nm_to_n, nm_to_h, irc_lower
import os
from datetime import datetime
from mechanize import Browser
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
try:
import sys, string, random, time
from ircbot import SingleServerIRCBot, OutputManager
from irclib import nm_to_n, nm_to_h, irc_lower
import os
from datetime import datetime
from mechanize import Browser
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,27 +196,34 @@ class LolBot(SingleServerIRCBot):
return datetime.today().strftime("%Y-%m-%d %H:%M:%S")
def save_url(self, nickname, url):
db = self.get_session()
if not db.query(Url).filter(Url.url == url).count():
theurl = Url(nickname, url)
db.add(theurl)
db.commit()
else:
try:
theurl = db.query(Url).filter(Url.url == url).one()
except MultipleResultsFound, ex:
print ex #wtf
except NoResultsFound, ex:
print ex #wtf
print theurl
return theurl.title
try:
db = self.get_session()
if not db.query(Url).filter(Url.url == url).count():
theurl = Url(nickname, url)
db.add(theurl)
db.commit()
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
except Exception, ex:
print "Exception caught saving URL: %s" % ex
return ""
def log_event(self, nick, text):
entry = Log(nick, text)
db = self.get_session()
db.add(entry)
db.commit()
print entry
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,28 +290,33 @@ class LolBot(SingleServerIRCBot):
else:
target = from_private.strip()
if cmd == 'help':
self.reply(self.helptext, target)
elif cmd == 'lol':
self.reply(self.ponder(), target)
elif cmd == 'urls' or cmd == 'list':
db = self.get_session()
for url in db.query(Url).order_by(Url.timestamp):
line = "%s %s" % (url.url, url.title)
self.reply(line, target)
time.sleep(1)
elif cmd.startswith('http:') or cmd.startswith('https:'):
title = self.save_url(from_private, cmd)
if title == '':
self.reply('URL added.', target)
if title != '':
self.reply('URL added: %s' % title, target)
else:
self.reply(self.exclaim(), target)
try:
if cmd == 'help':
self.reply(self.helptext, target)
elif cmd == 'lol':
self.reply(self.ponder(), target)
elif cmd == 'urls' or cmd == 'list':
db = self.get_session()
for url in db.query(Url).order_by(Url.timestamp):
line = "%s %s" % (url.url, url.title)
self.reply(line, target)
time.sleep(1)
elif cmd.startswith('http:') or cmd.startswith('https:'):
title = self.save_url(from_private, cmd)
if title == '':
self.reply('URL added.', target)
if title != '':
self.reply('URL added: %s' % title, target)
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():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment