Made bantracker releaseable
some small fixes Added a pony
This commit is contained in:
@ -1 +1,39 @@
|
||||
Insert a description of your plugin here, with any notes, etc. about using it.
|
||||
This plugin can store all bans/kicks etc in an sqlite database. It includes a
|
||||
cgi script to view bans/kicks and comment on them. The CGI script uses launchpad
|
||||
authentication, which may not be useful for everyone.
|
||||
|
||||
It also uses commoncgi.py which should be on your sys.path (or as you can see in
|
||||
the script, sys.path is modified to include the dir of commoncgi.py)
|
||||
|
||||
The schema of the sqlite database:
|
||||
|
||||
CREATE TABLE bans (
|
||||
id INTEGER PRIMARY KEY,
|
||||
channel VARCHAR(30) NOT NULL,
|
||||
mask VARCHAR(100) NOT NULL,
|
||||
operator VARCHAR(30) NOT NULL,
|
||||
time VARCHAR(300) NOT NULL,
|
||||
removal DATETIME,
|
||||
removal_op VARCHAR(30),
|
||||
log TEXT
|
||||
);
|
||||
CREATE TABLE comments (
|
||||
ban_id INTEGER,
|
||||
who VARCHAR(100) NOT NULL,
|
||||
comment MEDIUMTEXT NOT NULL,
|
||||
time VARCHAR(300) NOT NULL
|
||||
);
|
||||
CREATE TABLE sessions (
|
||||
session_id VARCHAR(50) PRIMARY KEY,
|
||||
user MEDIUMTEXT NOT NULL,
|
||||
time INT NOT NULL
|
||||
);
|
||||
CREATE TABLE users (
|
||||
username VARCHAR(50) PRIMARY KEY,
|
||||
salt VARCHAR(8),
|
||||
password VARCHAR(50)
|
||||
);
|
||||
|
||||
To configure the plugin, create the sqlite database with above structure and set
|
||||
supybot.plugins.bantracker.database to its filename. Then enable it per channel
|
||||
by setting the channel variable supybot.plugins.bantracker.enabled
|
||||
|
@ -367,7 +367,7 @@ for b in bans[start:end]:
|
||||
print '<br /><span class="removal">%s</span>' % pickle.loads(b[4]).astimezone(tz).strftime("%b %d %Y %H:%M:%S")
|
||||
print '</td>'
|
||||
# Log link
|
||||
print """<td><span class="pseudolink" onclick="showlog('%s')">Show/Hide log</span></td>""" % b[6]
|
||||
print """<td><span class="pseudolink" onclick="showlog('%s')">Show log</span></td>""" % b[6]
|
||||
print '</tr>'
|
||||
|
||||
# Comments
|
||||
|
@ -30,15 +30,10 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function showlog(item) {
|
||||
var c = new getObj('log');
|
||||
if ( c.style.display == 'block' ) {
|
||||
c.style.display = 'none';
|
||||
}
|
||||
else {
|
||||
loadlog(item);
|
||||
}
|
||||
|
||||
loadlog(item);
|
||||
}
|
||||
var r;
|
||||
function loadlog(id) {
|
||||
|
@ -19,7 +19,9 @@ def configure(advanced):
|
||||
conf.registerPlugin('Bantracker', True)
|
||||
|
||||
Bantracker = conf.registerPlugin('Bantracker')
|
||||
conf.registerChannelValue(conf.supybot.plugins.BanTracker, 'enabled',
|
||||
conf.registerChannelValue(conf.supybot.plugins.Bantracker, 'enabled',
|
||||
registry.Boolean(False, """Enable the bantracker"""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.BanTracker, 'stats',
|
||||
conf.registerChannelValue(conf.supybot.plugins.Bantracker, 'stats',
|
||||
registry.Boolean(False, """Enable join/part stats"""))
|
||||
conf.registerGlobalValue(conf.supybot.plugins.Bantracker, 'database',
|
||||
registry.String('', "Filename of the bans database"))
|
||||
|
@ -11,7 +11,6 @@
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
###
|
||||
#
|
||||
# Based on the standard supybot logging plugin, which has the following
|
||||
# copyright:
|
||||
#
|
||||
@ -43,38 +42,18 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
###
|
||||
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
import supybot.plugins as plugins
|
||||
import supybot.ircutils as ircutils
|
||||
import supybot.callbacks as callbacks
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import supybot.conf as conf
|
||||
import supybot.world as world
|
||||
|
||||
import sqlite, pytz, cPickle, datetime, time
|
||||
|
||||
db = '/home/dennis/ubugtu/data/bans.db'
|
||||
tz = 'Europe/Amsterdam'
|
||||
|
||||
def now():
|
||||
return cPickle.dumps(datetime.datetime.now(pytz.timezone(tz)))
|
||||
|
||||
def db_run(query, parms, expect_result = False, expect_id = False):
|
||||
con = sqlite.connect(db)
|
||||
cur = con.cursor()
|
||||
try:
|
||||
cur.execute(query, parms)
|
||||
except:
|
||||
con.close()
|
||||
raise
|
||||
data = None
|
||||
if expect_result: data = cur.fetchall()
|
||||
if expect_id: data = con.insert_id()
|
||||
con.commit()
|
||||
con.close()
|
||||
return data
|
||||
|
||||
class Bantracker(callbacks.Plugin):
|
||||
"""This plugin has no commands"""
|
||||
noIgnore = True
|
||||
@ -88,20 +67,31 @@ class Bantracker(callbacks.Plugin):
|
||||
for channel in irc.state.channels:
|
||||
self.doStatsLog(irc, channel, "START")
|
||||
|
||||
db = self.registryValue('database')
|
||||
if db:
|
||||
self.db = sqlite.connect(db)
|
||||
else:
|
||||
self.db = None
|
||||
|
||||
def __call__(self, irc, msg):
|
||||
try:
|
||||
# I don't know why I put this in, but it doesn't work, because it
|
||||
# doesn't call doNick or doQuit.
|
||||
# if msg.args and irc.isChannel(msg.args[0]):
|
||||
super(self.__class__, self).__call__(irc, msg)
|
||||
if irc in self.lastMsgs:
|
||||
if irc not in self.lastStates:
|
||||
self.lastStates[irc] = irc.state.copy()
|
||||
self.lastStates[irc].addMsg(irc, self.lastMsgs[irc])
|
||||
finally:
|
||||
# We must make sure this always gets updated.
|
||||
self.lastMsgs[irc] = msg
|
||||
|
||||
def db_run(self, query, parms, expect_result = False, expect_id = False):
|
||||
cur = self.db.cursor()
|
||||
cur.execute(query, parms)
|
||||
data = None
|
||||
if expect_result: data = cur.fetchall()
|
||||
if expect_id: data = con.insert_id()
|
||||
self.db.commit()
|
||||
return data
|
||||
|
||||
def reset(self):
|
||||
self.logs.clear()
|
||||
self.lastMsgs.clear()
|
||||
|
@ -25,6 +25,7 @@ Bugtracker dialects (types) this plugin understands:
|
||||
* Debbugs (debbugs sucks donkeyballs - please fix debbugs)
|
||||
* Trac (with not-too-buggered-up templates, it needs to do screenscraping)
|
||||
* Sourceforge (needs atid and group_id in the url!)
|
||||
* WikiForms (see bugs.gnewsense.org for an example)
|
||||
|
||||
To request a bug report, use this syntax:
|
||||
|
||||
|
@ -121,7 +121,6 @@ class Bugtracker(callbacks.PluginRegexp):
|
||||
|
||||
def reportnewbugs(self,irc):
|
||||
# Compile list of bugs
|
||||
print "Reporting new bugs"
|
||||
tracker = self.db['malone']
|
||||
bugs = {}
|
||||
sc = imaplib.IMAP4_SSL(imap_server)
|
||||
@ -129,13 +128,10 @@ class Bugtracker(callbacks.PluginRegexp):
|
||||
sc.select('INBOX')
|
||||
new_mail = sc.search(None, '(UNSEEN)')[1][0].split()[:20]
|
||||
for m in new_mail:
|
||||
print "Loading %s" % m
|
||||
msg = sc.fetch(m, 'RFC822')[1][0][1]
|
||||
#print msg
|
||||
fp = email.FeedParser.FeedParser()
|
||||
fp.feed(msg)
|
||||
bug = fp.close()
|
||||
#print "Mail parsed"
|
||||
# Determine bug number, component and tag
|
||||
try:
|
||||
id = int(bug['Reply-To'].split()[1])
|
||||
@ -151,15 +147,12 @@ class Bugtracker(callbacks.PluginRegexp):
|
||||
component = ''
|
||||
if tag not in bugs:
|
||||
bugs[tag] = {}
|
||||
#print "Data extracted"
|
||||
if id not in bugs[tag]:
|
||||
try:
|
||||
os.makedirs(os.path.join(bugreporter_base,tag,str(int(id/1000))))
|
||||
except:
|
||||
pass
|
||||
print os.path.join(bugreporter_base,tag,str(int(id/1000)),str(id))
|
||||
if id > 58184 and not os.path.exists(os.path.join(bugreporter_base,tag,str(int(id/1000)),str(id))):
|
||||
print "New bug: %d" % id
|
||||
fd2 = open(os.path.join(bugreporter_base,tag,str(int(id/1000)),str(id)),'w')
|
||||
fd2.close()
|
||||
try:
|
||||
@ -168,15 +161,13 @@ class Bugtracker(callbacks.PluginRegexp):
|
||||
else:
|
||||
bugs[tag][id] = self.get_bug(tracker, id, False)[0]
|
||||
except:
|
||||
print "Cannot get bug %d" % id
|
||||
pass
|
||||
for c in irc.state.channels:
|
||||
tag = self.registryValue('bugReporter', channel=c)
|
||||
if not tag:
|
||||
continue
|
||||
if tag not in bugs.keys():
|
||||
print "No new bugs in %s" % tag
|
||||
continue
|
||||
print "New bugs in %s (%s): %s" % (c, tag, str(bugs[tag].keys()))
|
||||
for b in sorted(bugs[tag].keys()):
|
||||
irc.queueMsg(ircmsgs.privmsg(c,'New bug: #%s' % bugs[tag][b][bugs[tag][b].find('bug ')+4:]))
|
||||
|
||||
@ -316,8 +307,6 @@ class Bugtracker(callbacks.PluginRegexp):
|
||||
for r in report:
|
||||
irc.reply(r, prefixNick=False)
|
||||
|
||||
#show_bug.cgi?id=|bugreport.cgi?bug=|(bugs|+bug)/|ticket/|tracker/.*aid=
|
||||
#&group_id=\d+&at_id=\d+
|
||||
def turlSnarfer(self, irc, msg, match):
|
||||
"(?P<tracker>https?://.*?)(show_bug.cgi\?id=|bugreport.cgi\?bug=|(bugs|\+bug)/|/ticket/|tracker/.*aid=)(?P<bug>\d+)(?P<sfurl>&group_id=\d+&at_id=\d+)?"
|
||||
if msg.args[0][0] == '#' and not self.registryValue('bugSnarfer', msg.args[0]):
|
||||
@ -371,7 +360,6 @@ class Bugtracker(callbacks.PluginRegexp):
|
||||
def get_bug(self, tracker, id, do_assignee, do_url = True):
|
||||
reports = []
|
||||
for r in tracker.get_bug(id):
|
||||
print r
|
||||
(bid, product, title, severity, status, assignee, url) = r
|
||||
severity = severity[0].upper() + severity[1:].lower()
|
||||
status = status[0].upper() + status[1:].lower()
|
||||
|
@ -194,10 +194,10 @@ class Encyclopedia(callbacks.Plugin):
|
||||
if value.startswith('also '):
|
||||
name += '-also'
|
||||
value = value[5:].strip()
|
||||
if len(name) > 20:
|
||||
irc.error("I am only a bot, please don't think I'm intelligent :)")
|
||||
return
|
||||
if not capab(msg.prefix, 'editfactoids'):
|
||||
if len(name) > 20:
|
||||
irc.error("I am only a bot, please don't think I'm intelligent :)")
|
||||
return
|
||||
irc.reply("Your edit request has been forwarded to %s. Thank you for your attention to detail"%self.registryValue('relaychannel'),private=True)
|
||||
irc.queueMsg(ircmsgs.privmsg(self.registryValue('relaychannel'), "In %s, %s said: %s" % (msg.args[0], msg.nick, msg.args[1])))
|
||||
lfd = open(logdir + '/botlogs/lock','a')
|
||||
|
@ -273,11 +273,13 @@ class Mess(callbacks.PluginRegexp):
|
||||
irc.reply(data.replace("\r\n",' ').replace("\r",' ').replace("\n",' '))
|
||||
southpark = wrap(southpark)
|
||||
|
||||
def pony(self, irc, msg, args):
|
||||
def pony(self, irc, msg, args, text):
|
||||
""" NO! """
|
||||
if not self.ok(msg.args[0]): return
|
||||
irc.reply("No you can't have a pony, %s!" % msg.nick)
|
||||
pony = wrap(pony)
|
||||
if not text:
|
||||
text = 'you'
|
||||
irc.reply("No %s can't have a pony, %s!" % (text, msg.nick))
|
||||
pony = wrap(pony, [additional('text')])
|
||||
|
||||
def _bauer(self,count=0):
|
||||
# if self.i % 2 == 0:
|
||||
|
Reference in New Issue
Block a user