Moved the more useful Moobot commands to Fun.

This commit is contained in:
Jeremy Fincher 2003-10-20 05:11:13 +00:00
parent eb31db6277
commit 3fb2795668
4 changed files with 87 additions and 93 deletions

View File

@ -495,6 +495,86 @@ class Fun(callbacks.Privmsg):
s = self._scrambleRe.sub(_subber, text)
irc.reply(msg, s)
_code = {
"A" : ".-",
"B" : "-...",
"C" : "-.-.",
"D" : "-..",
"E" : ".",
"F" : "..-.",
"G" : "--.",
"H" : "....",
"I" : "..",
"J" : ".---",
"K" : "-.-",
"L" : ".-..",
"M" : "--",
"N" : "-.",
"O" : "---",
"P" : ".--.",
"Q" : "--.-",
"R" : ".-.",
"S" : "...",
"T" : "-",
"U" : "..-",
"V" : "...-",
"W" : ".--",
"X" : "-..-",
"Y" : "-.--",
"Z" : "--..",
"0" : "-----",
"1" : ".----",
"2" : "..---",
"3" : "...--",
"4" : "....-",
"5" : ".....",
"6" : "-....",
"7" : "--...",
"8" : "---..",
"9" : "----.",
}
_revcode = dict([(y, x) for (x, y) in _code.items()])
_unmorsere = re.compile('([.-]+)')
def unmorse(self, irc, msg, args):
"""<morse code text>
Does the reverse of the morse/ditdaw command.
"""
text = privmsgs.getArgs(args)
text = text.replace('_', '-')
def morseToLetter(m):
s = m.group(1)
return self._revcode.get(s, s)
text = self._unmorsere.sub(morseToLetter, text)
text = text.replace(' ', '\x00')
text = text.replace(' ', '')
text = text.replace('\x00', ' ')
irc.reply(msg, text)
def morse(self, irc, msg, args):
"""<text>
Gives the more code equivalent of a given string.
"""
text = privmsgs.getArgs(args)
L = []
for c in text.upper():
if c in self._code:
L.append(self._code[c])
else:
L.append(c)
irc.reply(msg, ' '.join(L))
def reverse(self, irc, msg, args):
"""<text>
Reverses <text>.
"""
text = privmsgs.getArgs(args)
irc.reply(msg, text[::-1])
Class = Fun

View File

@ -99,81 +99,6 @@ class Moobot(callbacks.Privmsg):
something = privmsgs.getArgs(args)
irc.reply(msg, ':cool: %s :cool:' % something)
_code = {
"A" : ".-",
"B" : "-...",
"C" : "-.-.",
"D" : "-..",
"E" : ".",
"F" : "..-.",
"G" : "--.",
"H" : "....",
"I" : "..",
"J" : ".---",
"K" : "-.-",
"L" : ".-..",
"M" : "--",
"N" : "-.",
"O" : "---",
"P" : ".--.",
"Q" : "--.-",
"R" : ".-.",
"S" : "...",
"T" : "-",
"U" : "..-",
"V" : "...-",
"W" : ".--",
"X" : "-..-",
"Y" : "-.--",
"Z" : "--..",
"0" : "-----",
"1" : ".----",
"2" : "..---",
"3" : "...--",
"4" : "....-",
"5" : ".....",
"6" : "-....",
"7" : "--...",
"8" : "---..",
"9" : "----.",
}
_revcode = dict([(y, x) for (x, y) in _code.items()])
_unmorsere = re.compile('([.-]+)')
def unmorse(self, irc, msg, args):
"""<morse code text>
Does the reverse of the morse/ditdaw command.
"""
text = privmsgs.getArgs(args)
text = text.replace('_', '-')
def morseToLetter(m):
s = m.group(1)
return self._revcode.get(s, s)
text = self._unmorsere.sub(morseToLetter, text)
text = text.replace(' ', '\x00')
text = text.replace(' ', '')
text = text.replace('\x00', ' ')
irc.reply(msg, text)
def morse(self, irc, msg, args):
"""<text>
Gives the more code equivalent of a given string.
"""
text = privmsgs.getArgs(args)
L = []
for c in text.upper():
if c in self._code:
L.append(self._code[c])
else:
L.append(c)
irc.reply(msg, ' '.join(L))
ditdaw = morse
dawdit = unmorse
def hi(self, irc, msg, args):
"""takes no arguments
@ -181,14 +106,6 @@ class Moobot(callbacks.Privmsg):
"""
irc.reply(msg, 'howdy, %s!' % msg.nick)
def reverse(self, irc, msg, args):
"""<text>
Reverses <text>.
"""
text = privmsgs.getArgs(args)
irc.reply(msg, text[::-1])
def mime(self, irc, msg, args):
"""<text>

View File

@ -44,6 +44,13 @@ class FunTest(PluginTestCase, PluginDocumentation):
self.assertNotError('levenshtein Python Perl')
self.assertNotError('soundex jemfinch')
def testMorse(self):
self.assertResponse('unmorse [morse jemfinch]', 'JEMFINCH')
def testReverse(self):
for nick in nicks[:10]:
self.assertResponse('reverse %s' % nick, nick[::-1])
def testBinary(self):
self.assertResponse('binary A', '01000001')

View File

@ -35,20 +35,10 @@ import base64
class MoobotTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Moobot',)
def testMorse(self):
self.assertResponse('unmorse [morse jemfinch]', 'JEMFINCH')
self.assertResponse('dawdit [morse jemfinch]', 'JEMFINCH')
self.assertResponse('dawdit [ditdaw jemfinch]', 'JEMFINCH')
self.assertResponse('unmorse [ditdaw jemfinch]', 'JEMFINCH')
def testCool(self):
for nick in nicks[:10]:
self.assertResponse('cool %s' % nick, ':cool: %s :cool:' % nick)
def testReverse(self):
for nick in nicks[:10]:
self.assertResponse('reverse %s' % nick, nick[::-1])
def testMime(self):
for nick in nicks[:10]:
self.assertResponse('unmime [mime %s]' % nick, nick)