Poodletooth-iLand/otp/chat/ChatGarbler.py

24 lines
675 B
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
import random
class ChatGarbler:
2015-05-30 11:28:28 -05:00
def __init__(self, messages):
self.messages = messages
2015-03-03 16:10:12 -06:00
2015-05-30 14:02:08 -05:00
def garble(self, avatar, message):
2015-03-03 16:10:12 -06:00
newMessage = ''
2015-05-30 11:28:28 -05:00
if avatar.style:
avatarType = avatar.style.getType()
wordList = self.messages[avatarType if avatarType in self.messages else 'default']
2015-05-30 14:02:08 -05:00
numWords = len(message.split(' '))
2015-03-03 16:10:12 -06:00
for i in xrange(1, numWords + 1):
2015-05-30 11:28:28 -05:00
wordIndex = random.randint(0, len(wordList) - 1)
newMessage = newMessage + wordList[wordIndex]
2015-03-03 16:10:12 -06:00
if i < numWords:
newMessage = newMessage + ' '
2015-05-30 14:02:08 -05:00
return '\x01WLDisplay\x01%s\x02' % newMessage