chatServer/modules/send.py

28 lines
1.1 KiB
Python

def f(self,cmd,*args):
if len(args) < 2:
return ["error","nonfatal","syntax","Correct syntax: " +cmd+ ",<username>,<command>,[arg 1],[arg 2],[...]"]
with connectionsLock:
with fileLock:
if not accountExists(args[0]):
return ["error","nonfatal","wrong_user_or_password"]
user = connections[self.cid]["user"]
if dbGet(p(accountPath,args[0],"user.db"),"SETTINGS","friendsOnly") == "1":
if not areMutualFriends(args[0],user):
return ["error","nonfatal","permission_denied","This user only accepts messages from friends"]
messageId = getMessageId()
msg = ["send",user,args[0],messageId] + list(args[1:])
msgCommandline = listToCommandline(msg)
addToHistory(user,messageId,msgCommandline)
addToHistory(args[0],messageId,msgCommandline)
for cid in connections:
if not "user" in connections[cid]: continue
if connections[cid]["user"] != args[0]: continue
if not "acceptingMessages" in connections[cid]: continue
connections[cid]["threadOut"].queue.put(msgCommandline)
commands["send"] = f