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
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
2010-05-24 13:38:06 +00:00
from supybot . utils . str import format
2010-05-28 23:55:07 +00:00
import os
2010-05-24 13:38:06 +00:00
import sqlite
import re
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 )
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 " )
2010-05-28 23:55:07 +00:00
ignores_i = anything ( " Which factoid requets 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 ( ) )
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
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
2010-05-28 22:35:53 +00:00
relaychannel = anything ( " What channel/nick should the bot forward alter messages to? " , default = Encyclopedia . relaychannel . _default )
2010-05-24 13:38:06 +00:00
output ( " What message should the bot reply with when a factoid can not be found? " )
notfoundmsg = something ( " If you include a ' %s ' in the message, it will be replaced with the requested factoid " , default = Encyclopedia . notfoundmsg . _default )
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 = set ( [ ] )
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 . 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 )
if os . path . exists ( os . path . join ( db_dir , db_file + ' .db ' ) ) :
return
con = sqlite . connect ( os . path . join ( db_dir , db_file + ' .db ' ) )
cur = con . cursor ( )
try :
cur . execute ( """ CREATE TABLE facts (
id INTEGER PRIMARY KEY ,
author VARCHAR ( 100 ) NOT NULL ,
name VARCHAR ( 20 ) NOT NULL ,
added DATETIME ,
value VARCHAR ( 200 ) NOT NULL ,
popularity INTEGER NOT NULL DEFAULT 0
) """ )
#"""
cur . execute ( """ CREATE TABLE log (
id INTEGER PRIMARY KEY ,
author VARCHAR ( 100 ) NOT NULL ,
name VARCHAR ( 20 ) NOT NULL ,
added DATETIME ,
oldvalue VARCHAR ( 200 ) 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
Encyclopedia = conf . registerPlugin ( ' Encyclopedia ' )
2010-05-24 13:38:06 +00:00
conf . registerChannelValue ( Encyclopedia , ' enabled ' ,
registry . Boolean ( True , " Enable Encyclopedia " ) )
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 ' ,
registry . SpaceSeparatedListOfStrings ( [ ' #ubuntu-ops ' ] ,
2012-01-30 02:42:11 +00:00
' 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 ' ,
registry . String ( ' Factoid %s not found ' , ' Reply when factoid isn \' t found ' ) )
2010-05-24 13:38:06 +00:00
2007-03-14 20:50:20 +00:00
conf . registerChannelValue ( Encyclopedia , ' prefixchar ' ,
2007-02-04 17:35:40 +00:00
registry . String ( ' ! ' , ' Prefix character for factoid display/editing ' ) )
2010-05-24 13:38:06 +00:00
2007-02-04 17:35:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' datadir ' ,
2010-05-24 13:38:06 +00:00
conf . Directory ( conf . supybot . directories . data ( ) , ' Path to dir containing factoid databases ' , private = True ) )
2008-05-10 15:13:26 +00:00
conf . registerChannelValue ( Encyclopedia , ' alert ' ,
2008-10-22 17:31:40 +00:00
registry . SpaceSeparatedListOfStrings ( [ ' ops ' , ' op ' , ' kops ' , ' calltheops ' ] , ' factoid name(s) 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 ' ,
2009-03-10 05:16:09 +00:00
registry . String ( ' http://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 ' ,
registry . SpaceSeparatedListOfStrings ( [ ' find ' , ' info ' ] , ' factoid name(s) to ignore ' , private = True ) )
2010-05-24 13:38:06 +00:00
2009-11-16 16:43:34 +00:00
conf . registerChannelValue ( Encyclopedia , ' privateNotFound ' ,
registry . Boolean ( False , " If set to True, send notfoundmsg in private rather than in the channel " ) )
2010-10-16 04:20:53 +00:00
conf . registerChannelValue ( Encyclopedia , ' forcedFactoid ' ,
registry . Boolean ( False , " If True, factoids in kick ' s reason will be sent to the user in private " ) )
2010-05-24 13:38:06 +00:00
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curStable ' ,
2011-08-26 06:51:16 +00:00
registry . String ( ' Natty ' , " Current stable release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curStableLong ' ,
2011-08-26 06:51:16 +00:00
registry . String ( ' Natty Narwhal ' , " Current stable release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curStableNum ' ,
2011-08-26 06:51:16 +00:00
registry . String ( ' 11.04 ' , " Current stable release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curDevel ' ,
2011-08-26 06:51:16 +00:00
registry . String ( ' Oneiric ' , " Current development release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curDevelLong ' ,
2011-08-26 06:51:16 +00:00
registry . String ( ' Oneiric Ocelot ' , " Current development release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curDevelNum ' ,
2011-08-26 06:51:16 +00:00
registry . String ( ' 11.10 ' , " Current development release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curLTS ' ,
2010-05-24 13:38:06 +00:00
registry . String ( ' Lucid ' , " Current LTS release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curLTSLong ' ,
2010-05-24 13:38:06 +00:00
registry . String ( ' Lucid Lynx ' , " Current LTS release " ) )
2009-11-22 22:32:40 +00:00
conf . registerGlobalValue ( Encyclopedia , ' curLTSNum ' ,
2010-05-24 13:38:06 +00:00
registry . String ( ' 10.04 ' , " Current LTS release " ) )