forked from jtatum/Encyclopedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
214 lines (179 loc) · 10.2 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# -*- Encoding: utf-8 -*-
###
# Copyright (c) 2006-2007 Dennis Kaarsemaker
# Copyright (c) 2008-2010 Terence Simpson
#
# 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
from supybot.utils.str import format
import os
import sqlite
import re
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)
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 requets should the bot always ignore?", default=', '.join(Encyclopedia.ignores._default))
for name in re.split(r',?\s', ignores_i):
ignores.add(name.lower())
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
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 alter messages to?", default=Encyclopedia.relaychannel._default)
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)
ignorePrefix = yn('Should the bot respond to factoids whether or not its nick or the prefix character is mentioned?', default=Encyclopedia.ignorePrefix._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)
Encyclopedia.ignorePrefix.setValue(ignorePrefix)
# Create the initial database
db_dir = Encyclopedia.datadir()
db_file = Encyclopedia.database()
if not db_dir:
db_dir = conf.supybot.directories.data()
output("supybot.plugins.Encyclopedia.datadir will be set to %r" % db_dir)
Encyclopedia.datadir.setValue(db_dir)
if not db_file:
db_file = 'ubuntu'
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:
cur.close()
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 unauthorised edits are allowed.'))
conf.registerGlobalValue(Encyclopedia, 'notfoundmsg',
registry.String('Factoid %s not found', 'Reply when factoid isn\'t found'))
conf.registerChannelValue(Encyclopedia,'prefixchar',
registry.String('!','Prefix character for factoid display/editing'))
conf.registerGlobalValue(Encyclopedia, 'datadir',
conf.Directory(conf.supybot.directories.data(), 'Path to dir containing factoid databases', private=True))
conf.registerChannelValue(Encyclopedia, 'alert',
registry.SpaceSeparatedListOfStrings(['ops', 'op', 'kops', 'calltheops'], 'factoid name(s) used for alerts', private=True))
conf.registerChannelValue(Encyclopedia, 'remotedb',
registry.String('http://ubottu.com/ubuntu.db', 'Remote location of the master database', private=True))
conf.registerChannelValue(Encyclopedia, 'ignores',
registry.SpaceSeparatedListOfStrings(['find', 'info'], 'factoid name(s) to ignore', private=True))
conf.registerChannelValue(Encyclopedia, 'privateNotFound',
registry.Boolean(False, "If set to True, send notfoundmsg in private rather than in the channel"))
conf.registerChannelValue(Encyclopedia, 'ignorePrefix',
registry.Boolean(False, 'If True, this setting will try to match factoids and edits from regular channel text, regardless of whether the bot nick or prefix character is mentioned or not.'))
conf.registerChannelValue(Encyclopedia, 'forcedFactoid',
registry.Boolean(False, "If True, factoids in kick's reason will be sent to the user in private"))
conf.registerGlobalValue(Encyclopedia, 'curStable',
registry.String('Lucid', "Current stable release"))
conf.registerGlobalValue(Encyclopedia, 'curStableLong',
registry.String('Lucid Lynx', "Current stable release"))
conf.registerGlobalValue(Encyclopedia, 'curStableNum',
registry.String('10.04', "Current stable release"))
conf.registerGlobalValue(Encyclopedia, 'curDevel',
registry.String('Maverick', "Current development release"))
conf.registerGlobalValue(Encyclopedia, 'curDevelLong',
registry.String('Maverick Meerkat', "Current development release"))
conf.registerGlobalValue(Encyclopedia, 'curDevelNum',
registry.String('10.10', "Current development release"))
conf.registerGlobalValue(Encyclopedia, 'curLTS',
registry.String('Lucid', "Current LTS release"))
conf.registerGlobalValue(Encyclopedia, 'curLTSLong',
registry.String('Lucid Lynx', "Current LTS release"))
conf.registerGlobalValue(Encyclopedia, 'curLTSNum',
registry.String('10.04', "Current LTS release"))