Poodletooth-iLand/otp/chat/ChatAgent.py

52 lines
1.8 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal
2015-04-02 07:23:24 -05:00
from otp.ai.MagicWordGlobal import *
2015-03-03 16:10:12 -06:00
class ChatAgent(DistributedObjectGlobal):
2015-06-03 14:15:01 -05:00
2015-03-03 16:10:12 -06:00
def __init__(self, cr):
DistributedObjectGlobal.__init__(self, cr)
2015-06-03 14:15:01 -05:00
self.cr.chatAgent = self
2015-04-02 07:23:24 -05:00
self.chatMode = 0
2015-03-03 16:10:12 -06:00
def delete(self):
self.ignoreAll()
2015-04-02 07:23:24 -05:00
self.cr.chatAgent = None
2015-03-03 16:10:12 -06:00
DistributedObjectGlobal.delete(self)
2015-05-24 11:04:49 -05:00
def verifyMessage(self, message):
try:
message.decode('ascii')
return True
except:
return False
2015-03-03 16:10:12 -06:00
def sendChatMessage(self, message):
2015-05-24 11:04:49 -05:00
if not self.verifyMessage(message):
return
2015-04-02 07:23:24 -05:00
self.sendUpdate('chatMessage', [message, self.chatMode])
@magicWord(category=CATEGORY_MODERATOR, types=[int])
def chatmode(mode=-1):
""" Set the chat mode of the current avatar. """
mode2name = {
0 : "user",
1 : "moderator",
2 : "administrator",
3 : "system administrator",
}
if base.cr.chatAgent is None:
return "No ChatAgent found."
if mode == -1:
return "You are currently talking in the %s chat mode." % mode2name.get(base.cr.chatAgent.chatMode, "N/A")
if not 0 <= mode <= 3:
return "Invalid chat mode specified."
if mode == 3 and spellbook.getInvoker().getAdminAccess() < 500:
return "Chat mode 3 is reserved for system administrators."
if mode == 2 and spellbook.getInvoker().getAdminAccess() < 400:
return "Chat mode 2 is reserved for administrators."
if mode == 1 and spellbook.getInvoker().getAdminAccess() < 200:
# Like this will ever happen, but whatever.
return "Chat mode 1 is reserved for moderators."
base.cr.chatAgent.chatMode = mode
2015-07-05 18:59:25 -05:00
return "You are now talking in the %s chat mode." % mode2name.get(mode, "N/A")