Poodletooth-iLand/otp/chat/ChatAgentUD.py

40 lines
1.6 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobalUD
2015-04-02 07:23:24 -05:00
from otp.distributed import OtpDoGlobals
2015-03-03 16:10:12 -06:00
class ChatAgentUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory("ChatAgentUD")
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
2015-05-30 12:46:06 -05:00
2015-04-02 07:23:24 -05:00
self.chatMode2channel = {
1 : OtpDoGlobals.OTP_MOD_CHANNEL,
2 : OtpDoGlobals.OTP_ADMIN_CHANNEL,
3 : OtpDoGlobals.OTP_SYSADMIN_CHANNEL,
}
self.chatMode2prefix = {
1 : "[MOD] ",
2 : "[ADMIN] ",
3 : "[SYSADMIN] ",
}
2015-05-30 12:46:06 -05:00
2015-04-02 07:23:24 -05:00
def chatMessage(self, message, chatMode):
sender = self.air.getAvatarIdFromSender()
2015-05-30 12:46:06 -05:00
2015-04-02 07:23:24 -05:00
if sender == 0:
self.air.writeServerEvent('suspicious', accId=self.air.getAccountIdFromSender(),
2015-05-30 12:46:06 -05:00
issue='Account sent chat without an avatar', message=message)
2015-04-02 07:23:24 -05:00
return
2015-05-30 12:46:06 -05:00
self.air.writeServerEvent('chat-said', avId=sender, chatMode=chatMode, msg=message)
2015-04-02 07:23:24 -05:00
if chatMode != 0:
if message.startswith('.'):
2015-05-30 12:46:06 -05:00
message = '.' + self.chatMode2prefix.get(chatMode, "") + message[1:]
2015-04-02 07:23:24 -05:00
else:
2015-05-30 12:46:06 -05:00
message = self.chatMode2prefix.get(chatMode, "") + message
2015-04-02 07:23:24 -05:00
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
2015-05-30 12:46:06 -05:00
dg = DistributedAvatar.aiFormatUpdate('setTalk', sender, self.chatMode2channel.get(chatMode, sender), self.air.ourChannel, [message])
self.air.send(dg)