From 3fb2795668f99ee4f9b01910b6d4c85d7c9d0457 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 20 Oct 2003 05:11:13 +0000 Subject: [PATCH] Moved the more useful Moobot commands to Fun. --- plugins/Fun.py | 80 +++++++++++++++++++++++++++++++++++++++++++ plugins/Moobot.py | 83 --------------------------------------------- test/test_Fun.py | 7 ++++ test/test_Moobot.py | 10 ------ 4 files changed, 87 insertions(+), 93 deletions(-) diff --git a/plugins/Fun.py b/plugins/Fun.py index 4716d747b..a329d5f94 100644 --- a/plugins/Fun.py +++ b/plugins/Fun.py @@ -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): + """ + + 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): + """ + + 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): + """ + + Reverses . + """ + text = privmsgs.getArgs(args) + irc.reply(msg, text[::-1]) + Class = Fun diff --git a/plugins/Moobot.py b/plugins/Moobot.py index d278716b3..d2fd11a8b 100644 --- a/plugins/Moobot.py +++ b/plugins/Moobot.py @@ -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): - """ - - 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): - """ - - 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): - """ - - Reverses . - """ - text = privmsgs.getArgs(args) - irc.reply(msg, text[::-1]) - def mime(self, irc, msg, args): """ diff --git a/test/test_Fun.py b/test/test_Fun.py index 1e535c2a4..9b63e5cba 100644 --- a/test/test_Fun.py +++ b/test/test_Fun.py @@ -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') diff --git a/test/test_Moobot.py b/test/test_Moobot.py index 37a4695aa..7f3d34c26 100644 --- a/test/test_Moobot.py +++ b/test/test_Moobot.py @@ -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)