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/
- 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
- autoreconnect

View File

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

View File

@ -77,8 +77,8 @@ def bf(input):
break
output = '/'.join(output.splitlines())
if output == '':
return 'no output'
return unicode(output, 'iso-8859-1')[:430]

View File

@ -26,6 +26,7 @@ def gis(inp):
return 'no images found'
return parsed['responseData']['results'][0]['unescapedUrl']
@hook.command
@hook.command('g')
@hook.command('goog')
@ -45,7 +46,7 @@ def google(inp):
title, content = map(lambda x: html.fromstring(x).text_content(),
(result['titleNoFormatting'], result['content']))
out = '%s -- \x02%s\x02: "%s"' % (result['unescapedUrl'], title, content)
out = ' '.join(out.split())

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]',
'TOPIC': '-!- %(nick)s changed the topic of %(chan)s to: %(msg)s',
'QUIT': '-!- %(nick)s has quit [%(msg)s]'
}
}
ctcp_formats = {'ACTION': '* %(nick)s %(ctcpmsg)s'}
@ -49,7 +49,7 @@ def beautify(input):
args['param_tail'] = ' '.join(args['paraml'][1:])
args['msg'] = irc_color_re.sub('', args['msg'])
if input.command == 'PRIVMSG' and input.msg.count('\x01') >= 2:
#ctcp
ctcp = input.msg.split('\x01', 2)[1].split(' ', 1)
@ -85,14 +85,14 @@ def get_log_fd(dir, network, chan):
def log(bot, input):
with lock:
timestamp = gmtime(timestamp_format)
fd = get_log_fd(bot.persist_dir, bot.network, 'raw')
fd.write(timestamp + ' ' + input.raw + '\n')
if input.command == 'QUIT': # these are temporary fixes until proper
input.chan = 'quit' # presence tracking is implemented
if input.command == 'NICK':
input.chan = 'nick'
input.chan = 'nick'
beau = beautify(input)

View File

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

View File

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

View File

@ -4,7 +4,8 @@ import urllib2
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)

View File

@ -13,12 +13,13 @@ def unescape_xml(string):
# unescape the 5 chars that might be escaped in xml
# gratuitously functional
# return reduce(lambda x, y: x.replace(*y), (string,
# return reduce(lambda x, y: x.replace(*y), (string,
# zip('&gt; &lt; &apos; &quote; &amp'.split(), '> < \' " &'.split()))
# boring, normal
return string.replace('&gt;', '>').replace('&lt;', '<'). \
replace('&apos;', "'").replace('&quote;', '"').replace('&amp;', '&')
return string.replace('&gt;', '>').replace('&lt;', '<').replace('&apos;',
"'").replace('&quote;', '"').replace('&amp;', '&')
@hook.command
def twitter(input):

Binary file not shown.