Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_incoming_message(self, text, addr="Alice "):
msg = Message.new_empty(self.account, "text")
msg.set_text(text)
name, routeable_addr = parseaddr(addr)
contact = self.account.create_contact(email=routeable_addr, name=name)
chat = self.account.create_chat_by_contact(contact)
msg_in = chat.prepare_message(msg)
return msg_in
def __init__(self, incoming_message, text, terminal=False):
self.incoming_message = incoming_message
self.chat = self.incoming_message.chat
self.msg = Message.new_empty(self.chat.account, "text")
self.msg.set_text(text)
self.terminal = terminal
def get_chat(self, ref):
""" Return a 1:1 chat (creating one if needed) from the specified ref object.
ref can be a Message, Contact, email address string or chat-id integer.
"""
if isinstance(ref, dc.message.Message):
return self.account.create_chat_by_message(ref)
elif isinstance(ref, dc.contact.Contact):
return self.account.create_chat_by_contact(ref)
elif isinstance(ref, str) and '@' in ref:
return self.account.create_contact(ref).get_chat()
elif type(ref) is int:
try:
return self.account.get_chat_by_id(ref)
except ValueError:
return None