pep8 compliance

This commit is contained in:
Ryan Hitchman 2009-07-08 11:28:15 -06:00
parent 40be3038ab
commit 3cdf0d2c83
10 changed files with 61 additions and 48 deletions

View File

@ -15,7 +15,7 @@ rbot http://linuxbrit.co.uk/rbot/
pyirc http://www.k-pdt.net/pyirc/ pyirc http://www.k-pdt.net/pyirc/
- very simple, not multithreaded - very simple, not multithreaded
- poor use of regexes, skybot has much better parsing, but it implements many more irc control godes - poor use of regexes, skybot has much better parsing, but it implements many more irc control codes
- can convert irc colors to vt100 escape codes -- should implement this - can convert irc colors to vt100 escape codes -- should implement this
- autoreconnect - autoreconnect

View File

@ -6,7 +6,6 @@ from util import hook, yaml
########### from http://effbot.org/zone/re-sub.htm#unescape-html ############# ########### from http://effbot.org/zone/re-sub.htm#unescape-html #############
def unescape(text): def unescape(text):
def fixup(m): def fixup(m):

View File

@ -26,6 +26,7 @@ def gis(inp):
return 'no images found' return 'no images found'
return parsed['responseData']['results'][0]['unescapedUrl'] return parsed['responseData']['results'][0]['unescapedUrl']
@hook.command @hook.command
@hook.command('g') @hook.command('g')
@hook.command('goog') @hook.command('goog')

View File

@ -23,7 +23,7 @@ formats = {'PRIVMSG': '<%(nick)s> %(msg)s',
'KICK': '-!- %(param1)s was kicked from %(chan)s by %(nick)s [%(msg)s]', 'KICK': '-!- %(param1)s was kicked from %(chan)s by %(nick)s [%(msg)s]',
'TOPIC': '-!- %(nick)s changed the topic of %(chan)s to: %(msg)s', 'TOPIC': '-!- %(nick)s changed the topic of %(chan)s to: %(msg)s',
'QUIT': '-!- %(nick)s has quit [%(msg)s]' 'QUIT': '-!- %(nick)s has quit [%(msg)s]'
} }
ctcp_formats = {'ACTION': '* %(nick)s %(ctcpmsg)s'} ctcp_formats = {'ACTION': '* %(nick)s %(ctcpmsg)s'}

View File

@ -1,29 +1,35 @@
" seen.py: written by sklnd in about two beers July 2009" " seen.py: written by sklnd in about two beers July 2009"
import sqlite3
import datetime, time
import os import os
import time
import datetime
import sqlite3
from util import hook, timesince from util import hook, timesince
dbname = "seen.db" dbname = "seen.db"
def adapt_datetime(ts): def adapt_datetime(ts):
return time.mktime(ts.timetuple()) return time.mktime(ts.timetuple())
sqlite3.register_adapter(datetime.datetime, adapt_datetime) sqlite3.register_adapter(datetime.datetime, adapt_datetime)
@hook.command(hook=r'(.*)', prefix=False, ignorebots=False) @hook.command(hook=r'(.*)', prefix=False, ignorebots=False)
def seeninput(bot,input): def seeninput(bot, input):
dbpath = os.path.join(bot.persist_dir, dbname) dbpath = os.path.join(bot.persist_dir, dbname)
conn = dbconnect(dbpath) conn = dbconnect(dbpath)
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("insert or replace into seen(name, date, quote, chan) values(?,?,?,?)" cursor.execute("insert or replace into seen(name, date, quote, chan)"
command, (input.nick, datetime.datetime.now(), input.msg, input.chan)) "values(?,?,?,?)", command, (input.nick, datetime.datetime.now(),
input.msg, input.chan))
conn.commit() conn.commit()
conn.close() conn.close()
@hook.command @hook.command
def seen(bot, input): def seen(bot, input):
".seen <nick> - Tell when a nickname was last in active in irc" ".seen <nick> - Tell when a nickname was last in active in irc"
@ -48,23 +54,23 @@ def seen(bot, input):
if(results != None): if(results != None):
reltime = timesince(datetime.datetime.fromtimestamp(results[0])) reltime = timesince(datetime.datetime.fromtimestamp(results[0]))
return '%(name)s was last seen %(timespan)s ago saying: <%(name)s> %(quote)s' % \ return '%s was last seen %s ago saying: <%s> %s' % \
{'name': query, 'timespan': reltime, 'quote': results[1]} (query, reltime, results[1])
else: else:
return "I've never seen %(name)s" % {'name':query} return "I've never seen %s" % query
# check to see that our db has the the seen table, and return a connection.
def dbconnect(db): def dbconnect(db):
"check to see that our db has the the seen table and return a connection."
conn = sqlite3.connect(db) conn = sqlite3.connect(db)
results = conn.execute("select count(*) from sqlite_master where name=?", ("seen",)).fetchone() results = conn.execute("select count(*) from sqlite_master where name=?",
("seen", )).fetchone()
if(results[0] == 0): if(results[0] == 0):
conn.execute("create table if not exists "+ \ conn.execute("create table if not exists "
"seen(name varchar(30) not null, date datetime not null, "+ \ "seen(name varchar(30) not null, date datetime not null, "
"quote varchar(250) not null, chan varchar(32) not null, "+ \ "quote varchar(250) not null, chan varchar(32) not null, "
"primary key(name, chan));") "primary key(name, chan));")
conn.commit() conn.commit()
return conn return conn

View File

@ -10,41 +10,42 @@ from util import hook, timesince
dbname = "skydb" dbname = "skydb"
def adapt_datetime(ts): def adapt_datetime(ts):
return time.mktime(ts.timetuple()) return time.mktime(ts.timetuple())
sqlite3.register_adapter(datetime.datetime, adapt_datetime) sqlite3.register_adapter(datetime.datetime, adapt_datetime)
@hook.command(hook=r'(.*)', prefix=False, ignorebots=True) @hook.command(hook=r'(.*)', prefix=False, ignorebots=True)
def tellinput(bot,input): def tellinput(bot, input):
dbpath = os.path.join(bot.persist_dir, dbname) dbpath = os.path.join(bot.persist_dir, dbname)
conn = dbconnect(dbpath) conn = dbconnect(dbpath)
cursor = conn.cursor() cursor = conn.cursor()
command = "select count(name) from tell where name = ? and chan = ?" command = "select count(name) from tell where name = ? and chan = ?"
results = cursor.execute(command, (input.nick,input.chan)).fetchone() results = cursor.execute(command, (input.nick, input.chan)).fetchone()
if results[0] > 0: if results[0] > 0:
command = "select id, user_from, quote, date from tell where name = ? and chan = ?" command = "select id, user_from, quote, date from tell " \
"where name = ? and chan = ?"
tells = cursor.execute(command, (input.nick, input.chan)).fetchall() tells = cursor.execute(command, (input.nick, input.chan)).fetchall()
for tell in tells: for tell in tells:
reltime = timesince(datetime.datetime.fromtimestamp(tell[3])) reltime = timesince(datetime.datetime.fromtimestamp(tell[3]))
bot.reply('%(teller)s said %(reltime)s ago: %(quote)s' % \ bot.reply('%(teller)s said %(reltime)s ago: %(quote)s' %
{'teller': tell[1], 'quote': tell[2], 'reltime': reltime}) {'teller': tell[1], 'quote': tell[2], 'reltime': reltime})
command = "delete from tell where id = ?" command = "delete from tell where id = ?"
cursor.execute(command, (tell[0],)) cursor.execute(command, (tell[0], ))
conn.commit() conn.commit()
conn.close() conn.close()
@hook.command @hook.command
def tell(bot, input): def tell(bot, input):
".tell <nick> <message> - Relay <message> to <nick> the next time he talks"
".tell <nick> - Tell somebody something later. Unless you suck, in which case tell yourself to go take a hike"
if len(input.msg) < 6: if len(input.msg) < 6:
return tell.__doc__ return tell.__doc__
@ -60,7 +61,7 @@ def tell(bot, input):
conn = dbconnect(dbpath) conn = dbconnect(dbpath)
command = "select count(*) from tell_probation where name=? and chan=?" command = "select count(*) from tell_probation where name=? and chan=?"
if conn.execute(command, (input.nick,input.chan)).fetchone()[0] > 0: if conn.execute(command, (input.nick, input.chan)).fetchone()[0] > 0:
return "No." return "No."
command = "select count(*) from tell where name=? and user_from=?" command = "select count(*) from tell where name=? and user_from=?"
@ -68,8 +69,10 @@ def tell(bot, input):
return "You've told that person too many things." return "You've told that person too many things."
cursor = conn.cursor() cursor = conn.cursor()
command = "insert into tell(name, user_from, quote, chan, date) values(?,?,?,?,?)" command = "insert into tell(name, user_from, quote, chan, date) " \
cursor.execute(command, (query[0], input.nick, query[2], input.chan, datetime.datetime.now())) "values(?,?,?,?,?)"
cursor.execute(command, (query[0], input.nick, query[2], input.chan,
datetime.datetime.now()))
conn.commit() conn.commit()
conn.close() conn.close()
@ -78,25 +81,27 @@ def tell(bot, input):
else: else:
return tell.__doc__ return tell.__doc__
# check to see that our db has the the seen table, and return a connection.
def dbconnect(db): def dbconnect(db):
"check to see that our db has the the seen table and return a connection."
conn = sqlite3.connect(db) conn = sqlite3.connect(db)
results = conn.execute("select count(*) from sqlite_master where name=?", ("tell" ,)).fetchone() results = conn.execute("select count(*) from sqlite_master where name=?",
("tell", )).fetchone()
if results[0] == 0: if results[0] == 0:
conn.execute("create table if not exists "+ \ conn.execute("create table if not exists tell(id integer primary key "
"tell(id integer primary key autoincrement, name varchar(30) not null, "+ \ "autoincrement, name varchar(30) not null, user_from "
"user_from varchar(30) not null, quote varchar(250) not null, "+ \ "varchar(30) not null, quote varchar(250) not null, "
"chan varchar(32) not null, date datetime not null);") "chan varchar(32) not null, date datetime not null);")
conn.commit() conn.commit()
results = conn.execute("select count(*) from sqlite_master where name=?", ("tell_probation" ,)).fetchone() results = conn.execute("select count(*) from sqlite_master where name=?",
("tell_probation", )).fetchone()
if results[0] == 0: if results[0] == 0:
conn.execute("create table if not exists "+ \ conn.execute("create table if not exists "+ \
"tell_probation(name varchar(30), chan varchar(32),"+ \ "tell_probation(name varchar(30), chan varchar(32),"
"primary key(name, chan));") "primary key(name, chan));")
conn.commit() conn.commit()
return conn return conn

View File

@ -4,7 +4,8 @@ import urllib2
from util import hook from util import hook
tinyurl_re = re.compile(r'http://(?:www\.)?tinyurl.com/([A-Za-z0-9\-]+)', flags=re.IGNORECASE) tinyurl_re = re.compile(r'http://(?:www\.)?tinyurl.com/([A-Za-z0-9\-]+)',
flags=re.IGNORECASE)
@hook.command(hook=r'(.*)', prefix=False) @hook.command(hook=r'(.*)', prefix=False)

View File

@ -17,8 +17,9 @@ def unescape_xml(string):
# zip('&gt; &lt; &apos; &quote; &amp'.split(), '> < \' " &'.split())) # zip('&gt; &lt; &apos; &quote; &amp'.split(), '> < \' " &'.split()))
# boring, normal # boring, normal
return string.replace('&gt;', '>').replace('&lt;', '<'). \ return string.replace('&gt;', '>').replace('&lt;', '<').replace('&apos;',
replace('&apos;', "'").replace('&quote;', '"').replace('&amp;', '&') "'").replace('&quote;', '"').replace('&amp;', '&')
@hook.command @hook.command
def twitter(input): def twitter(input):

Binary file not shown.