TextTransform: al bhed translator

This commit is contained in:
Brian S. Stephan 2011-10-21 17:17:37 -05:00
parent ef66c855f3
commit a608f509ca
1 changed files with 40 additions and 0 deletions

View File

@ -42,6 +42,8 @@ class TextTransform(Module):
return self.reply(connection, event, reply[0])
elif self.upper(what, reply):
return self.reply(connection, event, reply[0])
elif self.al_bhed(what, reply):
return self.reply(connection, event, reply[0])
def rot13(self, what, reply):
"""
@ -82,5 +84,43 @@ class TextTransform(Module):
reply[0] = text.upper()
return True
def al_bhed(self, what, reply):
"""
Convert a string to al bhed.
"""
cipher = {'A':'Y','B':'P','C':'L','D':'T','E':'A','F':'V','G':'K','H':'R','I':'E','J':'Z','K':'G','L':'M','M':'S','N':'H','O':'U','P':'B','Q':'X','R':'N','S':'C','T':'D','U':'I','V':'J','W':'F','X':'Q','Y':'O','Z':'W'}
decipher = dict([(v,k) for (k,v) in cipher.iteritems()])
match = re.search('^!al-bhed\s+(.*)$', what)
if match:
text = match.group(1)
trans = []
for i in range(len(text)):
if text[i] in cipher:
trans.append(cipher[text[i]])
elif text[i].upper() in cipher:
trans.append(cipher[text[i].upper()].lower())
else:
trans.append(text[i])
reply[0] = "".join(trans)
return True
match = re.search('^!deal-bhed\s+(.*)$', what)
if match:
text = match.group(1)
trans = []
for i in range(len(text)):
if text[i] in decipher:
trans.append(decipher[text[i]])
elif text[i].upper() in cipher:
trans.append(decipher[text[i].upper()].lower())
else:
trans.append(text[i])
reply[0] = "".join(trans)
return True
# vi:tabstop=4:expandtab:autoindent
# kate: indent-mode python;indent-width 4;replace-tabs on;