Created method to send private messages

This commit is contained in:
SecretlyTaco 2018-03-22 23:22:20 +00:00
parent afe3395d48
commit fc5100c515

View file

@ -1,6 +1,7 @@
from pymongo import MongoClient
from bson.objectid import ObjectId
from backend import accounts
import datetime
client = MongoClient()
db = client.tweeder
@ -13,16 +14,23 @@ def send_message(msg_from, msg_to, msg_content):
from_id = accounts.get_profile(msg_from)['_id']
elif type(msg_from) == ObjectId:
from_id = msg_from
msg_from = accounts_db.find_one({'_id': from_id})['displayname']
if type(msg_to) == str:
to_id = accounts.get_profile(msg_to)['_id']
elif type(msg_to) == ObjectId:
to_id = msg_to
msg_to = accounts_db.find_one({'_id': to_id})['displayname']
currentTimeDate = datetime.datetime.now()
message = {
'from': from_id,
'to': to_id,
'content': msg_content
'fromName': msg_from,
'toName': msg_to,
'content': msg_content,
'timeSent': currentTimeDate
}
messages_db.insert_one(message)
messages_db.insert_one(message)