2010-05-24 13:38:06 +00:00
|
|
|
# -*- Encoding: utf-8 -*-
|
2006-10-19 14:39:11 +00:00
|
|
|
###
|
2010-05-24 13:38:06 +00:00
|
|
|
# Copyright (c) 2005-2007 Dennis Kaarsemaker
|
|
|
|
# Copyright (c) 2008-2010 Terence Simpson
|
|
|
|
# Copyright (c) 2010 Elián Hanisch
|
2006-10-19 14:39:11 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of version 2 of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
2006-06-26 17:57:20 +00:00
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.registry as registry
|
|
|
|
|
2010-03-17 10:14:07 +00:00
|
|
|
class ValidTypes(registry.OnlySomeStrings):
|
|
|
|
"""Invalid type, valid types are: 'removal', 'ban' or 'quiet'."""
|
|
|
|
validStrings = ('removal', 'ban', 'quiet')
|
|
|
|
|
2010-04-04 02:53:05 +00:00
|
|
|
|
2010-03-17 10:14:07 +00:00
|
|
|
class SpaceSeparatedListOfTypes(registry.SpaceSeparatedListOf):
|
|
|
|
Value = ValidTypes
|
|
|
|
|
|
|
|
|
2006-06-26 17:57:20 +00:00
|
|
|
def configure(advanced):
|
2010-05-24 13:38:06 +00:00
|
|
|
from supybot.question import yn, something, anything, output
|
|
|
|
import sqlite
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
from supybot.utils.str import format
|
2006-06-26 17:57:20 +00:00
|
|
|
conf.registerPlugin('Bantracker', True)
|
|
|
|
|
2010-05-24 13:38:06 +00:00
|
|
|
def getReviewTime():
|
|
|
|
output("How many days should the bot wait before requesting a ban/quiet review?")
|
|
|
|
review = something("Can be an integer or decimal value. Zero disables reviews.", default=str(Bantracker.review._default))
|
|
|
|
|
|
|
|
try:
|
|
|
|
review = float(review)
|
|
|
|
if review < 0:
|
|
|
|
raise TypeError
|
|
|
|
except TypeError:
|
|
|
|
output("%r is an invalid value, it must be an integer or float greater or equal to 0", review)
|
|
|
|
return getReviewTime()
|
|
|
|
else:
|
|
|
|
return review
|
|
|
|
|
|
|
|
enabled = yn("Enable Bantracker for all channels?")
|
|
|
|
database = something("Location of the Bantracker database", default=conf.supybot.directories.data.dirize('bans.db'))
|
|
|
|
bansite = anything("URL of the Bantracker web interface, without the 'bans.cgi'. (leave this blank if you don't want to run a web server)")
|
|
|
|
|
|
|
|
request = yn("Enable review and comment requests from bot?", default=False)
|
|
|
|
if request and advanced:
|
|
|
|
output("Which types would you like the bot to request comments for?")
|
|
|
|
output(format("The available request types are %L", type))
|
|
|
|
types = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.type._default))
|
|
|
|
type = set([])
|
|
|
|
for name in re.split(r',?\s+', types):
|
|
|
|
name = name.lower()
|
|
|
|
if name in ('removal', 'ban', 'quiet'):
|
|
|
|
type.append(name)
|
|
|
|
|
|
|
|
output("Which nicks should be bot not requets comments from?")
|
|
|
|
output("Is case insensitive and wildcards '*' and '?' are accepted.")
|
|
|
|
ignores = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.ignore._default))
|
|
|
|
ignore = set([])
|
|
|
|
for name in re.split(r',?\s+', ignores):
|
|
|
|
name = name.lower()
|
|
|
|
ignore.add(name)
|
|
|
|
|
|
|
|
output("You can set the comment and review requests for some nicks to be forwarded to specific nicks/channels")
|
|
|
|
output("Which nicks should these requests be forwarded for?")
|
|
|
|
output("Is case insensitive and wildcards '*' and '?' are accepted.")
|
|
|
|
forwards = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.forward._default))
|
|
|
|
forward = set([])
|
|
|
|
for name in re.split(r',?\s+', forwards):
|
|
|
|
name = name.lower()
|
|
|
|
forward.add(name)
|
|
|
|
|
|
|
|
output("Which nicks/channels should the requests be forwarded to?")
|
|
|
|
output("Is case insensitive and wildcards '*' and '?' are accepted.")
|
|
|
|
channels_i = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.channels._default))
|
|
|
|
channels = set([])
|
|
|
|
for name in re.split(r',?\s+', channel_i):
|
|
|
|
name = name.lower()
|
|
|
|
channels.add(name)
|
|
|
|
|
|
|
|
review = getReviewTime()
|
|
|
|
|
|
|
|
else:
|
|
|
|
type = Bantracker.type._default
|
|
|
|
ignore = Bantracker.ignore._default
|
|
|
|
forward = Bantracker.forward._default
|
|
|
|
channels = Bantracker.channels._default
|
|
|
|
review = Bantracker.review._default
|
|
|
|
|
|
|
|
Bantracker.enabled.setValue(enabled)
|
|
|
|
Bantracker.database.setValue(database)
|
|
|
|
Bantracker.bansite.setValue(bansite)
|
|
|
|
Bantracker.request.setValue(request)
|
|
|
|
Bantracker.type.setValue(type)
|
|
|
|
Bantracker.ignore.setValue(ignore)
|
|
|
|
Bantracker.forward.setValue(forward)
|
|
|
|
Bantracker.channels.setValue(channels)
|
|
|
|
Bantracker.review.setValue(review)
|
|
|
|
|
|
|
|
# Create the initial database
|
|
|
|
db_file = Bantracker.database()
|
|
|
|
if not db_file:
|
|
|
|
db_file = conf.supybot.directories.data.dirize('bans.db')
|
|
|
|
output("supybot.plugins.Bantracker.database will be set to %r" % db_file)
|
|
|
|
Bantracker.database.setValue(db_file)
|
|
|
|
|
|
|
|
if os.path.exists(db_file):
|
|
|
|
return
|
|
|
|
|
|
|
|
output("Creating an initial database in %r" % db_file)
|
|
|
|
con = sqlite.connect(db_file)
|
|
|
|
cur = con.cursor()
|
|
|
|
|
|
|
|
try:
|
|
|
|
con.begin()
|
|
|
|
cur.execute("""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
|
|
|
|
)""")
|
|
|
|
#"""
|
|
|
|
|
|
|
|
cur.execute("""CREATE TABLE comments (
|
|
|
|
ban_id INTEGER,
|
|
|
|
who VARCHAR(100) NOT NULL,
|
|
|
|
comment MEDIUMTEXT NOT NULL,
|
|
|
|
time VARCHAR(300) NOT NULL
|
|
|
|
)""")
|
|
|
|
#"""
|
|
|
|
|
|
|
|
cur.execute("""CREATE TABLE sessions (
|
|
|
|
session_id VARCHAR(50) PRIMARY KEY,
|
|
|
|
user MEDIUMTEXT NOT NULL,
|
|
|
|
time INT NOT NULL
|
|
|
|
)""")
|
|
|
|
#"""
|
|
|
|
|
|
|
|
cur.execute("""CREATE TABLE users (
|
|
|
|
username VARCHAR(50) PRIMARY KEY,
|
|
|
|
salt VARCHAR(8),
|
|
|
|
password VARCHAR(50)
|
|
|
|
)""")
|
|
|
|
#"""
|
|
|
|
|
|
|
|
except:
|
|
|
|
con.rollback()
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
con.commit()
|
|
|
|
finally:
|
|
|
|
con.close()
|
|
|
|
|
2006-06-26 17:57:20 +00:00
|
|
|
Bantracker = conf.registerPlugin('Bantracker')
|
2010-03-17 00:46:18 +00:00
|
|
|
conf.registerChannelValue(Bantracker, 'enabled',
|
2006-06-26 17:57:20 +00:00
|
|
|
registry.Boolean(False, """Enable the bantracker"""))
|
2010-03-17 00:46:18 +00:00
|
|
|
conf.registerGlobalValue(Bantracker, 'database',
|
2009-10-12 18:26:35 +00:00
|
|
|
registry.String('', "Filename of the bans database", private=True))
|
2010-03-17 00:46:18 +00:00
|
|
|
conf.registerGlobalValue(Bantracker, 'bansite',
|
2008-05-05 15:28:59 +00:00
|
|
|
registry.String('', "Web site for the bantracker, without the 'bans.cgi' appended", private=True))
|
2010-03-15 16:12:51 +00:00
|
|
|
|
2010-04-03 23:06:29 +00:00
|
|
|
conf.registerChannelValue(Bantracker, 'request',
|
2010-04-03 22:46:32 +00:00
|
|
|
registry.Boolean(False,
|
|
|
|
"Enable message requests from bot"))
|
2010-04-03 02:43:26 +00:00
|
|
|
conf.registerChannelValue(Bantracker.request, 'type',
|
2010-03-17 10:14:07 +00:00
|
|
|
SpaceSeparatedListOfTypes(['removal', 'ban', 'quiet'],
|
|
|
|
"List of events for which the bot should request a comment."))
|
2010-04-03 02:43:26 +00:00
|
|
|
conf.registerChannelValue(Bantracker.request, 'ignore',
|
|
|
|
registry.SpaceSeparatedListOfStrings(['FloodBot?', 'FloodBotK?', 'ChanServ'],
|
2010-04-04 02:53:05 +00:00
|
|
|
"List of nicks for which the bot won't request to comment or review."\
|
2010-03-15 23:51:32 +00:00
|
|
|
" Is case insensible and wildcards * ? are accepted."))
|
2010-04-03 02:43:26 +00:00
|
|
|
conf.registerChannelValue(Bantracker.request, 'forward',
|
2010-03-15 23:51:32 +00:00
|
|
|
registry.SpaceSeparatedListOfStrings([],
|
2010-03-16 02:26:19 +00:00
|
|
|
"List of nicks for which the bot will forward the request to"\
|
|
|
|
" the channels/nicks defined in forwards.channels option."\
|
2010-03-15 23:51:32 +00:00
|
|
|
" Is case insensible and wildcards * ? are accepted."))
|
2010-04-03 02:43:26 +00:00
|
|
|
conf.registerChannelValue(Bantracker.request.forward, 'channels',
|
2010-03-15 23:51:32 +00:00
|
|
|
registry.SpaceSeparatedListOfStrings([],
|
2010-04-04 02:53:05 +00:00
|
|
|
"List of channels/nicks to forward the request if the op is in the forward list."))
|
2010-04-04 00:55:59 +00:00
|
|
|
conf.registerGlobalValue(Bantracker.request, 'review',
|
2010-03-31 03:03:13 +00:00
|
|
|
registry.Float(7,
|
2010-04-04 02:53:05 +00:00
|
|
|
"Days after which the bot will request for review a ban. Can be an integer or decimal"
|
|
|
|
" value. Zero disables reviews."))
|
2010-04-03 02:43:26 +00:00
|
|
|
|
|
|
|
|