本文整理汇总了Python中toontown.chat.TTWhiteList.TTWhiteList.isWord方法的典型用法代码示例。如果您正苦于以下问题:Python TTWhiteList.isWord方法的具体用法?Python TTWhiteList.isWord怎么用?Python TTWhiteList.isWord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类toontown.chat.TTWhiteList.TTWhiteList
的用法示例。
在下文中一共展示了TTWhiteList.isWord方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ChatAgentUD
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
class ChatAgentUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory("ChatAgentUD")
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
self.whiteList = TTWhiteList()
def chatMessage(self, message):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', self.air.getAccountIdFromSender(),
'Account sent chat without an avatar', message)
return
modifications = []
words = message.split(' ')
offset = 0
WantWhitelist = config.GetBool('want-whitelist', 1)
for word in words:
if word and not self.whiteList.isWord(word) and WantWhitelist:
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:]
self.air.writeServerEvent('chat-said', sender, message, cleanMessage)
dclass = self.air.dclassesByName['DistributedAvatarUD']
dg = dclass.aiFormatUpdate(
'setTalk', sender, sender, self.air.ourChannel,
[0, 0, '', cleanMessage, modifications, 0])
self.air.send(dg)
示例2: ChatAgentUD
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
class ChatAgentUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory("ChatAgentUD")
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
self.whiteList = TTWhiteList()
self.muted = {}
def muteAccount(self, account, howLong):
print ['muteAccount', account, howLong]
self.muted[account] = int(time.time()/60) + howLong
def unmuteAccount(self, account):
print ['unuteAccount', account]
if account in self.muted:
del self.muted[account]
def chatMessage(self, message):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', self.air.getAccountIdFromSender(),
'Account sent chat without an avatar', message)
return
if sender in self.muted and int(time.time()/60) < self.muted[sender]:
return
modifications = []
words = message.split(' ')
offset = 0
WantWhitelist = config.GetBool('want-whitelist', 1)
for word in words:
if word and not self.whiteList.isWord(word) and WantWhitelist:
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:]
self.air.writeServerEvent('chat-said', sender, message, cleanMessage)
# 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)
self.air.csm.accountDB.persistChat(sender, message, self.air.ourChannel)
示例3: ChatAgentUD
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
class ChatAgentUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory("ChatAgentUD")
WantWhitelist = config.GetBool('want-whitelist', True)
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
self.whiteList = TTWhiteList()
def chatMessage(self, message):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', self.air.getAccountIdFromSender(),
'Account sent chat without an avatar', message)
return
modifications = []
words = message.split(' ')
offset = 0
wantWhitelist = self.WantWhitelist and self.air.friendsManager.getToonAccess(sender) < 400
for word in words:
if word and not self.whiteList.isWord(word) and wantWhitelist:
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:]
self.air.writeServerEvent('chat-said', sender, message, cleanMessage)
# 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)
示例4: TTChatInputWhiteList
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
#.........这里部分代码省略.........
elif self.receiverId and not self.toPlayer:
base.talkAssistant.sendWhisperTalk(text, self.receiverId)
elif self.receiverId and self.toPlayer:
base.talkAssistant.sendAccountTalk(text, self.receiverId)
def sendWhisperByFriend(self, avatarId, text):
online = 0
if avatarId in base.cr.doId2do:
online = 1
avatarUnderstandable = 0
av = None
if avatarId:
av = base.cr.identifyAvatar(avatarId)
if av != None:
avatarUnderstandable = av.isUnderstandable()
if avatarUnderstandable and online:
base.talkAssistant.sendWhisperTalk(text, avatarId)
return
def chatButtonPressed(self):
if self.okayToSubmit:
self.sendChat(self.chatEntry.get())
else:
self.sendFailed(self.chatEntry.get())
def cancelButtonPressed(self):
self.requestMode('Off')
localAvatar.chatMgr.fsm.request('mainMenu')
def enterAllChat(self):
ChatInputWhiteListFrame.enterAllChat(self)
self.whisperLabel.hide()
def exitAllChat(self):
ChatInputWhiteListFrame.exitAllChat(self)
def enterPlayerWhisper(self):
ChatInputWhiteListFrame.enterPlayerWhisper(self)
self.labelWhisper()
def exitPlayerWhisper(self):
ChatInputWhiteListFrame.exitPlayerWhisper(self)
self.whisperLabel.hide()
def enterAvatarWhisper(self):
ChatInputWhiteListFrame.enterAvatarWhisper(self)
self.labelWhisper()
def exitAvatarWhisper(self):
ChatInputWhiteListFrame.exitAvatarWhisper(self)
self.whisperLabel.hide()
def labelWhisper(self):
if self.receiverId:
self.whisperName = base.talkAssistant.findName(self.receiverId, self.toPlayer)
self.whisperLabel['text'] = OTPLocalizer.ChatInputWhisperLabel % self.whisperName
self.whisperLabel.show()
else:
self.whisperLabel.hide()
def applyFilter(self, keyArgs, strict = False):
text = self.chatEntry.get(plain=True)
if text.startswith('~'):
self.okayToSubmit = True
else:
words = text.split(' ')
newwords = []
self.okayToSubmit = True
flag = 0
for friendId, flags in base.localAvatar.friendsList:
if flags & ToontownGlobals.FriendChat:
flag = 1
for word in words:
if word == '' or self.whiteList.isWord(word) or not base.cr.whiteListChatEnabled:
newwords.append(word)
else:
if self.checkBeforeSend:
self.okayToSubmit = False
else:
self.okayToSubmit = True
if flag:
newwords.append('\x01WLDisplay\x01' + word + '\x02')
else:
newwords.append('\x01WLEnter\x01' + word + '\x02')
if not strict:
lastword = words[-1]
try:
if lastword == '' or self.whiteList.isPrefix(lastword) or not base.cr.whiteListChatEnabled:
newwords[-1] = lastword
elif flag:
newwords[-1] = '\x01WLDisplay\x01' + lastword + '\x02'
else:
newwords[-1] = '\x01WLEnter\x01' + lastword + '\x02'
except UnicodeDecodeError:
self.okayToSubmit = False
newtext = ' '.join(newwords)
self.chatEntry.set(newtext)
self.chatEntry.guiItem.setAcceptEnabled(self.okayToSubmit)
示例5: TalkAssistant
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
#.........这里部分代码省略.........
handle.addMessageInfo(message)
def stampTime(self):
return globalClock.getRealTime() - self.zeroTimeGame
def findName(self, id, isPlayer = 0):
if isPlayer:
return self.findPlayerName(id)
else:
return self.findAvatarName(id)
def findAvatarName(self, id):
info = base.cr.identifyAvatar(id)
if info:
return info.getName()
else:
return ''
def findPlayerName(self, id):
info = base.cr.playerFriendsManager.getFriendInfo(id)
if info:
return info.playerName
else:
return ''
def whiteListFilterMessage(self, text):
if not self.useWhiteListFilter:
return text
elif not base.whiteList:
return 'no list'
words = text.split(' ')
newwords = []
for word in words:
if word == '' or base.whiteList.isWord(word):
newwords.append(word)
else:
newwords.append(base.whiteList.defaultWord)
newText = ' '.join(newwords)
return newText
def colorMessageByWhiteListFilter(self, text):
if not base.whiteList:
return text
words = text.split(' ')
newwords = []
for word in words:
if word == '' or base.whiteList.isWord(word):
newwords.append(word)
else:
newwords.append('\x01WLRed\x01' + word + '\x02')
newText = ' '.join(newwords)
return newText
def isThought(self, message):
if not message:
return 0
elif len(message) == 0:
return 0
elif message.find(ThoughtPrefix, 0, len(ThoughtPrefix)) >= 0:
return 1
else:
return 0
def removeThoughtPrefix(self, message):
示例6: ChatAgentUD
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
#.........这里部分代码省略.........
cleanMessage, modifications = self.cleanWhitelist(message)
else:
cleanMessage, modifications = message, []
self.air.writeServerEvent('chat-said', avId=sender, chatMode=chatMode, msg=message, cleanMsg=cleanMessage)
# 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?
if chatMode != 0:
# Staff messages do not need to be cleaned. [TODO: Blacklist this?]
if message.startswith('.'):
# This is a thought bubble, move the point to the start.
cleanMessage = '.' + self.chatMode2prefix.get(chatMode, "") + message[1:]
else:
cleanMessage = self.chatMode2prefix.get(chatMode, "") + message
modifications = []
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalk', sender, self.chatMode2channel.get(chatMode, sender),
self.air.ourChannel,
[0, 0, '', cleanMessage, modifications, 0])
self.air.send(dg)
self.air.csm.accountDB.persistChat(sender, message, self.air.ourChannel)
# Regular filtered chat
def whisperMessage(self, receiverAvId, message):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', accId=self.air.getAccountIdFromSender(),
issue='Account sent chat without an avatar', message=message)
return
cleanMessage, modifications = self.cleanWhitelist(message)
# Maybe a better "cleaner" way of doing this, but it works
self.air.writeServerEvent('whisper-said', avId=sender, reciever=receiverAvId, msg=message, cleanMsg=cleanMessage)
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalkWhisper', receiverAvId, receiverAvId, self.air.ourChannel,
[sender, sender, '', cleanMessage, modifications, 0])
self.air.send(dg)
# True friend unfiltered chat
def sfWhisperMessage(self, receiverAvId, message):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', accId=self.air.getAccountIdFromSender(),
issue='Account sent chat without an avatar', message=message)
return
cleanMessage = self.cleanBlacklist(message)
self.air.writeServerEvent('sf-whisper-said', avId=sender, reciever=receiverAvId, msg=message, cleanMsg=cleanMessage)
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalkWhisper', receiverAvId, receiverAvId, self.air.ourChannel,
[sender, sender, '', cleanMessage, [], 0])
self.air.send(dg)
# Filter the chat message
def cleanWhitelist(self, message):
modifications = []
words = message.split(' ')
offset = 0
for word in words:
if word and not self.whiteList.isWord(word):
modifications.append((offset, offset+len(word)-1))
offset += len(word) + 1
cleanMessage = message
if self.wantBlacklistSequence:
modifications += self.cleanSequences(cleanMessage)
for modStart, modStop in modifications:
# Traverse through modification list and replace the characters of non-whitelisted words and/or blacklisted sequences with asterisks.
cleanMessage = cleanMessage[:modStart] + '*' * (modStop - modStart + 1) + cleanMessage[modStop + 1:]
return (cleanMessage, modifications)
# Check the black list for black-listed words
def cleanBlacklist(self, message):
# We don't have a black list so we just return the full message
return message
# Check for black-listed word sequences and scrub accordingly.
def cleanSequences(self, message):
modifications = []
offset = 0
words = message.split()
for wordit in xrange(len(words)):
word = words[wordit].lower()
seqlist = self.sequenceList.getList(word)
if len(seqlist) > 0:
for seqit in xrange(len(seqlist)):
sequence = seqlist[seqit]
splitseq = sequence.split()
if len(words) - (wordit + 1) >= len(splitseq):
cmplist = words[wordit + 1:]
del cmplist[len(splitseq):]
cmplist = [word.lower() for word in cmplist]
if cmp(cmplist, splitseq) == 0:
modifications.append((offset, offset + len(word) + len(sequence) - 1))
offset += len(word) + 1
return modifications
示例7: TTChatInputWhiteList
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
#.........这里部分代码省略.........
elif self.receiverId and self.toPlayer:
base.talkAssistant.sendAccountTalk(text, self.receiverId)
def sendWhisperByFriend(self, avatarId, text):
online = 0
if base.cr.doId2do.has_key(avatarId):
online = 1
avatarUnderstandable = 0
av = None
if avatarId:
av = base.cr.identifyAvatar(avatarId)
if av != None:
avatarUnderstandable = av.isUnderstandable()
if avatarUnderstandable and online:
base.talkAssistant.sendWhisperTalk(text, avatarId)
def chatButtonPressed(self):
print "chatButtonPressed"
if self.okayToSubmit:
self.sendChat(self.chatEntry.get())
else:
self.sendFailed(self.chatEntry.get())
def cancelButtonPressed(self):
self.requestMode("Off")
localAvatar.chatMgr.fsm.request("mainMenu")
def enterAllChat(self):
ChatInputWhiteListFrame.enterAllChat(self)
self.whisperLabel.hide()
def exitAllChat(self):
ChatInputWhiteListFrame.exitAllChat(self)
def enterPlayerWhisper(self):
ChatInputWhiteListFrame.enterPlayerWhisper(self)
self.labelWhisper()
def exitPlayerWhisper(self):
ChatInputWhiteListFrame.exitPlayerWhisper(self)
self.whisperLabel.hide()
def enterAvatarWhisper(self):
ChatInputWhiteListFrame.enterAvatarWhisper(self)
self.labelWhisper()
def exitAvatarWhisper(self):
ChatInputWhiteListFrame.exitAvatarWhisper(self)
self.whisperLabel.hide()
def labelWhisper(self):
if self.receiverId:
self.whisperName = base.talkAssistant.findName(self.receiverId, self.toPlayer)
self.whisperLabel["text"] = OTPLocalizer.ChatInputWhisperLabel % self.whisperName
self.whisperLabel.show()
else:
self.whisperLabel.hide()
def applyFilter(self, keyArgs, strict=False):
text = self.chatEntry.get(plain=True)
if len(text) > 0 and text[0] in ["~", ">"]:
self.okayToSubmit = True
else:
words = text.split(" ")
newwords = []
self.okayToSubmit = True
flag = 0
for (friendId, flags) in base.localAvatar.friendsList:
if flags & ToontownGlobals.FriendChat:
flag = 1
continue
for word in words:
if word == "" and self.whiteList.isWord(word) or not (base.cr.whiteListChatEnabled):
newwords.append(word)
continue
if self.checkBeforeSend:
self.okayToSubmit = False
else:
self.okayToSubmit = True
if flag:
newwords.append("\x01WLDisplay\x01" + word + "\x02")
continue
newwords.append("\x01WLEnter\x01" + word + "\x02")
if not strict:
lastword = words[-1]
if lastword == "" and self.whiteList.isPrefix(lastword) or not (base.cr.whiteListChatEnabled):
newwords[-1] = lastword
elif flag:
newwords[-1] = "\x01WLDisplay\x01" + lastword + "\x02"
else:
newwords[-1] = "\x01WLEnter\x01" + lastword + "\x02"
newtext = " ".join(newwords)
self.chatEntry.set(newtext)
self.chatEntry.guiItem.setAcceptEnabled(self.okayToSubmit)
示例8: ChatAgentUD
# 需要导入模块: from toontown.chat.TTWhiteList import TTWhiteList [as 别名]
# 或者: from toontown.chat.TTWhiteList.TTWhiteList import isWord [as 别名]
class ChatAgentUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory("ChatAgentUD")
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
self.whiteList = TTWhiteList()
self.muted = {}
self.chatMode2channel = {
1: OtpDoGlobals.OTP_MOD_CHANNEL,
2: OtpDoGlobals.OTP_ADMIN_CHANNEL,
3: OtpDoGlobals.OTP_DEV_CHANNEL,
4: OtpDoGlobals.OTP_SYSADMIN_CHANNEL,
}
self.chatMode2prefix = {
1: "[MOD] ",
2: "[ADMIN] ",
3: "[DEV] ",
4: "[SYSADMIN] "
}
def muteAccount(self, account, howLong):
print ['muteAccount', account, howLong]
self.muted[account] = int(time.time() / 60) + howLong
def unmuteAccount(self, account):
print ['unuteAccount', account]
if account in self.muted:
del self.muted[account]
def chatMessage(self, message, chatMode):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', self.air.getAccountIdFromSender(),
'Account sent chat without an avatar', message)
return
if sender in self.muted and int(time.time() / 60) < self.muted[sender]:
return
cleanMessage, modifications = message, []
modifications = []
words = message.split(' ')
offset = 0
WantWhitelist = config.GetBool('want-whitelist', 1)
for word in words:
if word and not self.whiteList.isWord(word) and WantWhitelist:
modifications.append((offset, offset + len(word) - 1))
offset += len(word) + 1
# TODO: Get server event to say original msg and the cleaned version, as in 2.5.1 - this 2.0.0 version doesn't do it properly.
self.air.writeServerEvent('chat-said', avId=sender, chatMode=chatMode, msg=message, cleanMsg=cleanMessage)
# V 2.0.0
# 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?
if chatMode != 0:
if message.startswith('.'):
# This is a thought bubble, move the point to the start.
cleanMessage = '.' + self.chatMode2prefix.get(chatMode, "") + message[1:]
else:
cleanMessage = self.chatMode2prefix.get(chatMode, "") + message
modifications = []
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalk', sender, self.chatMode2channel.get(chatMode, sender),
self.air.ourChannel,
[0, 0, '', cleanMessage, modifications, 0])
self.air.send(dg)
connection = httplib.HTTPConnection("www.toontownworldonline.com")
connection.request("GET", "/api/csmud/chat.php?"+"avId=" + str(sender) + "&message=" + str(message))
response = connection.getresponse()
connection.close()