mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-22 02:32:42 +01:00
Topic: run autopep8 on plugin.py
This commit is contained in:
parent
4f38958b70
commit
cef54fcfa3
@ -49,6 +49,7 @@ _ = PluginInternationalization('Topic')
|
||||
|
||||
import supybot.ircdb as ircdb
|
||||
|
||||
|
||||
def canChangeTopic(irc, msg, args, state):
|
||||
assert not state.channel
|
||||
callConverter('channel', irc, msg, args, state)
|
||||
@ -59,12 +60,13 @@ def canChangeTopic(irc, msg, args, state):
|
||||
c = irc.state.channels[state.channel]
|
||||
if 't' in c.modes and not c.isHalfopPlus(irc.nick):
|
||||
state.error(format(_('I can\'t change the topic, I\'m not (half)opped '
|
||||
'and %s is +t.'), state.channel), Raise=True)
|
||||
'and %s is +t.'), state.channel), Raise=True)
|
||||
|
||||
|
||||
def getTopic(irc, msg, args, state, format=True):
|
||||
separator = state.cb.registryValue('separator', state.channel)
|
||||
if separator in args[0] and not \
|
||||
state.cb.registryValue('allowSeparatorinTopics', state.channel):
|
||||
state.cb.registryValue('allowSeparatorinTopics', state.channel):
|
||||
state.errorInvalid('topic', args[0],
|
||||
format(_('The topic must not include %q.'),
|
||||
separator))
|
||||
@ -75,6 +77,7 @@ def getTopic(irc, msg, args, state, format=True):
|
||||
topic = ircutils.standardSubstitute(irc, msg, formatter, env)
|
||||
state.args.append(topic)
|
||||
|
||||
|
||||
def getTopicNumber(irc, msg, args, state):
|
||||
def error(s):
|
||||
state.errorInvalid(_('topic number'), s)
|
||||
@ -105,15 +108,19 @@ addConverter('topic', getTopic)
|
||||
addConverter('topicNumber', getTopicNumber)
|
||||
addConverter('canChangeTopic', canChangeTopic)
|
||||
|
||||
|
||||
def splitTopic(topic, separator):
|
||||
return list(filter(None, topic.split(separator)))
|
||||
|
||||
datadir = conf.supybot.directories.data()
|
||||
filename = conf.supybot.directories.data.dirize('Topic.pickle')
|
||||
|
||||
|
||||
class Topic(callbacks.Plugin):
|
||||
|
||||
"""This plugin allows you to use many topic-related functions,
|
||||
such as Add, Undo, and Remove."""
|
||||
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Topic, self)
|
||||
self.__parent.__init__(irc)
|
||||
@ -167,13 +174,13 @@ class Topic(callbacks.Plugin):
|
||||
stack = self.undos.setdefault(channel, [])
|
||||
stack.append(topics)
|
||||
maxLen = self.registryValue('undo.max', channel)
|
||||
del stack[:len(stack)-maxLen]
|
||||
del stack[:len(stack) - maxLen]
|
||||
|
||||
def _addRedo(self, channel, topics):
|
||||
stack = self.redos.setdefault(channel, [])
|
||||
stack.append(topics)
|
||||
maxLen = self.registryValue('undo.max', channel)
|
||||
del stack[:len(stack)-maxLen]
|
||||
del stack[:len(stack) - maxLen]
|
||||
|
||||
def _getUndo(self, channel):
|
||||
try:
|
||||
@ -201,8 +208,8 @@ class Topic(callbacks.Plugin):
|
||||
elif len(newTopic) > maxLen:
|
||||
if self.registryValue('recognizeTopiclen', channel):
|
||||
irc.error(format(_('That topic is too long for this '
|
||||
'server (maximum length: %i; this topic: '
|
||||
'%i).'), maxLen, len(newTopic)),
|
||||
'server (maximum length: %i; this topic: '
|
||||
'%i).'), maxLen, len(newTopic)),
|
||||
Raise=True)
|
||||
except KeyError:
|
||||
pass
|
||||
@ -235,7 +242,8 @@ class Topic(callbacks.Plugin):
|
||||
if capabilities:
|
||||
for capability in re.split(r'\s*;\s*', capabilities):
|
||||
if capability.startswith('channel,'):
|
||||
capability = ircdb.makeChannelCapability(channel, capability[8:])
|
||||
capability = ircdb.makeChannelCapability(
|
||||
channel, capability[8:])
|
||||
if capability and ircdb.checkCapability(msg.prefix, capability):
|
||||
return True
|
||||
return False
|
||||
@ -255,7 +263,7 @@ class Topic(callbacks.Plugin):
|
||||
return
|
||||
if irc.nick not in c.ops and 't' in c.modes:
|
||||
self.log.debug('Not trying to restore topic in %s. I\'m not opped '
|
||||
'and %s is +t.', channel, channel)
|
||||
'and %s is +t.', channel, channel)
|
||||
return
|
||||
try:
|
||||
topics = self.lastTopics[channel]
|
||||
@ -264,7 +272,7 @@ class Topic(callbacks.Plugin):
|
||||
else:
|
||||
newTopic = self._formatTopics(irc, channel, topics)
|
||||
if c.topic == '' or (c.topic != newTopic and
|
||||
self.registryValue('alwaysSetOnJoin', channel)):
|
||||
self.registryValue('alwaysSetOnJoin', channel)):
|
||||
self._sendTopics(irc, channel, newTopic)
|
||||
|
||||
def do332(self, irc, msg):
|
||||
@ -405,7 +413,7 @@ class Topic(callbacks.Plugin):
|
||||
topics = self._splitTopic(irc.state.getTopic(channel), channel)
|
||||
L = []
|
||||
for (i, t) in enumerate(topics):
|
||||
L.append(format(_('%i: %s'), i+1, utils.str.ellipsisify(t, 30)))
|
||||
L.append(format(_('%i: %s'), i + 1, utils.str.ellipsisify(t, 30)))
|
||||
s = utils.str.commaAndify(L)
|
||||
irc.reply(s)
|
||||
list = wrap(list, ['inChannel'])
|
||||
@ -546,9 +554,9 @@ class Topic(callbacks.Plugin):
|
||||
if not topics:
|
||||
raise KeyError
|
||||
except KeyError:
|
||||
irc.error(format(_('I haven\'t yet set the topic in %s.'),
|
||||
channel))
|
||||
return
|
||||
irc.error(format(_('I haven\'t yet set the topic in %s.'),
|
||||
channel))
|
||||
return
|
||||
self._sendTopics(irc, channel, topics)
|
||||
refresh = wrap(refresh, ['canChangeTopic'])
|
||||
|
||||
@ -563,8 +571,8 @@ class Topic(callbacks.Plugin):
|
||||
if not self._checkManageCapabilities(irc, msg, channel):
|
||||
capabilities = self.registryValue('requireManageCapability')
|
||||
irc.errorNoCapability(capabilities, Raise=True)
|
||||
self._addRedo(channel, self._getUndo(channel)) # current topic.
|
||||
topics = self._getUndo(channel) # This is the topic list we want.
|
||||
self._addRedo(channel, self._getUndo(channel)) # current topic.
|
||||
topics = self._getUndo(channel) # This is the topic list we want.
|
||||
if topics is not None:
|
||||
self._sendTopics(irc, channel, topics, isDo=True)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user