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
|
2011-05-28 06:33:21 +00:00
|
|
|
# Copyright (c) 2008-2011 Terence Simpson
|
2010-05-24 13:38:06 +00:00
|
|
|
# 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-28 23:55:07 +00:00
|
|
|
from supybot.questions import yn, something, output
|
2010-05-24 13:38:06 +00:00
|
|
|
import sqlite
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
from supybot.utils.str import format
|
2010-05-28 22:51:28 +00:00
|
|
|
|
|
|
|
def anything(prompt, default=None):
|
|
|
|
"""Because supybot is pure fail"""
|
|
|
|
from supybot.questions import expect
|
|
|
|
return expect(prompt, [], default=default)
|
|
|
|
|
2010-05-29 13:36:43 +00:00
|
|
|
Bantracker = conf.registerPlugin('Bantracker', True)
|
2006-06-26 17:57:20 +00:00
|
|
|
|
2010-05-24 13:38:06 +00:00
|
|
|
def getReviewTime():
|
|
|
|
output("How many days should the bot wait before requesting a ban/quiet review?")
|
2010-05-28 23:55:07 +00:00
|
|
|
review = something("Can be an integer or decimal value. Zero disables reviews.", default=str(Bantracker.request.review._default))
|
2010-05-24 13:38:06 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
review = float(review)
|
|
|
|
if review < 0:
|
|
|
|
raise TypeError
|
|
|
|
except TypeError:
|
2010-05-29 13:36:43 +00:00
|
|
|
output("%r is an invalid value, it must be an integer or float greater or equal to 0" % review)
|
2010-05-24 13:38:06 +00:00
|
|
|
return getReviewTime()
|
|
|
|
else:
|
|
|
|
return review
|
|
|
|
|
2011-05-28 06:33:21 +00:00
|
|
|
output("If you choose not to enabled Bantracker for all channels, it can be enabled per-channel with the '@Config channel' command")
|
2010-05-24 13:38:06 +00:00
|
|
|
enabled = yn("Enable Bantracker for all channels?")
|
2011-05-28 06:33:21 +00:00
|
|
|
database = something("Location of the Bantracker database", default=Bantracker.database._default)
|
|
|
|
bansite = anything("URL of the Bantracker web interface, without the 'bans.cgi'. (leave this blank if you aren't running a web server)")
|
2010-05-24 13:38:06 +00:00
|
|
|
|
|
|
|
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?")
|
2010-05-28 23:55:07 +00:00
|
|
|
output(format("The available request types are %L", Bantracker.request.type._default))
|
|
|
|
types = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.request.type._default))
|
2010-05-24 13:38:06 +00:00
|
|
|
type = set([])
|
|
|
|
for name in re.split(r',?\s+', types):
|
|
|
|
name = name.lower()
|
2011-05-28 06:33:21 +00:00
|
|
|
if name in ValidTypes.validStrings:
|
2010-05-28 23:55:07 +00:00
|
|
|
type.add(name)
|
2010-05-24 13:38:06 +00:00
|
|
|
|
|
|
|
output("Which nicks should be bot not requets comments from?")
|
2011-05-28 06:33:21 +00:00
|
|
|
output("This is useful if you have automated channel bots that should not be directly asked for reviews")
|
|
|
|
output("Is case-insensitive and the wildcards '*' and '?' are accepted.")
|
|
|
|
ignores = anything("Separate nicks by spaces or commas:", default=', '.join(Bantracker.request.ignore._default))
|
2010-05-24 13:38:06 +00:00
|
|
|
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")
|
2011-05-28 06:33:21 +00:00
|
|
|
output("This is useful if you have automated channel bots that should not be directly asked for reviews")
|
2010-05-24 13:38:06 +00:00
|
|
|
output("Which nicks should these requests be forwarded for?")
|
2011-05-28 06:33:21 +00:00
|
|
|
output("Is case-insensitive and the wildcards '*' and '?' are accepted.")
|
|
|
|
forwards = anything("Separate nicks by spaces or commas:", default=', '.join(Bantracker.request.forward._default))
|
2010-05-24 13:38:06 +00:00
|
|
|
forward = set([])
|
|
|
|
for name in re.split(r',?\s+', forwards):
|
|
|
|
name = name.lower()
|
|
|
|
forward.add(name)
|
|
|
|
|
2011-05-28 06:33:21 +00:00
|
|
|
output("Which nicks/channels should those requests be forwarded to?")
|
|
|
|
output("Is case-insensitive and wildcards '*' and '?' are accepted.")
|
|
|
|
channels_i = anything("Separate nicks/channels by spaces or commas:", default=', '.join(Bantracker.request.forward._default))
|
2010-05-24 13:38:06 +00:00
|
|
|
channels = set([])
|
2010-05-28 23:55:07 +00:00
|
|
|
for name in re.split(r',?\s+', channels_i):
|
2010-05-24 13:38:06 +00:00
|
|
|
name = name.lower()
|
|
|
|
channels.add(name)
|
|
|
|
|
|
|
|
review = getReviewTime()
|
|
|
|
|
|
|
|
else:
|
2010-05-28 23:55:07 +00:00
|
|
|
type = Bantracker.request.type._default
|
|
|
|
ignore = Bantracker.request.ignore._default
|
|
|
|
forward = Bantracker.request.forward._default
|
|
|
|
channels = Bantracker.request.forward.channels._default
|
|
|
|
review = Bantracker.request.review._default
|
2010-05-24 13:38:06 +00:00
|
|
|
|
|
|
|
Bantracker.enabled.setValue(enabled)
|
|
|
|
Bantracker.database.setValue(database)
|
|
|
|
Bantracker.bansite.setValue(bansite)
|
|
|
|
Bantracker.request.setValue(request)
|
2010-05-28 23:55:07 +00:00
|
|
|
Bantracker.request.type.setValue(type)
|
|
|
|
Bantracker.request.ignore.setValue(ignore)
|
|
|
|
Bantracker.request.forward.setValue(forward)
|
|
|
|
Bantracker.request.forward.channels.setValue(channels)
|
|
|
|
Bantracker.request.review.setValue(review)
|
2010-05-24 13:38:06 +00:00
|
|
|
|
|
|
|
# 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):
|
2011-05-28 06:33:21 +00:00
|
|
|
output("%r already exists" % db_file)
|
2010-05-24 13:38:06 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
output("Creating an initial database in %r" % db_file)
|
|
|
|
con = sqlite.connect(db_file)
|
|
|
|
cur = con.cursor()
|
|
|
|
|
|
|
|
try:
|
|
|
|
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
|
|
|
|
)""")
|
|
|
|
#"""
|
|
|
|
|
|
|
|
except:
|
|
|
|
con.rollback()
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
con.commit()
|
|
|
|
finally:
|
2010-05-28 23:55:07 +00:00
|
|
|
cur.close()
|
2010-05-24 13:38:06 +00:00
|
|
|
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',
|
2011-05-28 06:33:21 +00:00
|
|
|
registry.String(conf.supybot.directories.data.dirize('bans.db'), "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'],
|
2011-05-29 22:22:34 +00:00
|
|
|
"List of nicks for which the bot won't request a comment."\
|
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([],
|
2011-05-29 22:22:34 +00:00
|
|
|
"List of channels/nicks to forward the comment request if the op is in the forward list."))
|
|
|
|
|
|
|
|
conf.registerChannelValue(Bantracker, 'review',
|
|
|
|
registry.Boolean(True,
|
|
|
|
"Enable/disable reviews per channel."))
|
|
|
|
conf.registerGlobalValue(Bantracker.review, 'when',
|
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"
|
2011-05-29 22:22:34 +00:00
|
|
|
" value. Zero disables reviews globally."))
|
|
|
|
conf.registerChannelValue(Bantracker.review, 'ignore',
|
|
|
|
registry.SpaceSeparatedListOfStrings(['FloodBot?', 'FloodBotK?', 'ChanServ'],
|
|
|
|
"List of nicks for which the bot won't request a review."\
|
|
|
|
" Is case insensible and wildcards * ? are accepted."))
|
|
|
|
conf.registerChannelValue(Bantracker.review, 'forward',
|
|
|
|
registry.SpaceSeparatedListOfStrings([],
|
|
|
|
"List of nicks for which the bot will forward the reviews to"\
|
|
|
|
" the channels/nicks defined in forwards.channels option."\
|
|
|
|
" Is case insensible and wildcards * ? are accepted."))
|
|
|
|
conf.registerChannelValue(Bantracker.review.forward, 'channels',
|
|
|
|
registry.SpaceSeparatedListOfStrings([],
|
|
|
|
"List of channels/nicks to forward the request if the op is in the forward list."))
|
2010-04-03 02:43:26 +00:00
|
|
|
|
|
|
|
|