mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-03 01:39:23 +01:00
Changed morse/unmorse and related stuff to be (hopefully) clearer.
This commit is contained in:
parent
85331d2848
commit
ab7fd51ddd
@ -52,6 +52,7 @@ Commands include:
|
|||||||
|
|
||||||
from baseplugin import *
|
from baseplugin import *
|
||||||
|
|
||||||
|
import re
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
import ircmsgs
|
import ircmsgs
|
||||||
@ -69,46 +70,47 @@ class Moobot(callbacks.Privmsg):
|
|||||||
irc.reply(msg, ':cool: %s :cool:' % something)
|
irc.reply(msg, ':cool: %s :cool:' % something)
|
||||||
|
|
||||||
_code = {
|
_code = {
|
||||||
"A" : ".- ",
|
"A" : ".-",
|
||||||
"B" : "-... ",
|
"B" : "-...",
|
||||||
"C" : "-.-. ",
|
"C" : "-.-.",
|
||||||
"D" : "-.. ",
|
"D" : "-..",
|
||||||
"E" : ". ",
|
"E" : ".",
|
||||||
"F" : "..-. ",
|
"F" : "..-.",
|
||||||
"G" : "--. ",
|
"G" : "--.",
|
||||||
"H" : ".... ",
|
"H" : "....",
|
||||||
"I" : ".. ",
|
"I" : "..",
|
||||||
"J" : ".--- ",
|
"J" : ".---",
|
||||||
"K" : "-.- ",
|
"K" : "-.-",
|
||||||
"L" : ".-.. ",
|
"L" : ".-..",
|
||||||
"M" : "-- ",
|
"M" : "--",
|
||||||
"N" : "-. ",
|
"N" : "-.",
|
||||||
"O" : "--- ",
|
"O" : "---",
|
||||||
"P" : ".--. ",
|
"P" : ".--.",
|
||||||
"Q" : "--.- ",
|
"Q" : "--.-",
|
||||||
"R" : ".-. ",
|
"R" : ".-.",
|
||||||
"S" : "... ",
|
"S" : "...",
|
||||||
"T" : "- ",
|
"T" : "-",
|
||||||
"U" : "..- ",
|
"U" : "..-",
|
||||||
"V" : "...- ",
|
"V" : "...-",
|
||||||
"W" : ".-- ",
|
"W" : ".--",
|
||||||
"X" : "-..- ",
|
"X" : "-..-",
|
||||||
"Y" : "-.-- ",
|
"Y" : "-.--",
|
||||||
"Z" : "--.. ",
|
"Z" : "--..",
|
||||||
"0" : "----- ",
|
"0" : "-----",
|
||||||
"1" : ".---- ",
|
"1" : ".----",
|
||||||
"2" : "..--- ",
|
"2" : "..---",
|
||||||
"3" : "...-- ",
|
"3" : "...--",
|
||||||
"4" : "....- ",
|
"4" : "....-",
|
||||||
"5" : "..... ",
|
"5" : ".....",
|
||||||
"6" : "-.... ",
|
"6" : "-....",
|
||||||
"7" : "--... ",
|
"7" : "--...",
|
||||||
"8" : "---.. ",
|
"8" : "---..",
|
||||||
"9" : "----. ",
|
"9" : "----.",
|
||||||
}
|
}
|
||||||
|
|
||||||
_revcode = dict([(y.strip(), x) for (x, y) in _code.items()])
|
_revcode = dict([(y, x) for (x, y) in _code.items()])
|
||||||
|
|
||||||
|
_unmorsere = re.compile('([.-]+)')
|
||||||
def unmorse(self, irc, msg, args):
|
def unmorse(self, irc, msg, args):
|
||||||
"""<morse code text>
|
"""<morse code text>
|
||||||
|
|
||||||
@ -116,15 +118,14 @@ class Moobot(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
text = privmsgs.getArgs(args)
|
||||||
L = []
|
L = []
|
||||||
for (first, second, third) in window(text.split(' ')+[''], 3):
|
def morseToLetter(m):
|
||||||
if first == '' and second == '' and third == '':
|
s = m.group(1)
|
||||||
L.append(' ')
|
return self._revcode.get(s, s)
|
||||||
else:
|
text = self._unmorsere.sub(morseToLetter, text)
|
||||||
try:
|
text = text.replace(' ', '\x00')
|
||||||
L.append(self._revcode[first])
|
text = text.replace(' ', '')
|
||||||
except KeyError:
|
text = text.replace('\x00', ' ')
|
||||||
L.append(first)
|
irc.reply(msg, text)
|
||||||
irc.reply(msg, ''.join(L))
|
|
||||||
|
|
||||||
def morse(self, irc, msg, args):
|
def morse(self, irc, msg, args):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
Loading…
Reference in New Issue
Block a user