1###
2# Copyright (c) 2005, Jeremiah Fincher
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8#   * Redistributions of source code must retain the above copyright notice,
9#     this list of conditions, and the following disclaimer.
10#   * Redistributions in binary form must reproduce the above copyright notice,
11#     this list of conditions, and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#   * Neither the name of the author of this software nor the name of
14#     contributors to this software may be used to endorse or promote products
15#     derived from this software without specific prior written consent.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28###
29
30import supybot.conf as conf
31import supybot.registry as registry
32import supybot.callbacks as callbacks
33from supybot.i18n import PluginInternationalization, internationalizeDocstring
34_ = PluginInternationalization('RSS')
35
36def configure(advanced):
37    # This will be called by supybot to configure this module.  advanced is
38    # a bool that specifies whether the user identified themself as an advanced
39    # user or not.  You should effect your configuration by manipulating the
40    # registry as appropriate.
41    from supybot.questions import expect, anything, something, yn
42    conf.registerPlugin('RSS', True)
43
44
45class FeedNames(registry.SpaceSeparatedListOfStrings):
46    List = callbacks.CanonicalNameSet
47
48class FeedItemSortOrder(registry.OnlySomeStrings):
49    """Valid values include 'asInFeed', 'oldestFirst', 'newestFirst'."""
50    validStrings = ('asInFeed', 'oldestFirst', 'newestFirst', 'outdatedFirst',
51            'updatedFirst')
52
53RSS = conf.registerPlugin('RSS')
54
55conf.registerGlobalValue(RSS, 'feeds',
56    FeedNames([], _("""Determines what feeds should be accessible as
57    commands.""")))
58
59########
60# Format
61
62conf.registerChannelValue(RSS, 'headlineSeparator',
63    registry.StringSurroundedBySpaces('|', _("""Determines what string is
64    used to separate headlines in new feeds.""")))
65conf.registerChannelValue(RSS, 'format',
66    registry.String(_('$date: $title <$link>'), _("""The format the bot
67    will use for displaying headlines of a RSS feed that is triggered
68    manually. In addition to fields defined by feedparser ($published
69    (the entry date), $title, $link, $description, $id, etc.), the following
70    variables can be used: $feed_name, $date (parsed date, as defined in
71    supybot.reply.format.time)""")))
72conf.registerChannelValue(RSS, 'announceFormat',
73    registry.String(_('News from $feed_name: $title <$link>'),
74    _("""The format the bot will use for displaying headlines of a RSS feed
75    that is announced. See supybot.plugins.RSS.format for the available
76    variables.""")))
77
78###########
79# Announces
80
81conf.registerChannelValue(RSS, 'announce',
82    registry.SpaceSeparatedSetOfStrings([], _("""Determines which RSS feeds
83    should be announced in the channel; valid input is a list of strings
84    (either registered RSS feeds or RSS feed URLs) separated by spaces.""")))
85conf.registerGlobalValue(RSS, 'waitPeriod',
86    registry.PositiveInteger(1800, _("""Indicates how many seconds the bot will
87    wait between retrieving RSS feeds; requests made within this period will
88    return cached results.""")))
89conf.registerGlobalValue(RSS, 'sortFeedItems',
90    FeedItemSortOrder('asInFeed', _("""Determines whether feed items should be
91    sorted by their publication/update timestamp or kept in the same order as
92    they appear in a feed.""")))
93conf.registerChannelValue(RSS, 'notice',
94    registry.Boolean(False, _("""Determines whether announces will be sent
95    as notices instead of privmsgs.""")))
96conf.registerChannelValue(RSS, 'maximumAnnounceHeadlines',
97    registry.PositiveInteger(5, _("""Indicates how many new news entries may
98    be sent at the same time. Extra entries will be discarded.""")))
99
100####################
101# Headlines filtering
102conf.registerChannelValue(RSS, 'defaultNumberOfHeadlines',
103    registry.PositiveInteger(1, _("""Indicates how many headlines an rss feed
104    will output by default, if no number is provided.""")))
105conf.registerChannelValue(RSS, 'initialAnnounceHeadlines',
106    registry.Integer(5, _("""Indicates how many headlines an rss feed
107    will output when it is first added to announce for a channel.""")))
108conf.registerChannelValue(RSS, 'keywordWhitelist',
109    registry.SpaceSeparatedSetOfStrings([], _("""Space separated list of
110    strings, lets you filter headlines to those containing one or more items
111    in this whitelist.""")))
112conf.registerChannelValue(RSS, 'keywordBlacklist',
113    registry.SpaceSeparatedSetOfStrings([], _("""Space separated list of
114    strings, lets you filter headlines to those not containing any items
115    in this blacklist.""")))
116
117
118# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
119