mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 15:44:06 +01:00
Add/update supybot.databases.plugins.channelSpecific{,.link{,.allow}}
channelSpecific.link replaces channelSpecific.channel
This commit is contained in:
parent
0fe82001d5
commit
225c565aee
@ -158,10 +158,10 @@ class DBHandler(object):
|
|||||||
|
|
||||||
|
|
||||||
def makeChannelFilename(filename, channel=None, dirname=None):
|
def makeChannelFilename(filename, channel=None, dirname=None):
|
||||||
|
assert channel is not None, 'Death to those who use None for their channel'
|
||||||
filename = os.path.basename(filename)
|
filename = os.path.basename(filename)
|
||||||
if channel is None or \
|
channelSpecific = conf.supybot.databases.plugins.channelSpecific
|
||||||
not conf.get(conf.supybot.databases.plugins.channelSpecific, channel):
|
channel = channelSpecific.getChannelLink(channel)
|
||||||
channel = conf.supybot.databases.plugins.channelSpecific.channel()
|
|
||||||
channel = ircutils.toLower(channel)
|
channel = ircutils.toLower(channel)
|
||||||
if dirname is None:
|
if dirname is None:
|
||||||
dirname = conf.supybot.directories.data.dirize(channel)
|
dirname = conf.supybot.directories.data.dirize(channel)
|
||||||
@ -170,10 +170,9 @@ def makeChannelFilename(filename, channel=None, dirname=None):
|
|||||||
return os.path.join(dirname, filename)
|
return os.path.join(dirname, filename)
|
||||||
|
|
||||||
def getChannel(channel):
|
def getChannel(channel):
|
||||||
|
assert channel is not None, 'Death to those who use None for their channel'
|
||||||
channelSpecific = conf.supybot.databases.plugins.channelSpecific
|
channelSpecific = conf.supybot.databases.plugins.channelSpecific
|
||||||
if not conf.get(channelSpecific, channel):
|
return channelSpecific.getChannelLink(channel)
|
||||||
channel = conf.get(channelSpecific.channel, channel)
|
|
||||||
return channel
|
|
||||||
|
|
||||||
# XXX This shouldn't be a mixin. This should be contained by classes that
|
# XXX This shouldn't be a mixin. This should be contained by classes that
|
||||||
# want such behavior. But at this point, it wouldn't gain much for us
|
# want such behavior. But at this point, it wouldn't gain much for us
|
||||||
|
@ -361,14 +361,21 @@ def getChannelDb(irc, msg, args, state, **kwargs):
|
|||||||
channelSpecific = conf.supybot.databases.plugins.channelSpecific
|
channelSpecific = conf.supybot.databases.plugins.channelSpecific
|
||||||
try:
|
try:
|
||||||
getChannel(irc, msg, args, state, **kwargs)
|
getChannel(irc, msg, args, state, **kwargs)
|
||||||
if state.channel and not conf.get(channelSpecific, state.channel):
|
channel = channelSpecific.getChannelLink(state.channel)
|
||||||
state.channel = conf.get(channelSpecific.channel, state.channel)
|
state.channel = channel
|
||||||
|
state.args[-1] = channel
|
||||||
except (callbacks.ArgumentError, IndexError):
|
except (callbacks.ArgumentError, IndexError):
|
||||||
if channelSpecific():
|
if channelSpecific():
|
||||||
raise
|
raise
|
||||||
|
channel = channelSpecific.link()
|
||||||
|
if not conf.get(channelSpecific.link.allow, channel):
|
||||||
|
log.warning('channelSpecific.link is globally set to %s, but '
|
||||||
|
'%s disallows linking to its db.' % (channel, channel))
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
state.channel = channelSpecific.channel()
|
channel = channelSpecific.getChannelLink(channel)
|
||||||
state.args.append(state.channel)
|
state.channel = channel
|
||||||
|
state.args.append(channel)
|
||||||
|
|
||||||
def inChannel(irc, msg, args, state):
|
def inChannel(irc, msg, args, state):
|
||||||
if not state.channel:
|
if not state.channel:
|
||||||
|
68
src/conf.py
68
src/conf.py
@ -417,9 +417,9 @@ registerChannelValue(supybot.reply.whenAddressedBy, 'chars',
|
|||||||
reply to. A prefix character is a single character that the bot will use
|
reply to. A prefix character is a single character that the bot will use
|
||||||
to determine what messages are addressed to it; when there are no prefix
|
to determine what messages are addressed to it; when there are no prefix
|
||||||
characters set, it just uses its nick. Each character in this string is
|
characters set, it just uses its nick. Each character in this string is
|
||||||
interpreted individually; you can have multiple prefix chars simultaneously,
|
interpreted individually; you can have multiple prefix chars
|
||||||
and if any one of them is used as a prefix the bot will assume it is being
|
simultaneously, and if any one of them is used as a prefix the bot will
|
||||||
addressed."""))
|
assume it is being addressed."""))
|
||||||
|
|
||||||
registerChannelValue(supybot.reply.whenAddressedBy, 'strings',
|
registerChannelValue(supybot.reply.whenAddressedBy, 'strings',
|
||||||
registry.SpaceSeparatedSetOfStrings([], """Determines what strings the bot
|
registry.SpaceSeparatedSetOfStrings([], """Determines what strings the bot
|
||||||
@ -432,9 +432,9 @@ registerChannelValue(supybot.reply.whenAddressedBy, 'nick',
|
|||||||
registry.Boolean(True, """Determines whether the bot will reply when people
|
registry.Boolean(True, """Determines whether the bot will reply when people
|
||||||
address it by its nick, rather than with a prefix character."""))
|
address it by its nick, rather than with a prefix character."""))
|
||||||
registerChannelValue(supybot.reply.whenAddressedBy.nick, 'atEnd',
|
registerChannelValue(supybot.reply.whenAddressedBy.nick, 'atEnd',
|
||||||
registry.Boolean(False, """Determines whether the bot will reply when people
|
registry.Boolean(False, """Determines whether the bot will reply when
|
||||||
address it by its nick at the end of the message, rather than at the
|
people address it by its nick at the end of the message, rather than at
|
||||||
beginning."""))
|
the beginning."""))
|
||||||
registerChannelValue(supybot.reply.whenAddressedBy, 'nicks',
|
registerChannelValue(supybot.reply.whenAddressedBy, 'nicks',
|
||||||
registry.SpaceSeparatedSetOfStrings([], """Determines what extra nicks the
|
registry.SpaceSeparatedSetOfStrings([], """Determines what extra nicks the
|
||||||
bot will always respond to when addressed by, even if its current nick is
|
bot will always respond to when addressed by, even if its current nick is
|
||||||
@ -790,19 +790,55 @@ registerGlobalValue(supybot.databases.channels, 'filename',
|
|||||||
for the channels database. This file will go into the directory specified
|
for the channels database. This file will go into the directory specified
|
||||||
by the supybot.directories.conf variable."""))
|
by the supybot.directories.conf variable."""))
|
||||||
|
|
||||||
|
# TODO This will need to do more in the future (such as making sure link.allow
|
||||||
|
# will let the link occur), but for now let's just leave it as this.
|
||||||
|
class ChannelSpecific(registry.Boolean):
|
||||||
|
def getChannelLink(self, channel):
|
||||||
|
channelSpecific = supybot.databases.plugins.channelSpecific
|
||||||
|
channels = [channel]
|
||||||
|
def hasLinkChannel(channel):
|
||||||
|
if not get(channelSpecific, channel):
|
||||||
|
lchannel = get(channelSpecific.link, channel)
|
||||||
|
if not get(channelSpecific.link.allow, lchannel):
|
||||||
|
return False
|
||||||
|
return channel != lchannel
|
||||||
|
return False
|
||||||
|
lchannel = channel
|
||||||
|
while hasLinkChannel(lchannel):
|
||||||
|
if lchannel not in channels:
|
||||||
|
channels.append(lchannel)
|
||||||
|
lchannel = get(channelSpecific.link, lchannel)
|
||||||
|
else:
|
||||||
|
# Found a cyclic link. We'll just use the current channel
|
||||||
|
lchannel = channel
|
||||||
|
break
|
||||||
|
return lchannel
|
||||||
|
|
||||||
registerGroup(supybot.databases, 'plugins')
|
registerGroup(supybot.databases, 'plugins')
|
||||||
registerChannelValue(supybot.databases.plugins, 'channelSpecific',
|
registerChannelValue(supybot.databases.plugins, 'channelSpecific',
|
||||||
registry.Boolean(True, """Determines whether database-based plugins that
|
ChannelSpecific(True, """Determines whether database-based plugins that
|
||||||
can be channel-specific will be so. This can be overridden by individual
|
can be channel-specific will be so. This can be overridden by individual
|
||||||
channels. Do note that the bot likely needs to be restarted for changes of
|
channels. Do note that the bot needs to be restarted immediately after
|
||||||
this variable to take effect; also note that you may wish to set
|
changing this variable or your db plugins may not work for your channel;
|
||||||
supybot.databases.plugins.channelSpecific.channel appropriately if you
|
also note that you may wish to set
|
||||||
wish to share a certain channel's databases globally."""))
|
supybot.databases.plugins.channelSpecific.link appropriately if you wish
|
||||||
registerChannelValue(supybot.databases.plugins.channelSpecific, 'channel',
|
to share a certain channel's databases globally."""))
|
||||||
|
registerChannelValue(supybot.databases.plugins.channelSpecific, 'link',
|
||||||
ValidChannel('#', """Determines what channel global (non-channel-specific)
|
ValidChannel('#', """Determines what channel global (non-channel-specific)
|
||||||
databases will be considered a part of. This is helpful if you've been
|
databases will be considered a part of. This is helpful if you've been
|
||||||
running channel-specific for awhile and want to turn the databases for your
|
running channel-specific for awhile and want to turn the databases for
|
||||||
primary channel into global databases."""))
|
your primary channel into global databases. If
|
||||||
|
supybot.databases.plugins.channelSpecific.link.allow prevents linking, the
|
||||||
|
current channel will be used. Do note that the bot needs to be restarted
|
||||||
|
immediately after changing this variable or your db plugins may not work
|
||||||
|
for your channel."""))
|
||||||
|
registerChannelValue(supybot.databases.plugins.channelSpecific.link, 'allow',
|
||||||
|
registry.Boolean(True, """Determines whether another channel's global
|
||||||
|
(non-channel-specific) databases will be allowed to link to this channel's
|
||||||
|
databases. Do note that the bot needs to be restarted immediately after
|
||||||
|
changing this variable or your db plugins may not work for your channel.
|
||||||
|
"""))
|
||||||
|
|
||||||
|
|
||||||
class CDB(registry.Boolean):
|
class CDB(registry.Boolean):
|
||||||
def connect(self, filename):
|
def connect(self, filename):
|
||||||
@ -884,8 +920,8 @@ registerGlobalValue(supybot.protocols.irc, 'queueDuplicateMessages',
|
|||||||
registry.Boolean(False, """Determines whether the bot will allow duplicate
|
registry.Boolean(False, """Determines whether the bot will allow duplicate
|
||||||
messages to be queued for delivery to the server. This is a safety
|
messages to be queued for delivery to the server. This is a safety
|
||||||
mechanism put in place to prevent plugins from sending the same message
|
mechanism put in place to prevent plugins from sending the same message
|
||||||
multiple times; most of the time it doesn't matter, but when it does, you'll
|
multiple times; most of the time it doesn't matter, but when it does,
|
||||||
probably want it to disallowed."""))
|
you'll probably want it to disallowed."""))
|
||||||
|
|
||||||
###
|
###
|
||||||
# supybot.protocols.http
|
# supybot.protocols.http
|
||||||
|
Loading…
Reference in New Issue
Block a user