mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Updated to use __all__, etc.
This commit is contained in:
parent
0d46bcdd39
commit
4c31e63ff8
@ -44,12 +44,12 @@ import random
|
|||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.ircdb as ircdb
|
import supybot.ircdb as ircdb
|
||||||
|
from supybot.commands import *
|
||||||
import supybot.ircmsgs as ircmsgs
|
import supybot.ircmsgs as ircmsgs
|
||||||
import supybot.plugins as plugins
|
import supybot.plugins as plugins
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
from supybot.commands import wrap, addWrapper, inChannel, getChannel
|
|
||||||
|
|
||||||
class TopicFormat(registry.String):
|
class TopicFormat(registry.String):
|
||||||
"Value must include $topic, otherwise the actual topic would be left out."
|
"Value must include $topic, otherwise the actual topic would be left out."
|
||||||
@ -82,8 +82,8 @@ conf.registerChannelValue(conf.supybot.plugins.Topic.undo, 'max',
|
|||||||
|
|
||||||
def canChangeTopic(irc, msg, args, state):
|
def canChangeTopic(irc, msg, args, state):
|
||||||
assert not state.channel
|
assert not state.channel
|
||||||
getChannel(irc, msg, args, state)
|
callConverter('channel', irc, msg, args, state)
|
||||||
inChannel(irc, msg, args, state)
|
callConverter('inChannel', irc, msg, args, state)
|
||||||
if state.channel not in irc.state.channels:
|
if state.channel not in irc.state.channels:
|
||||||
irc.error('I\'m not currently in %s.' % state.channel, Raise=True)
|
irc.error('I\'m not currently in %s.' % state.channel, Raise=True)
|
||||||
c = irc.state.channels[state.channel]
|
c = irc.state.channels[state.channel]
|
||||||
@ -128,9 +128,9 @@ def getTopicNumber(irc, msg, args, state):
|
|||||||
n += len(topics)
|
n += len(topics)
|
||||||
state.args.append(n)
|
state.args.append(n)
|
||||||
|
|
||||||
addWrapper('topic', getTopic)
|
addConverter('topic', getTopic)
|
||||||
addWrapper('topicNumber', getTopicNumber)
|
addConverter('topicNumber', getTopicNumber)
|
||||||
addWrapper('canChangeTopic', canChangeTopic)
|
addConverter('canChangeTopic', canChangeTopic)
|
||||||
|
|
||||||
def splitTopic(topic, separator):
|
def splitTopic(topic, separator):
|
||||||
return filter(None, topic.split(separator))
|
return filter(None, topic.split(separator))
|
||||||
|
@ -188,9 +188,8 @@ def getNonInt(irc, msg, args, state, type='non-integer value'):
|
|||||||
|
|
||||||
def getFloat(irc, msg, args, state):
|
def getFloat(irc, msg, args, state):
|
||||||
try:
|
try:
|
||||||
x = float(args[0])
|
state.args.append(float(args[0]))
|
||||||
del args[0]
|
del args[0]
|
||||||
return x
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.errorInvalid('floating point number', args[0])
|
irc.errorInvalid('floating point number', args[0])
|
||||||
|
|
||||||
@ -498,9 +497,15 @@ wrappers = ircutils.IrcDict({
|
|||||||
'checkChannelCapability': checkChannelCapability,
|
'checkChannelCapability': checkChannelCapability,
|
||||||
})
|
})
|
||||||
|
|
||||||
def addWrapper(name, wrapper):
|
def addConverter(name, wrapper):
|
||||||
wrappers[name] = wrapper
|
wrappers[name] = wrapper
|
||||||
|
|
||||||
|
def getConverter(name):
|
||||||
|
return wrappers[name]
|
||||||
|
|
||||||
|
def callConverter(name, irc, msg, args, state, *L):
|
||||||
|
getConverter(name)(irc, msg, args, state, *L)
|
||||||
|
|
||||||
class State(object):
|
class State(object):
|
||||||
def __init__(self, name=None, logger=None):
|
def __init__(self, name=None, logger=None):
|
||||||
if logger is None:
|
if logger is None:
|
||||||
@ -512,6 +517,23 @@ class State(object):
|
|||||||
self.getopts = []
|
self.getopts = []
|
||||||
self.channel = None
|
self.channel = None
|
||||||
|
|
||||||
|
class context(object):
|
||||||
|
def __init__(self, spec):
|
||||||
|
self.args = ()
|
||||||
|
if isinstance(spec, tuple):
|
||||||
|
assert spec, 'tuple spec must not be empty.'
|
||||||
|
self.args = spec[1:]
|
||||||
|
self.converter = getConverter(spec[0])
|
||||||
|
elif spec is None:
|
||||||
|
self.converter = getConverter('anything')
|
||||||
|
else:
|
||||||
|
assert isinstance(spec, basestring)
|
||||||
|
self.args = ()
|
||||||
|
self.converter = getConverter(spec)
|
||||||
|
|
||||||
|
def __call__(self, irc, msg, args, state):
|
||||||
|
self.converter(irc, msg, args, state, *self.args)
|
||||||
|
|
||||||
# getopts: None means "no conversion", '' means "takes no argument"
|
# getopts: None means "no conversion", '' means "takes no argument"
|
||||||
def args(irc,msg,args, types=[], state=None,
|
def args(irc,msg,args, types=[], state=None,
|
||||||
getopts=None, allowExtra=False, requireExtra=False, combineRest=True):
|
getopts=None, allowExtra=False, requireExtra=False, combineRest=True):
|
||||||
@ -659,4 +681,6 @@ def wrap(f, *argsArgs, **argsKwargs):
|
|||||||
return newf
|
return newf
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['wrap', 'args',
|
||||||
|
'getConverter', 'addConverter', 'callConverter']
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user