Converted to commands.wrap. These are all untested, so someone should test them at some point.

This commit is contained in:
Jeremy Fincher 2004-11-19 23:23:14 +00:00
parent 8b1962068b
commit 5762ed6d74
3 changed files with 26 additions and 43 deletions

View File

@ -44,7 +44,7 @@ import babelfish
import supybot.conf as conf
import supybot.utils as utils
import supybot.privmsgs as privmsgs
from supybot.commands import *
import supybot.registry as registry
import supybot.callbacks as callbacks
@ -95,16 +95,13 @@ class Babelfish(callbacks.Privmsg):
"""
irc.reply(utils.commaAndify(babelfish.available_languages))
def translate(self, irc, msg, args):
def translate(self, irc, msg, args, fromLang, to, toLang, text):
"""<from-language> [to] <to-language> <text>
Returns <text> translated from <from-language> into <to-language>.
Beware that translating to or from languages that use multi-byte
characters may result in some very odd results.
"""
if len(args) >= 2 and args[1] == 'to':
args.pop(1)
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
chan = msg.args[0]
try:
(fromLang, toLang) = self._getLang(fromLang, toLang, chan)
@ -131,15 +128,17 @@ class Babelfish(callbacks.Privmsg):
except babelfish.BabelfishChangedError, e:
irc.error('Babelfish has foiled our plans by changing its '
'webpage format.')
translate = wrap(translate,
['something', optional(literal('to')),
'something', 'text'])
def babelize(self, irc, msg, args):
def babelize(self, irc, msg, args, fromLang, toLang, text):
"""<from-language> <to-language> <text>
Translates <text> repeatedly between <from-language> and <to-language>
until it doesn't change anymore or 12 times, whichever is fewer. One
of the languages must be English.
"""
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
chan = msg.args[0]
try:
(fromLang, toLang) = self._getLang(fromLang, toLang, chan)
@ -170,14 +169,18 @@ class Babelfish(callbacks.Privmsg):
except babelfish.BabelfishChangedError, e:
irc.reply('Babelfish has foiled our plans by changing its '
'webpage format.')
babelize = wrap(babelize, ['something', 'something', 'text'])
def randomlanguage(self, irc, msg, args):
"""[<allow-english>]
def randomlanguage(self, irc, msg, args, optlist):
"""[--allow-english]
Returns a random language supported by babelfish. If <allow-english>
Returns a random language supported by babelfish. If --allow-english
is provided, will include English in the list of possible languages.
"""
allowEnglish = privmsgs.getArgs(args, required=0, optional=1)
allowEnglish = False
for (option, arg) in optlist:
if option == 'allow-english':
allowEnglish = True
languages = self.registryValue('languages', msg.args[0])
if not languages:
irc.error('I can\'t speak any other languages.')
@ -185,6 +188,7 @@ class Babelfish(callbacks.Privmsg):
while not allowEnglish and language == 'English':
language = random.choice(languages)
irc.reply(language)
randomlanguage = wrap(randomlanguage, [getopts({'allow-english': ''})])
Class = Babelfish

View File

@ -42,19 +42,18 @@ import threading
import supybot.conf as conf
import supybot.utils as utils
import supybot.world as world
from supybot.commands import *
import supybot.ircmsgs as ircmsgs
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.callbacks as callbacks
class DCC(callbacks.Privmsg):
def chat(self, irc, msg, args):
def chat(self, irc, msg, args, text):
"""<text>
Sends <text> to the user via a DCC CHAT. Use nested commands to your
benefit here.
"""
text = privmsgs.getArgs(args)
def openChatPort():
try:
host = ircutils.hostFromHostmask(irc.prefix)
@ -112,6 +111,7 @@ class DCC(callbacks.Privmsg):
world.threadsSpawned += 1
t.setDaemon(True)
t.start()
chat = wrap(chat, ['text'])

View File

@ -49,7 +49,6 @@ import supybot.utils as utils
import supybot.plugins as plugins
from supybot.commands import *
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
import supybot.webutils as webutils
import supybot.callbacks as callbacks
@ -418,53 +417,33 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
else:
return ''
def total(self, irc, msg, args):
def total(self, irc, msg, args, type, project):
"""{bugs,rfes} [<project>]
Returns the total count of open bugs or rfes. <project> is only
necessary if a default project is not set.
"""
if not args:
raise callbacks.ArgumentError
type = args.pop(0)
if type == 'bugs':
self._totalbugs(irc, msg, args)
self._totalbugs(irc, msg, project)
elif type == 'rfes':
self._totalrfes(irc, msg, args)
else:
raise callbacks.ArgumentError
self._totalrfes(irc, msg, project)
total = wrap(total, [literal(('bugs', 'rfes')), additional('something')])
def _totalbugs(self, irc, msg, args):
"""[<project>]
Returns a count of the open/total bugs. <project> is not needed if a
default project is set.
"""
project = privmsgs.getArgs(args, required=0, optional=1)
def _totalbugs(self, irc, msg, project):
project = project or self.registryValue('defaultProject', msg.args[0])
if not project:
raise callbacks.ArgumentError
total = self._getNumBugs(project)
if total:
irc.reply(total)
else:
irc.error('Could not find bug statistics.')
irc.error('Could not find bug statistics for %s.' % project)
def _totalrfes(self, irc, msg, args):
"""[<project>]
Returns a count of the open/total RFEs. <project> is not needed if a
default project is set.
"""
project = privmsgs.getArgs(args, required=0, optional=1)
def _totalrfes(self, irc, msg, project):
project = project or self.registryValue('defaultProject', msg.args[0])
if not project:
raise callbacks.ArgumentError
total = self._getNumRfes(project)
if total:
irc.reply(total)
else:
irc.error('Could not find RFE statistics.')
irc.error('Could not find RFE statistics for %s.' % project)
def fight(self, irc, msg, args, optlist, projects):
"""[--{bugs,rfes}] [--{open,closed}] <project name> <project name> \