restructure utilities, harmonize imports, add doc on other bots
This commit is contained in:
parent
e6545f8ce7
commit
40be3038ab
|
@ -0,0 +1,26 @@
|
|||
Other bots we should "borrow" ideas from:
|
||||
|
||||
supybot http://supybot.com/
|
||||
- horribly bloated plugin structure, each plugin has its own directory and 4 files (unit testing for plugins what)
|
||||
|
||||
phenny http://inamidst.com/phenny/
|
||||
- inspiration for skybot, too much magic and not easy enough to change
|
||||
|
||||
pyfibot http://code.google.com/p/pyfibot/
|
||||
- interesting, but lots of magic
|
||||
|
||||
rbot http://linuxbrit.co.uk/rbot/
|
||||
- Ruby
|
||||
- lots of plugins
|
||||
|
||||
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
|
||||
- can convert irc colors to vt100 escape codes -- should implement this
|
||||
- autoreconnect
|
||||
|
||||
pybot
|
||||
- can handle multiple servers, but not multithreaded
|
||||
- ugly modules
|
||||
- too many external dependencies
|
||||
- attempt at NLP
|
|
@ -1,10 +1,8 @@
|
|||
import yaml
|
||||
import urllib
|
||||
import htmlentitydefs
|
||||
import re
|
||||
|
||||
import hook
|
||||
|
||||
from util import hook, yaml
|
||||
|
||||
########### from http://effbot.org/zone/re-sub.htm#unescape-html #############
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ http://brainfuck.sourceforge.net/brain.py'''
|
|||
import re
|
||||
import random
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
BUFFER_SIZE = 5000
|
||||
MAX_STEPS = 1000000
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import urllib
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
@hook.command('god')
|
||||
|
|
|
@ -5,7 +5,8 @@ simulates dicerolls
|
|||
import re
|
||||
import random
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
whitespace_re = re.compile(r'\s+')
|
||||
valid_diceroll_re = re.compile(r'^[+-]?(\d+|\d*d\d+)([+-](\d+|\d*d\d+))*$')
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import yaml
|
||||
import urllib
|
||||
from lxml import html
|
||||
|
||||
import hook
|
||||
from util import hook, yaml
|
||||
|
||||
|
||||
def api_get(kind, query):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
#@hook.command
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import hashlib
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
@hook.command
|
||||
|
|
|
@ -4,7 +4,8 @@ posts everything buttbot says to the iambuttbot twitter account
|
|||
"""
|
||||
|
||||
import urllib
|
||||
import hook
|
||||
|
||||
from util import hook
|
||||
|
||||
|
||||
@hook.command(hook=r'(.*)', prefix=False, ignorebots=False)
|
||||
|
|
|
@ -8,7 +8,8 @@ import codecs
|
|||
import time
|
||||
import re
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
lock = thread.allocate_lock()
|
||||
log_fds = {} # '%(net)s %(chan)s' : (filename, fd)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
@hook.event('KICK INVITE')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# for crusty old rotor
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
@hook.command
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import urllib
|
||||
import re
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
re_lineends = re.compile(r'[\r\n]*')
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ import os
|
|||
import thread
|
||||
import codecs
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
lock = thread.allocate_lock()
|
||||
memory = {}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
import sqlite3
|
||||
import datetime, time
|
||||
import hook
|
||||
import os
|
||||
from timesince import timesince
|
||||
|
||||
dbname = "skydb"
|
||||
from util import hook, timesince
|
||||
|
||||
dbname = "seen.db"
|
||||
|
||||
def adapt_datetime(ts):
|
||||
return time.mktime(ts.timetuple())
|
||||
|
@ -18,18 +18,9 @@ def seeninput(bot,input):
|
|||
dbpath = os.path.join(bot.persist_dir, dbname)
|
||||
|
||||
conn = dbconnect(dbpath)
|
||||
|
||||
cursor = conn.cursor()
|
||||
command = "select count(name) from seen where name = ? and chan = ?"
|
||||
cursor.execute(command, (input.nick,input.chan))
|
||||
|
||||
if(cursor.fetchone()[0] == 0):
|
||||
command = "insert into seen(name, date, quote, chan) values(?,?,?,?)"
|
||||
cursor.execute(command, (input.nick, datetime.datetime.now(), input.msg, input.chan))
|
||||
else:
|
||||
command = "update seen set date=?, quote=? where name = ? and chan = ?"
|
||||
cursor.execute(command, (datetime.datetime.now(), input.msg, input.nick, 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()
|
||||
|
||||
|
@ -66,7 +57,7 @@ def seen(bot, input):
|
|||
# check to see that our db has the the seen table, and return a connection.
|
||||
def dbconnect(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):
|
||||
conn.execute("create table if not exists "+ \
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
@hook.sieve
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
" tell.py: written by sklnd in July 2009"
|
||||
|
||||
import datetime, time
|
||||
import sqlite3
|
||||
import hook
|
||||
import os
|
||||
from timesince import timesince
|
||||
import time
|
||||
import datetime
|
||||
import sqlite3
|
||||
|
||||
from util import hook, timesince
|
||||
|
||||
|
||||
dbname = "skydb"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
import urllib2
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
tinyurl_re = re.compile(r'http://(?:www\.)?tinyurl.com/([A-Za-z0-9\-]+)', flags=re.IGNORECASE)
|
||||
|
|
|
@ -6,7 +6,7 @@ retrieves most recent tweets
|
|||
import urllib
|
||||
from lxml import etree
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
def unescape_xml(string):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from lxml import html
|
||||
import urllib
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
@hook.command('u')
|
||||
|
|
|
@ -6,7 +6,8 @@ import thread
|
|||
import urllib
|
||||
from lxml import etree
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
lock = thread.allocate_lock()
|
||||
stalk = {}
|
||||
|
|
|
@ -5,7 +5,8 @@ import urllib
|
|||
from lxml import etree
|
||||
import re
|
||||
|
||||
import hook
|
||||
from util import hook
|
||||
|
||||
|
||||
api_prefix = "http://en.wikipedia.org/w/api.php"
|
||||
search_url = api_prefix + "?action=opensearch&search=%s&format=xml"
|
||||
|
|
|
@ -2,9 +2,7 @@ import re
|
|||
from lxml import etree
|
||||
import locale
|
||||
|
||||
import hook
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "")
|
||||
from util import hook
|
||||
|
||||
|
||||
def ytdata(id):
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
import re
|
||||
from lxml import etree
|
||||
import locale
|
||||
|
||||
import hook
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "")
|
||||
|
||||
|
||||
def ytdata(id):
|
||||
url = 'http://gdata.youtube.com/feeds/api/videos/' + id
|
||||
x = etree.parse(url)
|
||||
|
||||
# I can't figure out how to deal with schemas/namespaces properly :(
|
||||
yt = '{http://gdata.youtube.com/schemas/2007}'
|
||||
media = '{http://search.yahoo.com/mrss/}'
|
||||
|
||||
rating = x.find('{http://schemas.google.com/g/2005}rating')
|
||||
data = dict(rating.items())
|
||||
data['title'] = x.find('{http://www.w3.org/2005/Atom}title').text
|
||||
data['views'] = locale.format('%d', int(x.find(yt + 'statistics').get(
|
||||
'viewCount')), 1)
|
||||
length = int(x.find(media + 'group/' + yt + 'duration').get('seconds'))
|
||||
data['length'] = ''
|
||||
if length / 3600: # > 1 hour
|
||||
data['length'] += str(length/3600) + 'h '
|
||||
if length / 60: # > 1 minute
|
||||
data['length'] += str(length/60 % 60) + 'm '
|
||||
data['length'] += "%ds" % (length % 60)
|
||||
|
||||
return data
|
||||
|
||||
youtube_re = re.compile(r'.*youtube.*v=([-_a-z0-9]+)', flags=re.IGNORECASE)
|
||||
|
||||
|
||||
@hook.command(hook=r'(.*)', prefix=False, ignore='chan:#cobol chan:#yospos')
|
||||
def youtube(inp):
|
||||
m = youtube_re.match(inp)
|
||||
if m:
|
||||
data = ytdata(m.group(1))
|
||||
return '\x02%(title)s\x02 - rated \x02%(average)s/%(max)s\x02 ' \
|
||||
'(%(numRaters)s) - views \x02%(views)s\x02 - length \x02' \
|
||||
'%(length)s\x02' % data
|
Loading…
Reference in New Issue