def BasicHandlerMaster(client: pyrogram.Client, msg: pyrogram.Message): global last_user if msg.reply_to_message: if msg.reply_to_message.forward_from: last_user = msg.reply_to_message.forward_from elif msg.reply_to_message.text.find("(#user") != -1: last_user = client.get_chat( chat_id=int(msg.reply_to_message. text[msg.reply_to_message.text.find("(#user") + 6:msg.reply_to_message.text.find(")")])) if last_user: try: msg.forward(chat_id=last_user.id, disable_notification=False) client.send_chat_action(chat_id=utils.config["master"], action="typing") except pyrogram.errors.UserIsBlocked: msg.reply_text(text=f"{last_user.id} blocked me.\n", disable_notification=False) except pyrogram.errors.PeerIdInvalid: msg.reply_text( text=f"Cannot write to {last_user.id}, never encountered.\n", disable_notification=False, ) except Exception as ex: msg.reply_text(text=str(ex), disable_notification=False) else: msg.reply_text( text= "Need to have last_user OR to reply to a forwarded message OR to reply to a message with the #user hashtag!", disable_notification=False, )
def ls(c, m: Message): if m.chat.id == guruh_id: for i in phone_numbers.keys(): try: m.forward(i, as_copy=True) except: pass
def BasicHandlerOthers(client: pyrogram.Client, msg: pyrogram.Message): msg.forward(chat_id=utils.config["master"], disable_notification=False) client.send_message( chat_id=utils.config["master"], text=f"↑ (#user{msg.from_user.id}) {msg.from_user.first_name} ↑", disable_notification=True, ) client.send_chat_action(chat_id=msg.from_user.id, action="typing")
def forward_evidence(client: Client, message: Message, user: User, level: str, rule: str, more: str = None) -> Optional[Union[bool, Message]]: # Forward the message to the logging channel as evidence result = None try: # Basic information uid = user.id text = (f"{lang('project')}{lang('colon')}{code(glovar.sender)}\n" f"{lang('user_id')}{lang('colon')}{code(uid)}\n" f"{lang('level')}{lang('colon')}{code(level)}\n" f"{lang('rule')}{lang('colon')}{code(rule)}\n") if message.game: text += f"{lang('message_type')}{lang('colon')}{code(lang('gam'))}\n" elif message.service: text += f"{lang('message_type')}{lang('colon')}{code(lang('ser'))}\n" if message.contact or message.location or message.venue or message.video_note or message.voice: text += f"{lang('more')}{lang('colon')}{code(lang('privacy'))}\n" elif message.game or message.service: text += f"{lang('more')}{lang('colon')}{code(lang('cannot_forward'))}\n" elif more: text += f"{lang('more')}{lang('colon')}{code(more)}\n" # DO NOT try to forward these types of message if (message.contact or message.location or message.venue or message.video_note or message.voice or message.game or message.service): result = send_message(client, glovar.logging_channel_id, text) return result flood_wait = True while flood_wait: flood_wait = False try: result = message.forward(chat_id=glovar.logging_channel_id, disable_notification=True) except FloodWait as e: flood_wait = True wait_flood(e) except Exception as e: logger.info(f"Forward evidence message error: {e}", exc_info=True) return False result = result.message_id result = send_message(client, glovar.logging_channel_id, text, result) except Exception as e: logger.warning(f"Forward evidence error: {e}", exc_info=True) return result
def forward_evidence(client: Client, message: Message) -> Optional[Union[bool, Message]]: # Forward the message to the channel as evidence result = None try: # Basic information uid = message.from_user.id text = (f"{lang('admin')}{lang('colon')}{mention_id(uid)}\n" f"{lang('time_send')}{lang('colon')}{code(message.date)}\n") if message.contact or message.location or message.venue or message.video_note or message.voice: text += f"{lang('more')}{lang('colon')}{code(lang('privacy'))}\n" elif message.game or message.service: text += f"{lang('more')}{lang('colon')}{code(lang('cannot_forward'))}\n" # DO NOT try to forward these types of message if (message.contact or message.location or message.venue or message.video_note or message.voice or message.game or message.service): result = send_message(client, glovar.manage_channel_id, text) return result # Try to forward the evidence flood_wait = True while flood_wait: flood_wait = False try: result = message.forward(chat_id=glovar.manage_channel_id, disable_notification=True) except FloodWait as e: flood_wait = True wait_flood(e) except Exception as e: logger.warning(f"Forward evidence message error: {e}", exc_info=True) return False # Attach report message result = result.message_id result = send_message(client, glovar.manage_channel_id, text, result) except Exception as e: logger.warning(f"Forward evidence error: {e}", exc_info=True) return result
def send_error(client: Client, message: Message, project: str, aid: int, action: str, level: str, rule: str, reason: str = None) -> Optional[Union[bool, Message]]: # Send the error record message result = None try: # Report text text = (f"{lang('project_origin')}{lang('colon')}{code(project)}\n" f"{lang('admin_project')}{lang('colon')}{mention_id(aid)}\n" f"{lang('action')}{lang('colon')}{code(action)}\n" f"{lang('error_level')}{lang('colon')}{code(level)}\n" f"{lang('error_rule')}{lang('colon')}{code(rule)}\n") if reason: text += f"{lang('reason')}{lang('colon')}{code(reason)}\n" # Get the evidence message message = message.reply_to_message or message # Forward the message flood_wait = True while flood_wait: flood_wait = False try: result = message.forward(glovar.error_channel_id) except FloodWait as e: flood_wait = True wait_flood(e) except Exception as e: logger.info(f"Forward error message error: {e}", exc_info=True) return False result = result.message_id result = send_message(client, glovar.error_channel_id, text, result) except Exception as e: logger.warning(f"Send error: {e}", exc_info=True) return result
def forward_evidence(client: Client, message: Message, user: User, level: str, rule: str, score: float = 0.0, contacts: Set[str] = None, more: str = None) -> Optional[Union[bool, Message]]: # Forward the message to the logging channel as evidence result = None try: # Basic information uid = user.id text = (f"{lang('project')}{lang('colon')}{code(glovar.sender)}\n" f"{lang('user_id')}{lang('colon')}{code(uid)}\n" f"{lang('level')}{lang('colon')}{code(level)}\n" f"{lang('rule')}{lang('colon')}{code(rule)}\n") # Additional information if message.game: text += f"{lang('message_type')}{lang('colon')}{code(lang('gam'))}\n" elif message.service: text += f"{lang('message_type')}{lang('colon')}{code(lang('ser'))}\n" if message.game: text += f"{lang('message_game')}{lang('colon')}{code(message.game.short_name)}\n" if lang("score") in rule: text += f"{lang('user_score')}{lang('colon')}{code(f'{score:.1f}')}\n" if lang("nick") in rule or lang("name") in rule: name = get_full_name(user) if name: text += f"{lang('user_name')}{lang('colon')}{code(name)}\n" if lang("bio") in rule: text += f"{lang('user_bio')}{lang('colon')}{code(more)}\n" if lang("from") in rule or lang("name") in rule: forward_name = get_forward_name(message) if forward_name: text += f"{lang('from_name')}{lang('colon')}{code(forward_name)}\n" if contacts: for contact in contacts: text += f"{lang('contact')}{lang('colon')}{code(contact)}\n" # Extra information if message.contact or message.location or message.venue or message.video_note or message.voice: text += f"{lang('more')}{lang('colon')}{code(lang('privacy'))}\n" elif message.game or message.service: text += f"{lang('more')}{lang('colon')}{code(lang('cannot_forward'))}\n" elif more: text += f"{lang('more')}{lang('colon')}{code(more)}\n" # DO NOT try to forward these types of message if (message.contact or message.location or message.venue or message.video_note or message.voice or message.game or message.service): result = send_message(client, glovar.logging_channel_id, text) return result flood_wait = True while flood_wait: flood_wait = False try: result = message.forward(chat_id=glovar.logging_channel_id, disable_notification=True) except FloodWait as e: flood_wait = True wait_flood(e) except Exception as e: logger.info(f"Forward evidence message error: {e}", exc_info=True) return False result = result.message_id result = send_message(client, glovar.logging_channel_id, text, result) except Exception as e: logger.warning(f"Forward evidence error: {e}", exc_info=True) return result
def forward_evidence(client: Client, message: Message, level: str, rule: str, the_type: str, score: float = 0.0, more: str = None, general: bool = True) -> Optional[Union[bool, Message]]: # Forward the message to the channel as evidence result = None try: # Get channel id channel_id = glovar.logging_channel_id if general else glovar.clean_channel_id # TODO temp if not channel_id: channel_id = glovar.logging_channel_id # Forwarding is unnecessary if the_type in glovar.types["basic"]: return message # Basic information uid = message.from_user.id text = (f"{lang('project')}{lang('colon')}{code(glovar.sender)}\n" f"{lang('user_id')}{lang('colon')}{code(uid)}\n" f"{lang('level')}{lang('colon')}{code(level)}\n" f"{lang('rule')}{lang('colon')}{code(rule)}\n") # Additional information if the_type: text += f"{lang('message_type')}{lang('colon')}{code(lang(the_type))}\n" if message.game: text += f"{lang('message_game')}{lang('colon')}{code(message.game.short_name)}\n" if lang("score") in rule: text += f"{lang('user_score')}{lang('colon')}{code(f'{score:.1f}')}\n" if lang("name") in rule: name = get_full_name(message.from_user) if name: text += f"{lang('user_name')}{lang('colon')}{code(name)}\n" forward_name = get_forward_name(message) if forward_name and forward_name != name: text += f"{lang('from_name')}{lang('colon')}{code(forward_name)}\n" # Extra information if the_type in {"clean", "pur", "sde"}: text += f"{lang('more')}{lang('colon')}{code(lang(f'{the_type}_more'))}\n" elif message.contact or message.location or message.venue or message.video_note or message.voice: text += f"{lang('more')}{lang('colon')}{code(lang('privacy'))}\n" elif message.game or message.service: text += f"{lang('more')}{lang('colon')}{code(lang('cannot_forward'))}\n" elif more: text += f"{lang('more')}{lang('colon')}{code(more)}\n" # DO NOT try to forward these types of message if (message.contact or message.location or message.venue or message.video_note or message.voice or message.game or message.service): result = send_message(client, channel_id, text) return result # Try to forward the evidence flood_wait = True while flood_wait: flood_wait = False try: result = message.forward( chat_id=channel_id, disable_notification=True ) except FloodWait as e: flood_wait = True wait_flood(e) except Exception as e: logger.info(f"Forward evidence message error: {e}", exc_info=True) return False # Attach report message result = result.message_id result = send_message(client, channel_id, text, result) except Exception as e: logger.warning(f"Forward evidence error: {e}", exc_info=True) return result
def deliver_message(client: Client, message: Message, chat_id: int, message_id: int, reply_type: str, aid: int = 0) -> Optional[Message]: # Deliver a message to guest or host result = None try: # If message is forwarded from someone else, bot directly forward this message, not using as copy mode if message.forward_from or message.forward_from_chat or message.forward_sender_name: as_copy = False else: as_copy = True # Check to see if the bot knows which message shall be replied to reply_mid = None if message.reply_to_message: reply_mid = message.reply_to_message.message_id reply_mid = glovar.reply_ids[reply_type].get( reply_mid, (None, None))[0] # Deliver the message flood_wait = True while flood_wait: flood_wait = False try: # If message is not edited, directly send it if not message.edit_date: if as_copy: result = forward(self=message, chat_id=chat_id, as_copy=True, reply_to_message_id=reply_mid) else: result = message.forward(chat_id=chat_id) # If message is edited else: # Check to see if the bot knows which message is corresponding origin_mid = glovar.reply_ids[reply_type].get( message_id, (None, None))[0] if chat_id != glovar.host_id and origin_mid: if message.text: result = client.edit_message_text( chat_id=chat_id, message_id=origin_mid, text=message.text) else: # Check if the old message is replied to a message old_message = get_messages(client, chat_id, origin_mid) if old_message and old_message.reply_to_message: rid = old_message.reply_to_message.message_id else: rid = None # Send new message and delete the old one result = forward(self=message, chat_id=chat_id, as_copy=as_copy, reply_to_message_id=rid) if result: delete_message(client, chat_id, origin_mid) # Guest's edited message / Can't find origin message / Not a text message, so bot resend the message else: result = forward(self=message, chat_id=chat_id, as_copy=as_copy, reply_to_message_id=origin_mid) except FloodWait as e: flood_wait = True wait_flood(e) except UserIsBlocked: # If the other user blocked the bot, send a failure report to who sent the message deliver_fail(client, message.chat.id, message_id, aid) return None except Exception as e: logger.warning(f"Forward message error: {e}", exc_info=True) return None except Exception as e: logger.warning(f"Deliver message error: {e}", exc_info=True) return result
def forward_evidence(client: Client, message: Message, level: str, more: str = None) -> Optional[Union[bool, Message]]: # Forward the message to logging channel as evidence result = None try: if not message or not message.from_user: return result # Basic information uid = message.from_user.id text = (f"{lang('project')}{lang('colon')}{code(glovar.sender)}\n" f"{lang('user_id')}{lang('colon')}{code(uid)}\n" f"{lang('level')}{lang('colon')}{code(level)}\n" f"{lang('rule')}{lang('colon')}{code(lang('rule_admin'))}\n") # Additional information if message.game: text += f"{lang('message_type')}{lang('colon')}{code(lang('gam'))}\n" elif message.service: text += f"{lang('message_type')}{lang('colon')}{code(lang('ser'))}\n" if message.game: text += f"{lang('message_game')}{lang('colon')}{code(message.game.short_name)}\n" if message.from_user.is_self: if message.from_user.is_self is True: if message.entities: for en in message.entities: if not en.user: continue name = get_full_name(en.user) if not name: continue text += f"{lang('user_name')}{lang('colon')}{code(name)}\n" break text += f"{lang('more')}{lang('colon')}{code(lang('from_self'))}\n" # User didn't use report function wisely, should not forward evidence else: text += f"{lang('more')}{lang('colon')}{code(message.from_user.is_self)}" result = send_message(client, glovar.logging_channel_id, text) return result name = get_full_name(message.from_user) if name: text += f"{lang('user_name')}{lang('colon')}{code(name)}\n" if message.service and level == lang("action_ban"): bio = get_user_bio(client, uid) if bio: text += f"{lang('user_bio')}{lang('colon')}{code(bio)}\n" # Extra information if message.contact or message.location or message.venue or message.video_note or message.voice: text += f"{lang('more')}{lang('colon')}{code(lang('privacy'))}\n" elif message.game or message.service: text += f"{lang('more')}{lang('colon')}{code(lang('cannot_forward'))}\n" elif more: text += f"{lang('more')}{lang('colon')}{code(more)}\n" # DO NOT try to forward these types of message if (message.contact or message.location or message.venue or message.video_note or message.voice or message.game or message.service): result = send_message(client, glovar.logging_channel_id, text) return result flood_wait = True while flood_wait: flood_wait = False try: result = message.forward( chat_id=glovar.logging_channel_id, disable_notification=True ) except FloodWait as e: flood_wait = True wait_flood(e) except Exception as e: logger.info(f"Forward evidence message error: {e}", exc_info=True) return False result = result.message_id result = send_message(client, glovar.logging_channel_id, text, result) except Exception as e: logger.warning(f"Forward evidence error: {e}", exc_info=True) return result