Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
reactions: bool = False,
commands: bool = False,
substitution: bool = False) -> Message:
author = author or chat.self
uid = f"__msg_id_{uuid4()}__"
message = Message(
chat=chat, author=author,
type=msg_type, target=target, uid=uid,
file=file_path.open('rb'), filename=file_path.name,
path=file_path, mime=mime,
text=f"Content of {msg_type.name} message with ID {uid}",
deliver_to=coordinator.master
)
message = self.attach_message_properties(message, reactions, commands, substitution)
self.messages_sent[uid] = message
coordinator.send_message(message)
return message
def edit_file_like_message(self, message: Message,
file_path: Path,
mime: str,
reactions: bool = False,
commands: bool = False,
substitution: bool = False) -> Message:
message.text = f"Content of edited {message.type.name} media with ID {message.uid}"
message.edit = True
message.edit_media = True
message.file = file_path.open('rb')
message.filename = file_path.name
message.path = file_path
message.mime = mime
message = self.attach_message_properties(message, reactions, commands, substitution)
self.messages_sent[message.uid] = message
coordinator.send_message(message)
return message
def send_location_msg(self):
slave = next(iter(coordinator.slaves.values()))
alice = slave.get_chat('alice')
msg = EFBMsg()
msg.deliver_to = slave
msg.chat = alice
msg.author = EFBChat(self).self()
msg.type = MsgType.Location
msg.text = "I'm not here."
msg.attributes = EFBMsgLocationAttribute(latitude=0.1, longitude=1.0)
return coordinator.send_message(msg)
def send_link_msg(self):
slave = next(iter(coordinator.slaves.values()))
alice = slave.get_chat('alice')
msg = EFBMsg()
msg.deliver_to = slave
msg.chat = alice
msg.author = EFBChat(self).self()
msg.type = MsgType.Link
msg.text = "Check it out."
msg.attributes = EFBMsgLinkAttribute(
title="Example",
url="https://example.com"
)
return coordinator.send_message(msg)
context['message_type'] = 'group'
self.logger.debug(repr(context))
chat = self.chat_manager.build_efb_chat_as_group(context)
try:
author = chat.get_member(SystemChatMember.SYSTEM_ID)
except KeyError:
author = chat.add_system_member()
msg = Message(
uid="__group_notice__.%s" % int(time.time()),
type=MsgType.Text,
chat=chat,
author=author,
text=context['message'],
deliver_to=coordinator.master
)
coordinator.send_message(msg)
uid=f"__reauth__.{uuid4()}",
type=MsgType.Text,
)
on_log_out = self.flag("on_log_out")
on_log_out = on_log_out if on_log_out in (
"command", "idle", "reauth") else "command"
if on_log_out == "command":
msg.type = MsgType.Text
msg.commands = MessageCommands(
[MessageCommand(name=self._("Log in again"), callable_name="reauth", kwargs={"command": True})])
elif on_log_out == "reauth":
if self.flag("qr_reload") == "console_qr_code":
msg.text += "\n" + self._("Please check your log to continue.")
self.reauth()
coordinator.send_message(msg)
def reply_message(self, message: EFBMsg, text: str):
reply = EFBMsg()
reply.text = text
reply.chat = coordinator.slaves[message.chat.channel_id].get_chat(message.chat.chat_uid)
reply.author = self.chat
reply.type = MsgType.Text
reply.deliver_to = coordinator.master
reply.target = message
reply.uid = str(uuid.uuid4())
coordinator.send_message(reply)
# Format message IDs as JSON of List[List[str]].
efb_msg.uid = MessageID(json.dumps(
[[str(getattr(msg, "id", constants.INVALID_MESSAGE_ID + str(uuid.uuid4())))]]
))
if not efb_msg.chat or not efb_msg.author:
chat, author = self.get_chat_and_author(msg)
# Do not override what's defined in the wrapped methods
efb_msg.chat = efb_msg.chat or chat
efb_msg.author = efb_msg.author or author
logger.debug("[%s] Chat: %s, Author: %s", efb_msg.uid, efb_msg.chat, efb_msg.author)
coordinator.send_message(efb_msg)
if efb_msg.file:
efb_msg.file.close()
msg.type = MsgType.Image
file = NamedTemporaryFile(suffix=".png")
qr_url = "https://login.weixin.qq.com/l/" + uuid
QRCode(qr_url).png(file, scale=10)
msg.text = self._("QR code expired, please scan the new one.")
msg.path = Path(file.name)
msg.file = file
msg.mime = 'image/png'
if self.master_qr_picture_id is not None:
msg.edit = True
msg.edit_media = True
msg.uid = self.master_qr_picture_id
else:
self.master_qr_picture_id = msg.uid
if status in (200, 201) or uuid != self.qr_uuid:
coordinator.send_message(msg)
except KeyError:
author = chat.add_system_member()
msg = Message(
uid="__{context[uid_prefix]}__.{uni_id}".format(context=context,
uni_id=str(int(time.time()))),
type=MsgType.Text,
chat=chat,
author=author,
deliver_to=coordinator.master
)
if 'message' in context:
msg.text = context['message']
if 'commands' in context:
msg.commands = MessageCommands(context['commands'])
coordinator.send_message(msg)