2010-05-24 13:38:06 +00:00
# -*- Encoding: utf-8 -*-
2006-06-26 17:57:20 +00:00
###
2007-02-04 17:35:40 +00:00
# Copyright (c) 2006-2007 Dennis Kaarsemaker
2010-05-24 13:38:06 +00:00
# Copyright (c) 2008-2010 Terence Simpson
2018-03-09 18:56:04 +00:00
# Copyright (c) 2018- Krytarik Raido
2006-06-26 17:57:20 +00:00
#
2007-02-04 17:35:40 +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
def configure ( advanced ) :
2010-05-28 22:51:28 +00:00
from supybot . questions import yn , something , output
2018-05-21 22:45:04 +00:00
import os , re , sqlite3
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-24 13:38:06 +00:00
Encyclopedia = conf . registerPlugin ( ' Encyclopedia ' , True )
2021-12-02 21:13:04 +00:00
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
2010-05-24 13:38:06 +00:00
enabled = yn ( " Enable Encyclopedia for all channels? " , default = Encyclopedia . enabled . _default )
2021-12-02 21:13:04 +00:00
2010-05-24 13:38:06 +00:00
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 " )
2018-05-21 22:45:04 +00:00
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 ) :
2010-05-24 13:38:06 +00:00
ignores . add ( name . lower ( ) )
2021-12-02 21:13:04 +00:00
repeatdelay = getRepeatdelay ( )
2010-05-24 13:38:06 +00:00
2010-05-28 23:55:07 +00:00
curStable = something ( " What is short name of the current stable release? " , default = Encyclopedia . curStable . _default )
2010-05-24 13:38:06 +00:00
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 )
2010-05-28 23:55:07 +00:00
curLTSLong = something ( " What is long name of the current LTS release? " , default = Encyclopedia . curLTSLong . _default )
2010-05-24 13:38:06 +00:00
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
2021-12-02 21:13:04 +00:00
repeatdelay = Encyclopedia . repeatdelay . _default
2010-05-28 23:55:07 +00:00
curStable = Encyclopedia . curStable . _default
2010-05-24 13:38:06 +00:00
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
2018-05-21 22:45:04 +00:00
relaychannel = anything ( " What channel/nick should the bot forward edit messages to? " , default = Encyclopedia . relaychannel . _default )
2021-12-02 21:13:04 +00:00
output ( " What message should the bot reply with when a factoid cannot be found? " )
2010-05-24 13:38:06 +00:00
notfoundmsg = something ( " If you include a ' %s ' in the message, it will be replaced with the requested factoid " , default = Encyclopedia . notfoundmsg . _default )
2018-05-21 22:45:04 +00:00
alert = set ( [ ] )
2010-05-24 13:38:06 +00:00
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 ) )
2018-05-21 22:45:04 +00:00
for name in re . split ( r ' [, \ s]+ ' , alert_i ) :
2010-05-24 13:38:06 +00:00
alert . add ( name . lower ( ) )
2018-05-21 22:45:04 +00:00
remotedb = anything ( " Location of a remote database to sync with (used with @sync): " , default = Encyclopedia . remotedb . _default )
2010-05-24 13:38:06 +00:00
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 )
2021-12-02 21:13:04 +00:00
Encyclopedia . remotedb . setValue ( remotedb )
2010-05-24 13:38:06 +00:00
Encyclopedia . privateNotFound . setValue ( privateNotFound )
# Create the initial database
db_dir = Encyclopedia . datadir ( )
db_file = Encyclopedia . database ( )
if not db_dir :
2011-05-28 06:33:21 +00:00
db_dir = Encyclopedia . datadir . _default
2010-05-24 13:38:06 +00:00
output ( " supybot.plugins.Encyclopedia.datadir will be set to %r " % db_dir )
Encyclopedia . datadir . setValue ( db_dir )
if not db_file :
2011-05-28 06:33:21 +00:00
db_file = Encyclopedia . database . _default
2010-05-24 13:38:06 +00:00
output ( " supybot.plugins.Encyclopedia.database will be set to %r " % db_file )
Encyclopedia . database . setValue ( db_dir )
2018-03-09 18:56:04 +00:00
if os . path . exists ( os . path . join ( db_dir , ' %s .db ' % db_file ) ) :
2010-05-24 13:38:06 +00:00
return
2018-03-09 18:56:04 +00:00
con = sqlite3 . connect ( os . path . join ( db_dir , ' %s .db ' % db_file ) )
2010-05-24 13:38:06 +00:00
cur = con . cursor ( )
try :
cur . execute ( """ CREATE TABLE facts (
2018-03-09 18:56:04 +00:00
id INTEGER PRIMARY KEY ,
name TEXT NOT NULL ,
value TEXT NOT NULL ,
2018-05-21 22:45:04 +00:00
author TEXT NOT NULL ,
added TEXT NOT NULL ,
2018-03-22 20:34:04 +00:00
editor TEXT ,
edited TEXT ,
2018-03-09 18:56:04 +00:00
popularity INTEGER NOT NULL DEFAULT 0
) """ )
2010-05-24 13:38:06 +00:00
cur . execute ( """ CREATE TABLE log (
2018-03-09 18:56:04 +00:00
id INTEGER PRIMARY KEY ,
2018-03-22 20:34:04 +00:00
type TEXT NOT NULL ,
2018-03-09 18:56:04 +00:00
name TEXT NOT NULL ,
2018-03-22 20:34:04 +00:00
value TEXT NOT NULL ,
2018-05-21 22:45:04 +00:00
author TEXT NOT NULL ,
added TEXT NOT NULL
2018-03-09 18:56:04 +00:00
) """ )
2010-05-24 13:38:06 +00:00
2018-03-22 20:34:04 +00:00
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
) """ )
2010-05-24 13:38:06 +00:00
except :
con . rollback ( )
raise
else :
con . commit ( )
finally :
con . close ( )
2006-06-26 17:57:20 +00:00
Encyclopedia = conf . registerPlugin ( ' Encyclopedia ' )
2010-05-24 13:38:06 +00:00
conf . registerChannelValue ( Encyclopedia , ' enabled ' ,
2018-05-21 22:45:04 +00:00
registry . Boolean ( True , ' Enable Encyclopedia ' ) )
2010-05-24 13:38:06 +00:00
2006-06-26 17:57:20 +00:00
conf . registerChannelValue ( Encyclopedia , ' database ' ,
2008-08-07 11:37:25 +00:00
registry . String ( ' ubuntu ' , ' Name of database to use ' ) )
2010-05-24 13:38:06 +00:00
2008-05-10 15:13:26 +00:00
conf . registerChannelValue ( Encyclopedia , ' relaychannel ' ,
2006-09-28 12:35:24 +00:00
registry . String ( ' #ubuntu-ops ' , ' Relay channel for unauthorized edits ' ) )
2010-05-24 13:38:06 +00:00
2010-12-12 16:33:52 +00:00
conf . registerGlobalValue ( Encyclopedia , ' editchannel ' ,
2018-05-21 22:45:04 +00:00
registry . SpaceSeparatedListOfStrings ( [ ' #ubuntu-ops ' ] ,
' Channels where edits of restricted editors are allowed ' ) )
2010-12-12 16:33:52 +00:00
2006-10-03 00:05:56 +00:00
conf . registerGlobalValue ( Encyclopedia , ' notfoundmsg ' ,
2018-05-21 22:45:04 +00:00
registry . String ( ' Factoid %s not found ' , ' Reply when factoid is not found ' ) )
2010-05-24 13:38:06 +00:00
2007-03-14 20:50:20 +00:00
conf . registerChannelValue ( Encyclopedia , ' prefixchar ' ,
2021-06-12 10:34:04 +00:00
registry . String ( ' ! ' , ' Character the bot will respond to factoid requests with ' ) )
2010-05-24 13:38:06 +00:00
2007-02-04 17:35:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' datadir ' ,
2021-06-12 10:34:04 +00:00
conf . Directory ( conf . supybot . directories . data ( ) , ' Directory containing factoid databases ' , private = True ) )
2010-05-24 13:38:06 +00:00
2008-05-10 15:13:26 +00:00
conf . registerChannelValue ( Encyclopedia , ' alert ' ,
2018-05-21 22:45:04 +00:00
registry . SpaceSeparatedListOfStrings ( [ ' ops ' , ' op ' , ' kops ' , ' calltheops ' ] , ' Factoid names used for alerts ' , private = True ) )
2010-05-24 13:38:06 +00:00
2008-08-07 11:37:25 +00:00
conf . registerChannelValue ( Encyclopedia , ' remotedb ' ,
2018-05-21 22:45:04 +00:00
registry . String ( ' https://ubottu.com/ubuntu.db ' , ' Remote location of the master database ' , private = True ) )
2010-05-24 13:38:06 +00:00
2008-10-22 17:31:40 +00:00
conf . registerChannelValue ( Encyclopedia , ' ignores ' ,
2018-05-21 22:45:04 +00:00
registry . SpaceSeparatedListOfStrings ( [ ' info ' , ' depends ' , ' find ' ] , ' Factoid names to ignore ' , private = True ) )
2010-05-24 13:38:06 +00:00
2021-12-02 21:13:04 +00:00
conf . registerChannelValue ( Encyclopedia , ' repeatdelay ' ,
registry . Integer ( 60 , " Number of seconds to wait between repeated factoid calls " ) )
2009-11-16 16:43:34 +00:00
conf . registerChannelValue ( Encyclopedia , ' privateNotFound ' ,
2021-06-12 10:34:04 +00:00
registry . Boolean ( False , " Send notfoundmsg in private rather than in the channel " ) )
2009-11-16 16:43:34 +00:00
2010-10-16 04:20:53 +00:00
conf . registerChannelValue ( Encyclopedia , ' forcedFactoid ' ,
2021-06-12 10:34:04 +00:00
registry . Boolean ( False , " Factoids in kick reason will be sent to the user in private " ) )
2010-10-16 04:20:53 +00:00
2010-05-24 13:38:06 +00:00
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curStable ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' Impish ' , " Current stable release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curStableLong ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' Impish Indri ' , " Current stable release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curStableNum ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' 21.10 ' , " Current stable release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curDevel ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' Jammy ' , " Current development release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curDevelLong ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' Jammy Jellyfish ' , " Current development release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curDevelNum ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' 22.04 ' , " Current development release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curLTS ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' Focal ' , " Current LTS release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curLTSLong ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' Focal Fossa ' , " Current LTS release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curLTSNum ' ,
2021-12-02 21:13:04 +00:00
registry . String ( ' 20.04 ' , " Current LTS release " ) )