* Encyclopedia, PackageInfo: + Make repeat delay a setting. + Update default configuration. * Bugtracker: Fix inconsistencies in network specificity.
240 lines
11 KiB
Python
240 lines
11 KiB
Python
# -*- Encoding: utf-8 -*-
|
|
###
|
|
# Copyright (c) 2006-2007 Dennis Kaarsemaker
|
|
# Copyright (c) 2008-2010 Terence Simpson
|
|
# Copyright (c) 2018- Krytarik Raido
|
|
#
|
|
# 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.
|
|
#
|
|
###
|
|
|
|
import supybot.conf as conf
|
|
import supybot.registry as registry
|
|
|
|
def configure(advanced):
|
|
from supybot.questions import yn, something, output
|
|
import os, re, sqlite3
|
|
|
|
def anything(prompt, default=None):
|
|
"""Because supybot is pure fail"""
|
|
from supybot.questions import expect
|
|
return expect(prompt, [], default=default)
|
|
|
|
Encyclopedia = conf.registerPlugin('Encyclopedia', True)
|
|
|
|
def getRepeatdelay():
|
|
output("How many seconds should the bot wait before repeating factoids?")
|
|
repeatdelay = something("Enter a number greater or equal to 0.", default=Encyclopedia.repeatdelay._default)
|
|
|
|
try:
|
|
repeatdelay = int(repeatdelay)
|
|
if repeatdelay < 0:
|
|
raise TypeError
|
|
except TypeError:
|
|
output("Invalid value '%s', it must be an integer greater or equal to 0." % repeatdelay)
|
|
return getRepeatdelay()
|
|
else:
|
|
return repeatdelay
|
|
|
|
enabled = yn("Enable Encyclopedia for all channels?", default=Encyclopedia.enabled._default)
|
|
|
|
if advanced:
|
|
datadir = something("Which directory should the factoids database be in?", default=Encyclopedia.datadir._default)
|
|
database = something("What should be the name of the default database (without the .db extension)?", default=Encyclopedia.database._default)
|
|
prefixchar = something("What prefix character should the bot respond to factoid requests with?", default=Encyclopedia.prefixchar._default)
|
|
ignores = set([])
|
|
output("This plugin can be configured to always ignore certain factoid requests, this is useful when you want another plugin to handle them")
|
|
output("For instance, the PackageInfo plugin responds to !info and !find, so those should be ignored in Encyclopedia to allow this to work")
|
|
ignores_i = anything("Which factoid requests should the bot always ignore?", default=', '.join(Encyclopedia.ignores._default))
|
|
for name in re.split(r'[,\s]+', ignores_i):
|
|
ignores.add(name.lower())
|
|
repeatdelay = getRepeatdelay()
|
|
|
|
curStable = something("What is short name of the current stable release?", default=Encyclopedia.curStable._default)
|
|
curStableLong = something("What is long name of the current stable release?", default=Encyclopedia.curStableLong._default)
|
|
curStableNum = something("What is version number of the current stable release?", default=Encyclopedia.curStableNum._default)
|
|
|
|
curDevel = something("What is short name of the current development release?", default=Encyclopedia.curDevel._default)
|
|
curDevelLong = something("What is long name of the current development release?", default=Encyclopedia.curDevelLong._default)
|
|
curDevelNum = something("What is version number of the current development release?", default=Encyclopedia.curDevelNum._default)
|
|
|
|
curLTS = something("What is short name of the current LTS release?", default=Encyclopedia.curLTS._default)
|
|
curLTSLong = something("What is long name of the current LTS release?", default=Encyclopedia.curLTSLong._default)
|
|
curLTSNum = something("What is version number of the current LTS release?", default=Encyclopedia.curLTSNum._default)
|
|
else:
|
|
datadir = Encyclopedia.datadir._default
|
|
database = Encyclopedia.database._default
|
|
prefixchar = Encyclopedia.prefixchar._default
|
|
ignores = Encyclopedia.ignores._default
|
|
repeatdelay = Encyclopedia.repeatdelay._default
|
|
curStable = Encyclopedia.curStable._default
|
|
curStableLong = Encyclopedia.curStableLong._default
|
|
curStableNum = Encyclopedia.curStableNum._default
|
|
curDevel = Encyclopedia.curDevel._default
|
|
curDevelLong = Encyclopedia.curDevelLong._default
|
|
curDevelNum = Encyclopedia.curDevelNum._default
|
|
curLTS = Encyclopedia.curLTS._default
|
|
curLTSLong = Encyclopedia.curLTSLong._default
|
|
curLTSNum = Encyclopedia.curLTSNum._default
|
|
|
|
relaychannel = anything("What channel/nick should the bot forward edit messages to?", default=Encyclopedia.relaychannel._default)
|
|
output("What message should the bot reply with when a factoid cannot be found?")
|
|
notfoundmsg = something("If you include a '%s' in the message, it will be replaced with the requested factoid", default=Encyclopedia.notfoundmsg._default)
|
|
alert = set([])
|
|
output("When certain factoids are called an alert can be forwarded to a channel/nick")
|
|
output("Which factoids should the bot forward alert calls for?")
|
|
alert_i = anything("Separate types by spaces or commas:", default=', '.join(Encyclopedia.alert._default))
|
|
for name in re.split(r'[,\s]+', alert_i):
|
|
alert.add(name.lower())
|
|
remotedb = anything("Location of a remote database to sync with (used with @sync):", default=Encyclopedia.remotedb._default)
|
|
privateNotFound = yn("Should the bot reply in private when a factoid is not found, as opposed to in the channel?", default=Encyclopedia.privateNotFound._default)
|
|
|
|
Encyclopedia.enabled.setValue(enabled)
|
|
Encyclopedia.datadir.setValue(datadir)
|
|
Encyclopedia.database.setValue(database)
|
|
Encyclopedia.prefixchar.setValue(prefixchar)
|
|
Encyclopedia.ignores.setValue(ignores)
|
|
Encyclopedia.curStable.setValue(curStable)
|
|
Encyclopedia.curStableLong.setValue(curStableLong)
|
|
Encyclopedia.curStableNum.setValue(curStableNum)
|
|
Encyclopedia.curDevel.setValue(curDevel)
|
|
Encyclopedia.curDevelLong.setValue(curDevelLong)
|
|
Encyclopedia.curDevelNum.setValue(curDevelNum)
|
|
Encyclopedia.curLTS.setValue(curLTS)
|
|
Encyclopedia.curLTSLong.setValue(curLTSLong)
|
|
Encyclopedia.curLTSNum.setValue(curLTSNum)
|
|
Encyclopedia.relaychannel.setValue(relaychannel)
|
|
Encyclopedia.notfoundmsg.setValue(notfoundmsg)
|
|
Encyclopedia.alert.setValue(alert)
|
|
Encyclopedia.remotedb.setValue(remotedb)
|
|
Encyclopedia.privateNotFound.setValue(privateNotFound)
|
|
|
|
# Create the initial database
|
|
db_dir = Encyclopedia.datadir()
|
|
db_file = Encyclopedia.database()
|
|
|
|
if not db_dir:
|
|
db_dir = Encyclopedia.datadir._default
|
|
output("supybot.plugins.Encyclopedia.datadir will be set to %r" % db_dir)
|
|
Encyclopedia.datadir.setValue(db_dir)
|
|
|
|
if not db_file:
|
|
db_file = Encyclopedia.database._default
|
|
output("supybot.plugins.Encyclopedia.database will be set to %r" % db_file)
|
|
Encyclopedia.database.setValue(db_dir)
|
|
|
|
if os.path.exists(os.path.join(db_dir, '%s.db' % db_file)):
|
|
return
|
|
|
|
con = sqlite3.connect(os.path.join(db_dir, '%s.db' % db_file))
|
|
cur = con.cursor()
|
|
|
|
try:
|
|
cur.execute("""CREATE TABLE facts (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
value TEXT NOT NULL,
|
|
author TEXT NOT NULL,
|
|
added TEXT NOT NULL,
|
|
editor TEXT,
|
|
edited TEXT,
|
|
popularity INTEGER NOT NULL DEFAULT 0
|
|
)""")
|
|
|
|
cur.execute("""CREATE TABLE log (
|
|
id INTEGER PRIMARY KEY,
|
|
type TEXT NOT NULL,
|
|
name TEXT NOT NULL,
|
|
value TEXT NOT NULL,
|
|
author TEXT NOT NULL,
|
|
added TEXT NOT NULL
|
|
)""")
|
|
|
|
cur.execute("""CREATE TABLE requests (
|
|
id INTEGER PRIMARY KEY,
|
|
type TEXT NOT NULL,
|
|
name TEXT NOT NULL,
|
|
value TEXT NOT NULL,
|
|
requester TEXT NOT NULL,
|
|
requested TEXT NOT NULL
|
|
)""")
|
|
|
|
except:
|
|
con.rollback()
|
|
raise
|
|
else:
|
|
con.commit()
|
|
finally:
|
|
con.close()
|
|
|
|
Encyclopedia = conf.registerPlugin('Encyclopedia')
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'enabled',
|
|
registry.Boolean(True, 'Enable Encyclopedia'))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'database',
|
|
registry.String('ubuntu', 'Name of database to use'))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'relaychannel',
|
|
registry.String('#ubuntu-ops', 'Relay channel for unauthorized edits'))
|
|
|
|
conf.registerGlobalValue(Encyclopedia, 'editchannel',
|
|
registry.SpaceSeparatedListOfStrings(['#ubuntu-ops'],
|
|
'Channels where edits of restricted editors are allowed'))
|
|
|
|
conf.registerGlobalValue(Encyclopedia, 'notfoundmsg',
|
|
registry.String('Factoid %s not found', 'Reply when factoid is not found'))
|
|
|
|
conf.registerChannelValue(Encyclopedia,'prefixchar',
|
|
registry.String('!', 'Character the bot will respond to factoid requests with'))
|
|
|
|
conf.registerGlobalValue(Encyclopedia, 'datadir',
|
|
conf.Directory(conf.supybot.directories.data(), 'Directory containing factoid databases', private=True))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'alert',
|
|
registry.SpaceSeparatedListOfStrings(['ops', 'op', 'kops', 'calltheops'], 'Factoid names used for alerts', private=True))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'remotedb',
|
|
registry.String('https://ubottu.com/ubuntu.db', 'Remote location of the master database', private=True))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'ignores',
|
|
registry.SpaceSeparatedListOfStrings(['info', 'depends', 'find'], 'Factoid names to ignore', private=True))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'repeatdelay',
|
|
registry.Integer(60, "Number of seconds to wait between repeated factoid calls"))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'privateNotFound',
|
|
registry.Boolean(False, "Send notfoundmsg in private rather than in the channel"))
|
|
|
|
conf.registerChannelValue(Encyclopedia, 'forcedFactoid',
|
|
registry.Boolean(False, "Factoids in kick reason will be sent to the user in private"))
|
|
|
|
|
|
conf.registerGlobalValue(Encyclopedia, 'curStable',
|
|
registry.String('Impish', "Current stable release"))
|
|
conf.registerGlobalValue(Encyclopedia, 'curStableLong',
|
|
registry.String('Impish Indri', "Current stable release"))
|
|
conf.registerGlobalValue(Encyclopedia, 'curStableNum',
|
|
registry.String('21.10', "Current stable release"))
|
|
|
|
conf.registerGlobalValue(Encyclopedia, 'curDevel',
|
|
registry.String('Jammy', "Current development release"))
|
|
conf.registerGlobalValue(Encyclopedia, 'curDevelLong',
|
|
registry.String('Jammy Jellyfish', "Current development release"))
|
|
conf.registerGlobalValue(Encyclopedia, 'curDevelNum',
|
|
registry.String('22.04', "Current development release"))
|
|
|
|
conf.registerGlobalValue(Encyclopedia, 'curLTS',
|
|
registry.String('Focal', "Current LTS release"))
|
|
conf.registerGlobalValue(Encyclopedia, 'curLTSLong',
|
|
registry.String('Focal Fossa', "Current LTS release"))
|
|
conf.registerGlobalValue(Encyclopedia, 'curLTSNum',
|
|
registry.String('20.04', "Current LTS release"))
|