Tweaks and modifications.

Bantracker:
  Make the bantracker URL configurable from the bot
  Make sure all the html links are relative
Encyclopedia:
  Handle the possibility of apt-file not being installed
  Handle the possibility of the apt-file cache not being created
  Add sync command to sync with a remote database
  Make sure all the html links are relative
Mess:
  Take out the hard-coded paths, use the config variables to find the plugin dir
This commit is contained in:
Terence Simpson 2008-05-05 12:34:57 +01:00
parent 9be83810c6
commit 393b3521f5
13 changed files with 86 additions and 22 deletions

View File

@ -20,7 +20,7 @@ import supybot.world as world
__version__ = "0.3.1"
__author__ = supybot.Author("Dennis Kaarsemaker","Seveas","dennis@kaarsemaker.net")
__contributors__ = {}
__contributors__ = {supybot.Author("Terence Simpson", "stdin", "stdin@stdin.me.uk"): ['Alow configurable bantracker URL']}
__url__ = 'https://ubotu.ubuntu-nl.org'
import config

View File

@ -14,13 +14,15 @@
###
import sys
# This needs to be set to the location of the commoncgi.py file
sys.path.append('/var/www/ubotu.ubuntu-nl.org')
from commoncgi import *
### Variables
db = '/home/dennis/ubotu/data/bans.db'
# Location of the bans database
db = '/home/ubotu/data/bans.db'
num_per_page = 100
### You shouldn't have to change anything under this line ###
con = sqlite.connect(db)
cur = con.cursor()
@ -29,7 +31,12 @@ error = ''
user = None
# Delete old sessions
cur.execute("""DELETE FROM sessions WHERE time < %d""", int(time.time()) - 2592000 * 3)
## For some reason this fails, so deal with it
try:
cur.execute("""DELETE FROM sessions WHERE time < %d""", int(time.time()) - 2592000 * 3)
except:
con.commit()
pass
# Session handling
if form.has_key('sess'):
@ -95,7 +102,7 @@ tz = pytz.timezone(tz)
# Search form
print '<div class="search">'
print '<form action="/bans.cgi" method="GET">'
print '<form action="bans.cgi" method="GET">'
print '<input class="input" type="text" name="query"'
if form.has_key('query'):
print 'value="%s" ' % form['query'].value

View File

@ -1,7 +1,7 @@
<html>
<head>
<title>Ubugtu bantracker</title>
<link rel="stylesheet" href="/bot.css" />
<link rel="stylesheet" href="bot.css" />
<link rel="shortcut icon" href="favicon.ico" type="image/png" />
<script type="text/javascript">
var DHTML = (document.getElementById || document.all || document.layers);
@ -39,7 +39,7 @@
function loadlog(id) {
r = new XMLHttpRequest();
r.onreadystatechange = printlog;
r.open("GET",'/bans.cgi?log=' + id, true);
r.open("GET",'bans.cgi?log=' + id, true);
r.send(null);
}
function printlog() {

View File

@ -23,3 +23,5 @@ conf.registerChannelValue(conf.supybot.plugins.Bantracker, 'enabled',
registry.Boolean(False, """Enable the bantracker"""))
conf.registerGlobalValue(conf.supybot.plugins.Bantracker, 'database',
registry.String('', "Filename of the bans database",private=True))
conf.registerGlobalValue(conf.supybot.plugins.Bantracker, 'bansite',
registry.String('', "Web site for the bantracker, without the 'bans.cgi' appended", private=True)

View File

@ -240,11 +240,13 @@ class Bantracker(callbacks.Plugin):
return
user.addAuth(msg.prefix)
ircdb.users.setUser(user, flush=False)
if not self.registryValue('bansite'):
irc.error("No bansite enabled, please set conf.supybot.plugins.Bantracker.bansite")
return
sessid = md5.new('%s%s%d' % (msg.prefix, time.time(), random.randint(1,100000))).hexdigest()
self.db_run("""INSERT INTO sessions (session_id, user, time) VALUES (%s, %s, %d);""",
(sessid, msg.prefix[:msg.prefix.find('!')], int(time.time())))
irc.reply('Log in at https://ubotu.ubuntu-nl.org/bans.cgi?sess=%s' % sessid, private=True)
irc.reply('Log in at %s/bans/cgi?sess=%s' % (self.registryValue('bansite'), sessid), private=True)
btlogin = wrap(btlogin)

View File

@ -22,7 +22,7 @@ import supybot.world as world
__version__ = "2.2"
__author__ = supybot.Author("Dennis Kaarsemaker","Seveas","dennis@kaarsemaker.net")
__contributors__ = {}
__contributors__ = {supybot.Author("Terence Simpson", "stdin", "stdin@stdin.me.uk"): ['sync']}
__url__ = 'https://bots.ubuntulinux.nl'
import config

View File

@ -40,3 +40,5 @@ conf.registerGlobalValue(Encyclopedia, 'aptdir',
registry.String('', 'Path to apt cache directory',private=True))
conf.registerGlobalValue(Encyclopedia, 'alert',
registry.String('ops','factoid name used for alerts'))
conf.registerGlobalValue(Encyclopedia, 'remotedb',
registry.String('http://jussi01.com/ubuntu.db', 'Remote location of the master database'))

View File

@ -14,14 +14,19 @@
###
import sys
sys.path.append('/var/www/ubotu.ubuntu-nl.org')
# This needs to be set to the location of the commoncgi.py file
sys.path.append('/var/www/')
from commoncgi import *
### Variables
NUM_PER_PAGE=50.0
datadir = '/home/dennis/ubotu/data/facts'
# Directory of the factoids database
datadir = '/home/ubotu/data'
# Database name (without .db)
default_database = 'ubuntu'
#### You shouldn't have to change anything under this line ###
databases = [x for x in os.listdir(datadir)]
# Initialize

View File

@ -2,7 +2,7 @@
<head>
<title>Ubotu factoids</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="/bot.css" />
<link rel="stylesheet" href="bot.css" />
<link rel="shortcut icon" href="favicon.ico" type="image/png" />
<script type="text/javascript">
var DHTML = (document.getElementById || document.all || document.layers);
@ -48,16 +48,13 @@ More factoids: <a href="factoids.cgi?db=ubuntu">Ubuntu</a> &middot;
<a href="factoids.cgi?db=falcon">Falcon</a> &middot;
<a href="factoids.cgi?db=buntudot">buntudot</a> &middot;
<a href="factoids.cgi?db=gnewsense">GNewSense</a><br />
<form action="/factoids.cgi" method="GET"><input class="input" type="text" name="search" />
<form action="factoids.cgi" method="GET"><input class="input" type="text" name="search" />
<input class="input" type="submit" value="Search"></form>
<p>
%s
</p>
<p>
<a href="ubuntu.db">Ubuntu factoid database file</a><br />
<a href="buntudot.db">Buntudot factoid database file</a><br />
<a href="falcon.db">Falcon factoid database file</a><br />
<a href="gnewsense.db">GNewSense factoid database file</a><br />
&copy;2006 Dennis Kaarsemaker
</p>
</div>

View File

@ -1,7 +1,7 @@
<html>
<head>
<title>Bot logs</title>
<link rel="stylesheet" href="/bot.css" />
<link rel="stylesheet" href="bot.css" />
<link rel="shortcut icon" href="favicon.ico" type="image/png" />
</head>
<body>

View File

@ -46,6 +46,12 @@ class Apt:
if filelookup:
data = commands.getoutput(self.aptfilecommand % (distro, distro, pkg)).split()
if data:
if data[0] == 'sh:': # apt-file isn't installed
plugin.log.error("apt-file is not installed")
return "Please use http://packages.ubuntu.com/ to search for files"
if data[0] == 'E:': # No files in the cache dir
plugin.log.error("Please run the 'update_apt_file' script")
return "Cache out of data, please contact the administrator"
if len(data) > 5:
return "File %s found in %s (and %d others)" % (pkg, ', '.join(data[:5]), len(data)-5)
return "File %s found in %s" % (pkg, ', '.join(data))

View File

@ -512,4 +512,47 @@ class Encyclopedia(callbacks.Plugin):
ret[r] = 1
return 'Found: %s' % ', '.join(sorted(ret.keys(), lambda x, y: cmp(ret[x], ret[y]))[:10])
def sync(self, irc, msg, args):
"""takes no arguements
Downloads a copy of the database from the remote server.
"""
if not capab(msg.prefix, "owner"):
irc.error("Sorry, you can't do that")
return
def download_database(location, dpath):
"""Download the database located at location to path dpath"""
import urllib2
fd = urllib2.urlopen(location)
newDb = fd.read()
fd.close()
fd2 = open(dpath,'w')
fd2.write(newDb)
fd2.close()
# Having this configurable is nice, but could lead to errors in *my* code,
# So I'll just assume it's always going to be set to 'ubuntu'
# db = self.registryValue('database')
db = 'ubuntu'
dbpath = os.path.join(self.registryValue('datadir'), '%s.db' % db)
# We're moving files and downloading, lots can go wrong so use lots of try blocks.
try:
os.rename(dbpath, "%s.backup" % dbpath)
except:
self.log.error("Could not rename %s to %s.backup" % (dbpath, dbpath))
irc.error("Internal error, see log")
return
try:
# Downloading can take some time, let the user know we're doing something
irc.reply("Attemting to download database", prefixNick=False)
download_database(self.registryValue('remotedb'), dbpath)
irc.replySuccess()
except:
self.log.error("Could not download %s to %s" % (self.registryValue('remotedb'), dbpath))
irc.error("Internal error, see log")
os.rename("%s.backup" % dbpath, dbpath)
return
sync = wrap(sync)
Class = Encyclopedia

View File

@ -41,10 +41,10 @@ mess = {
'vmjg59': ('Virtual Matthew Garrett', 'http://www.rjek.com/vmjg59.cgi', r'<body>(?P<fact>.*?)<p>', True),
'shakespeare': ('Shakespeare quotes', 'http://www.pangloss.com/seidel/Shaker/', r'<font.*?>(?P<fact>.*?)</font>', False),
'lugradio': ('Lugradio facts', 'http://planet.lugradio.org/facts/', r'<h2>\s*(?P<fact>.*?)</h2>', False),
'bofh': ('BOFH excuses', '/home/dennis/ubotu/plugins/Mess/bofh.txt', 'BOFH Excuse #%d: ', False),
'42': ('HHGTTG quotes', '/home/dennis/ubotu/plugins/Mess/42.txt', '', False),
'magic8ball': ('The magic 8ball', '/home/dennis/ubotu/plugins/Mess/ball.txt', '', False),
'ferengi': ('Ferengi rules of acquisition', '/home/dennis/ubotu/plugins/Mess/ferengi.txt', 'Ferengi rule of acquisition ', False)
'bofh': ('BOFH excuses', '%s/Mess/bofh.txt' % conf.supybot.directories.plugins[1], 'BOFH Excuse #%d: ', False),
'42': ('HHGTTG quotes', '%s/Mess/42.txt' % conf.supybot.directories.plugins[1], '', False),
'magic8ball': ('The magic 8ball', '%s/Mess/ball.txt' % conf.supybot.directories.plugins[1], '', False),
'ferengi': ('Ferengi rules of acquisition', '%s/Mess/ferengi.txt' % conf.supybot.directories.plugins[1], 'Ferengi rule of acquisition ', False)
}
data = {}
for m in mess.keys():