Poodletooth-iLand/otp/chat/ChatAgentUD.py

42 lines
1.8 KiB
Python
Raw Normal View History

2015-03-03 22:10:12 +00:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobalUD
# TODO: OTP should not depend on Toontown... Hrrm.
from toontown.chat.TTWhiteList import TTWhiteList
class ChatAgentUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory("ChatAgentUD")
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
self.whiteList = TTWhiteList()
def chatMessage(self, message):
2015-03-03 22:10:12 +00:00
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', self.air.getAccountIdFromSender(),
'Account sent chat without an avatar', message)
2015-03-03 22:10:12 +00:00
return
2015-03-03 22:10:12 +00:00
modifications = []
words = message.split(' ')
offset = 0
WantWhitelist = config.GetBool('want-whitelist', 1)
2015-03-03 22:10:12 +00:00
for word in words:
if word and not self.whiteList.isWord(word) and WantWhitelist:
2015-03-03 22:10:12 +00:00
modifications.append((offset, offset+len(word)-1))
offset += len(word) + 1
cleanMessage = message
for modStart, modStop in modifications:
cleanMessage = cleanMessage[:modStart] + '*'*(modStop-modStart+1) + cleanMessage[modStop+1:]
2015-03-03 22:10:12 +00:00
self.air.writeServerEvent('chat-said', sender, message, cleanMessage)
2015-03-31 11:59:36 +00:00
# TODO: The above is probably a little too ugly for my taste... Maybe AIR
# should be given an API for sending updates for unknown objects?
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalk', sender, sender,
self.air.ourChannel,
[0, 0, '', cleanMessage, modifications, 0])
self.air.send(dg)