Work on chat garbler

This commit is contained in:
John 2015-05-30 19:28:28 +03:00 committed by Loudrob
parent 1b2c00f7a1
commit d9454000b4
7 changed files with 36 additions and 78 deletions

View file

@ -31,7 +31,7 @@ want-checkers #t
want-house-types #t
# Chat:
want-whitelist #f
want-whitelist #t
# Optional:
want-jor-el-cam #f

View file

@ -5,21 +5,18 @@ import string
import time
from otp.ai.MagicWordGlobal import *
from otp.avatar import Avatar, PlayerBase
from otp.avatar import DistributedAvatar
from otp.avatar import Avatar, PlayerBase, DistributedAvatar
from otp.avatar.Avatar import teleportNotify
from otp.chat import ChatGarbler
from otp.chat import TalkAssistant
from otp.chat import ChatGarbler, TalkAssistant
from otp.distributed.TelemetryLimited import TelemetryLimited
from otp.otpbase import OTPGlobals
from otp.otpbase import OTPLocalizer
from otp.otpbase import OTPGlobals, OTPLocalizer
from otp.speedchat import SCDecoders
from toontown.chat.ChatGlobals import *
from toontown.chat.WhisperPopup import WhisperPopup
class DistributedPlayer(DistributedAvatar.DistributedAvatar, PlayerBase.PlayerBase, TelemetryLimited):
TeleportFailureTimeout = 60.0
chatGarbler = ChatGarbler.ChatGarbler()
chatGarbler = ChatGarbler.ChatGarbler({'default': OTPLocalizer.ChatGarblerDefault})
def __init__(self, cr):
try:

View file

@ -54,7 +54,6 @@ class LocalAvatar(DistributedAvatar.DistributedAvatar, DistributedSmoothNode.Dis
self.customMessages = []
self.chatMgr = chatMgr
base.talkAssistant = talkAssistant
self.garbleChat = 1
self.teleportAllowed = 1
self.lockedDown = 0
self.isPageUp = 0

View file

@ -1,29 +1,24 @@
import string
import random
from otp.otpbase import OTPLocalizer
class ChatGarbler:
def __init__(self, messages):
self.messages = messages
def garble(self, avatar, message):
def garble(self, avatar, message, isRandom=False):
newMessage = ''
numWords = random.randint(1, 7)
wordlist = OTPLocalizer.ChatGarblerDefault
if avatar.style:
avatarType = avatar.style.getType()
wordList = self.messages[avatarType if avatarType in self.messages else 'default']
numWords = random.randint(1, 7) if isRandom else 1
for i in xrange(1, numWords + 1):
wordIndex = random.randint(0, len(wordlist) - 1)
newMessage = newMessage + wordlist[wordIndex]
wordIndex = random.randint(0, len(wordList) - 1)
newMessage = newMessage + wordList[wordIndex]
if i < numWords:
newMessage = newMessage + ' '
return newMessage
def garbleSingle(self, avatar, message):
newMessage = ''
numWords = 1
wordlist = OTPLocalizer.ChatGarblerDefault
for i in xrange(1, numWords + 1):
wordIndex = random.randint(0, len(wordlist) - 1)
newMessage = newMessage + wordlist[wordIndex]
if i < numWords:
newMessage = newMessage + ' '
return newMessage
return newMessage

View file

@ -1,49 +1,16 @@
import string
import random
from toontown.toonbase import TTLocalizer
from otp.otpbase import OTPLocalizer
from otp.chat import ChatGarbler
from toontown.toonbase import TTLocalizer
class ToonChatGarbler(ChatGarbler.ChatGarbler):
animalSounds = {'dog': TTLocalizer.ChatGarblerDog,
'cat': TTLocalizer.ChatGarblerCat,
'mouse': TTLocalizer.ChatGarblerMouse,
'horse': TTLocalizer.ChatGarblerHorse,
'rabbit': TTLocalizer.ChatGarblerRabbit,
'duck': TTLocalizer.ChatGarblerDuck,
'monkey': TTLocalizer.ChatGarblerMonkey,
'bear': TTLocalizer.ChatGarblerBear,
'pig': TTLocalizer.ChatGarblerPig,
'default': OTPLocalizer.ChatGarblerDefault}
def garble(self, toon, message):
newMessage = ''
animalType = toon.getStyle().getType()
if animalType in ToonChatGarbler.animalSounds:
wordlist = ToonChatGarbler.animalSounds[animalType]
else:
wordlist = ToonChatGarbler.animalSounds['default']
numWords = random.randint(1, 7)
for i in xrange(1, numWords + 1):
wordIndex = random.randint(0, len(wordlist) - 1)
newMessage = newMessage + wordlist[wordIndex]
if i < numWords:
newMessage = newMessage + ' '
return newMessage
def garbleSingle(self, toon, message):
newMessage = ''
animalType = toon.getStyle().getType()
if animalType in ToonChatGarbler.animalSounds:
wordlist = ToonChatGarbler.animalSounds[animalType]
else:
wordlist = ToonChatGarbler.animalSounds['default']
numWords = 1
for i in xrange(1, numWords + 1):
wordIndex = random.randint(0, len(wordlist) - 1)
newMessage = newMessage + wordlist[wordIndex]
if i < numWords:
newMessage = newMessage + ' '
return newMessage
def __init__(self):
self.messages = {'dog': TTLocalizer.ChatGarblerDog,
'cat': TTLocalizer.ChatGarblerCat,
'mouse': TTLocalizer.ChatGarblerMouse,
'horse': TTLocalizer.ChatGarblerHorse,
'rabbit': TTLocalizer.ChatGarblerRabbit,
'duck': TTLocalizer.ChatGarblerDuck,
'monkey': TTLocalizer.ChatGarblerMonkey,
'bear': TTLocalizer.ChatGarblerBear,
'pig': TTLocalizer.ChatGarblerPig,
'default': TTLocalizer.ChatGarblerDefault}

View file

@ -81,7 +81,7 @@ class FriendHandle:
if word == '':
newwords.append(word)
elif word[0] == '\x07':
newwords.append('\x01WLDisplay\x01' + self.chatGarbler.garbleSingle(self, word) + '\x02')
newwords.append('\x01WLDisplay\x01' + self.chatGarbler.garble(self, word) + '\x02')
scrubbed = 1
elif base.whiteList.isWord(word):
newwords.append(word)
@ -99,7 +99,7 @@ class FriendHandle:
if word == '':
newwords.append(word)
elif word[0] == '\x07':
newwords.append('\x01WLRed\x01' + self.chatGarbler.garbleSingle(self, word) + '\x02')
newwords.append('\x01WLRed\x01' + self.chatGarbler.garble(self, word) + '\x02')
elif base.whiteList.isWord(word):
newwords.append(word)
else:

View file

@ -2402,7 +2402,7 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute
if word == '':
newwords.append(word)
elif word[0] == '\x07' or len(word) > 1 and word[0] == '.' and word[1] == '\x07':
newwords.append('\x01WLDisplay\x01' + self.chatGarbler.garbleSingle(self, word) + '\x02')
newwords.append('\x01WLDisplay\x01' + self.chatGarbler.garble(self, word) + '\x02')
scrubbed = 1
elif not self.whiteListEnabled or base.whiteList.isWord(word):
newwords.append(word)
@ -2428,7 +2428,7 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute
if word == '':
newwords.append(word)
elif word[0] == '\x07':
newwords.append('\x01WLRed\x01' + self.chatGarbler.garbleSingle(self, word) + '\x02')
newwords.append('\x01WLRed\x01' + self.chatGarbler.garble(self, word) + '\x02')
elif not self.whiteListEnabled or base.whiteList.isWord(word):
newwords.append(word)
else: