~ubuntu-ru-irc/+junk/irckit

« back to all changes in this revision

Viewing changes to ubuntuhelp/ubuntubot/plugins/Encyclopedia/config.py

  • Committer: rmPIC30 at gmail
  • Date: 2010-07-13 09:08:58 UTC
  • Revision ID: rmpic30@gmail.com-20100713090858-w5kkmk093hx38cen
Добавляю бота

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Encoding: utf-8 -*-
 
2
###
 
3
# Copyright (c) 2006-2007 Dennis Kaarsemaker
 
4
# Copyright (c) 2008-2010 Terence Simpson
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of version 2 of the GNU General Public License as
 
8
# published by the Free Software Foundation.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
###
 
16
 
 
17
import supybot.conf as conf
 
18
import supybot.registry as registry
 
19
 
 
20
def configure(advanced):
 
21
    from supybot.questions import yn, something, output
 
22
    from supybot.utils.str import format
 
23
    import os
 
24
    import sqlite
 
25
    import re
 
26
 
 
27
    def anything(prompt, default=None):
 
28
        """Because supybot is pure fail"""
 
29
        from supybot.questions import expect
 
30
        return expect(prompt, [], default=default)
 
31
 
 
32
    Encyclopedia = conf.registerPlugin('Encyclopedia', True)
 
33
 
 
34
    enabled = yn("Enable Encyclopedia for all channels?", default=Encyclopedia.enabled._default)
 
35
    if advanced:
 
36
        datadir = something("Which directory should the factoids database be in?", default=Encyclopedia.datadir._default)
 
37
        database = something("What should be the name of the default database (without the .db extension)?", default=Encyclopedia.database._default)
 
38
        prefixchar = something("What prefix character should the bot respond to factoid requests with?", default=Encyclopedia.prefixchar._default)
 
39
        ignores = set([])
 
40
        output("This plugin can be configured to always ignore certain factoid requests, this is useful when you want another plugin to handle them")
 
41
        output("For instance, the PackageInfo plugin responds to !info and !find, so those should be ignored in Encyclopedia to allow this to work")
 
42
        ignores_i = anything("Which factoid requets should the bot always ignore?", default=', '.join(Encyclopedia.ignores._default))
 
43
        for name in re.split(r',?\s', ignores_i):
 
44
            ignores.add(name.lower())
 
45
 
 
46
        curStable = something("What is short name of the current stable release?", default=Encyclopedia.curStable._default)
 
47
        curStableLong = something("What is long name of the current stable release?", default=Encyclopedia.curStableLong._default)
 
48
        curStableNum = something("What is version number of the current stable release?", default=Encyclopedia.curStableNum._default)
 
49
 
 
50
        curDevel = something("What is short name of the current development release?", default=Encyclopedia.curDevel._default)
 
51
        curDevelLong = something("What is long name of the current development release?", default=Encyclopedia.curDevelLong._default)
 
52
        curDevelNum = something("What is version number of the current development release?", default=Encyclopedia.curDevelNum._default)
 
53
 
 
54
        curLTS = something("What is short name of the current LTS release?", default=Encyclopedia.curLTS._default)
 
55
        curLTSLong = something("What is long name of the current LTS release?", default=Encyclopedia.curLTSLong._default)
 
56
        curLTSNum = something("What is version number of the current LTS release?", default=Encyclopedia.curLTSNum._default)
 
57
    else:
 
58
        datadir = Encyclopedia.datadir._default
 
59
        database = Encyclopedia.database._default
 
60
        prefixchar = Encyclopedia.prefixchar._default
 
61
        ignores = Encyclopedia.ignores._default
 
62
        curStable = Encyclopedia.curStable._default
 
63
        curStableLong = Encyclopedia.curStableLong._default
 
64
        curStableNum = Encyclopedia.curStableNum._default
 
65
        curDevel = Encyclopedia.curDevel._default
 
66
        curDevelLong = Encyclopedia.curDevelLong._default
 
67
        curDevelNum = Encyclopedia.curDevelNum._default
 
68
        curLTS = Encyclopedia.curLTS._default
 
69
        curLTSLong = Encyclopedia.curLTSLong._default
 
70
        curLTSNum = Encyclopedia.curLTSNum._default
 
71
 
 
72
    relaychannel = anything("What channel/nick should the bot forward alter messages to?", default=Encyclopedia.relaychannel._default)
 
73
    output("What message should the bot reply with when a factoid can not be found?")
 
74
    notfoundmsg = something("If you include a '%s' in the message, it will be replaced with the requested factoid", default=Encyclopedia.notfoundmsg._default)
 
75
    output("When certain factoids are called an alert can be forwarded to a channel/nick")
 
76
    output("Which factoids should the bot forward alert calls for?")
 
77
    alert = set([])
 
78
    alert_i = anything("Separate types by spaces or commas:", default=', '.join(Encyclopedia.alert._default))
 
79
    for name in re.split(r',?\s+', alert_i):
 
80
        alert.add(name.lower())
 
81
    remotedb = anything("Location of a remote database to sync with (used with @sync)", default=Encyclopedia.remotedb._default)
 
82
    privateNotFound = yn("Should the bot reply in private when a factoid is not found, as opposed to in the channel?", default=Encyclopedia.privateNotFound._default)
 
83
 
 
84
    Encyclopedia.enabled.setValue(enabled)
 
85
    Encyclopedia.datadir.setValue(datadir)
 
86
    Encyclopedia.database.setValue(database)
 
87
    Encyclopedia.prefixchar.setValue(prefixchar)
 
88
    Encyclopedia.ignores.setValue(ignores)
 
89
    Encyclopedia.curStable.setValue(curStable)
 
90
    Encyclopedia.curStableLong.setValue(curStableLong)
 
91
    Encyclopedia.curStableNum.setValue(curStableNum)
 
92
    Encyclopedia.curDevel.setValue(curDevel)
 
93
    Encyclopedia.curDevelLong.setValue(curDevelLong)
 
94
    Encyclopedia.curDevelNum.setValue(curDevelNum)
 
95
    Encyclopedia.curLTS.setValue(curLTS)
 
96
    Encyclopedia.curLTSLong.setValue(curLTSLong)
 
97
    Encyclopedia.curLTSNum.setValue(curLTSNum)
 
98
    Encyclopedia.relaychannel.setValue(relaychannel)
 
99
    Encyclopedia.notfoundmsg.setValue(notfoundmsg)
 
100
    Encyclopedia.alert.setValue(alert)
 
101
    Encyclopedia.privateNotFound.setValue(privateNotFound)
 
102
 
 
103
    # Create the initial database
 
104
    db_dir = Encyclopedia.datadir()
 
105
    db_file = Encyclopedia.database()
 
106
 
 
107
    if not db_dir:
 
108
        db_dir = conf.supybot.directories.data()
 
109
        output("supybot.plugins.Encyclopedia.datadir will be set to %r" % db_dir)
 
110
        Encyclopedia.datadir.setValue(db_dir)
 
111
 
 
112
    if not db_file:
 
113
        db_file = 'ubuntu'
 
114
        output("supybot.plugins.Encyclopedia.database will be set to %r" % db_file)
 
115
        Encyclopedia.database.setValue(db_dir)
 
116
 
 
117
    if os.path.exists(os.path.join(db_dir, db_file + '.db')):
 
118
        return
 
119
 
 
120
    con = sqlite.connect(os.path.join(db_dir, db_file + '.db'))
 
121
    cur = con.cursor()
 
122
 
 
123
    try:
 
124
        cur.execute("""CREATE TABLE facts (
 
125
    id INTEGER PRIMARY KEY,
 
126
    author VARCHAR(100) NOT NULL,
 
127
    name VARCHAR(20) NOT NULL,
 
128
    added DATETIME,
 
129
    value VARCHAR(200) NOT NULL,
 
130
    popularity INTEGER NOT NULL DEFAULT 0
 
131
)""")
 
132
#"""
 
133
        cur.execute("""CREATE TABLE log (
 
134
    id INTEGER PRIMARY KEY,
 
135
    author VARCHAR(100) NOT NULL,
 
136
    name VARCHAR(20) NOT NULL,
 
137
    added DATETIME,
 
138
    oldvalue VARCHAR(200) NOT NULL
 
139
)""")
 
140
 
 
141
    except:
 
142
        con.rollback()
 
143
        raise
 
144
    else:
 
145
        con.commit()
 
146
    finally:
 
147
        cur.close()
 
148
        con.close()
 
149
 
 
150
Encyclopedia = conf.registerPlugin('Encyclopedia')
 
151
 
 
152
conf.registerChannelValue(Encyclopedia, 'enabled',
 
153
    registry.Boolean(True, "Enable Encyclopedia"))
 
154
 
 
155
conf.registerChannelValue(Encyclopedia, 'database',
 
156
    registry.String('ubuntu', 'Name of database to use'))
 
157
 
 
158
conf.registerChannelValue(Encyclopedia, 'relaychannel',
 
159
    registry.String('#ubuntu-ops', 'Relay channel for unauthorized edits'))
 
160
 
 
161
conf.registerGlobalValue(Encyclopedia, 'notfoundmsg',
 
162
    registry.String('Factoid %s not found', 'Reply when factoid isn\'t found'))
 
163
 
 
164
conf.registerChannelValue(Encyclopedia,'prefixchar',
 
165
    registry.String('!','Prefix character for factoid display/editing'))
 
166
 
 
167
conf.registerGlobalValue(Encyclopedia, 'datadir',
 
168
    conf.Directory(conf.supybot.directories.data(), 'Path to dir containing factoid databases', private=True))
 
169
 
 
170
conf.registerChannelValue(Encyclopedia, 'alert',
 
171
    registry.SpaceSeparatedListOfStrings(['ops', 'op', 'kops', 'calltheops'], 'factoid name(s) used for alerts', private=True))
 
172
 
 
173
conf.registerChannelValue(Encyclopedia, 'remotedb',
 
174
    registry.String('http://ubottu.com/ubuntu.db', 'Remote location of the master database', private=True))
 
175
 
 
176
conf.registerChannelValue(Encyclopedia, 'ignores',
 
177
    registry.SpaceSeparatedListOfStrings(['find', 'info'], 'factoid name(s) to ignore', private=True))
 
178
 
 
179
conf.registerChannelValue(Encyclopedia, 'privateNotFound',
 
180
    registry.Boolean(False, "If set to True, send notfoundmsg in private rather than in the channel"))
 
181
 
 
182
 
 
183
conf.registerGlobalValue(Encyclopedia, 'curStable',
 
184
    registry.String('Lucid', "Current stable release"))
 
185
conf.registerGlobalValue(Encyclopedia, 'curStableLong',
 
186
    registry.String('Lucid Lynx', "Current stable release"))
 
187
conf.registerGlobalValue(Encyclopedia, 'curStableNum',
 
188
    registry.String('10.04', "Current stable release"))
 
189
 
 
190
conf.registerGlobalValue(Encyclopedia, 'curDevel',
 
191
    registry.String('Maverick', "Current development release"))
 
192
conf.registerGlobalValue(Encyclopedia, 'curDevelLong',
 
193
    registry.String('Maverick Meerkat', "Current development release"))
 
194
conf.registerGlobalValue(Encyclopedia, 'curDevelNum',
 
195
    registry.String('10.10', "Current development release"))
 
196
 
 
197
conf.registerGlobalValue(Encyclopedia, 'curLTS',
 
198
    registry.String('Lucid', "Current LTS release"))
 
199
conf.registerGlobalValue(Encyclopedia, 'curLTSLong',
 
200
    registry.String('Lucid Lynx', "Current LTS release"))
 
201
conf.registerGlobalValue(Encyclopedia, 'curLTSNum',
 
202
    registry.String('10.04', "Current LTS release"))