From 53cb245acae4b2a9ee5eb86b926834939f08a0a7 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Thu, 25 Jun 2020 17:33:29 +0200 Subject: [PATCH] Partially translated the config to italian and minor fixes --- BotBase/methods/safe_edit.py | 84 ------------------------- BotBase/methods/safe_send.py | 117 ----------------------------------- BotBase/methods/various.py | 79 ----------------------- BotBase/modules/antiflood.py | 2 +- README.md | 2 +- 5 files changed, 2 insertions(+), 282 deletions(-) delete mode 100755 BotBase/methods/safe_edit.py delete mode 100755 BotBase/methods/safe_send.py delete mode 100755 BotBase/methods/various.py diff --git a/BotBase/methods/safe_edit.py b/BotBase/methods/safe_edit.py deleted file mode 100755 index 768db3d..0000000 --- a/BotBase/methods/safe_edit.py +++ /dev/null @@ -1,84 +0,0 @@ -from pyrogram.errors import RPCError, FloodWait -import time -import logging -from pyrogram import Client, CallbackQuery -from typing import Union - - -def edit_message_text(update: Union[CallbackQuery, Client], sleep: bool = True, *args, **kwargs): - """Edits a message in a way that never triggers exceptions and logs errors - - :param update: The pyrogram.Client instance or pyrogram.CallbackQuery - object to call the method for - :type update: Union[Client, CallbackQuery] - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - :returns: Whatever the called pyrogram method returns, or an exception if - the method call caused an error - """ - - try: - return update.edit_message_text(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def edit_message_caption(update: Union[CallbackQuery, Client], sleep: bool = True, *args, **kwargs): - """Edits a message caption in a way that never triggers exceptions and logs errors - - :param update: The pyrogram.Client instance or pyrogram.CallbackQuery - object to call the method for - :type update: Union[Client, CallbackQuery] - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - :returns: Whatever the called pyrogram method returns, or an exception if - the method call caused an error - """ - - try: - return update.edit_message_caption(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def edit_message_media(update: Union[CallbackQuery, Client], sleep: bool = True, *args, **kwargs): - """Edits a message media in a way that never triggers exceptions and logs errors - - :param update: The pyrogram.Client instance or pyrogram.CallbackQuery - object to call the method for - :type update: Union[Client, CallbackQuery] - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - :returns: Whatever the called pyrogram method returns, or an exception if - the method call caused an error - """ - - try: - return update.edit_message_media(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - diff --git a/BotBase/methods/safe_send.py b/BotBase/methods/safe_send.py deleted file mode 100755 index 5e23ee8..0000000 --- a/BotBase/methods/safe_send.py +++ /dev/null @@ -1,117 +0,0 @@ -from pyrogram.errors import RPCError, FloodWait -from pyrogram import Client -import time -import logging - - -def send_message(client: Client, sleep: bool = True, *args, **kwargs): - """Sends a message in a way that never triggers exceptions and logs errors - - :param client: The pyrogram.Client instance to call the method for - :type client: class: Client - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - """ - - try: - return client.send_message(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def send_photo(client: Client, sleep: bool = True, *args, **kwargs): - """Sends a photo in a way that never triggers exceptions and logs errors - - :param client: The pyrogram.Client instance to call the method for - :type client: class: Client - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - """ - - try: - return client.send_photo(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def send_audio(client: Client, sleep: bool = True, *args, **kwargs): - """Sends an audio in a way that never triggers exceptions and logs errors - - :param client: The pyrogram.Client instance to call the method for - :type client: class: Client - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - """ - - try: - return client.send_audio(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def send_sticker(client: Client, sleep: bool = True, *args, **kwargs): - """Sends a sticker in a way that never triggers exceptions and logs errors - - :param client: The pyrogram.Client instance to call the method for - :type client: class: Client - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - """ - try: - return client.send_sticker(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def send_animation(client: Client, sleep: bool = True, *args, **kwargs): - """Sends an animation in a way that never triggers exceptions and logs errors - - :param client: The pyrogram.Client instance to call the method for - :type client: class: Client - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - """ - try: - return client.send_animation(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error diff --git a/BotBase/methods/various.py b/BotBase/methods/various.py deleted file mode 100755 index c9f17f4..0000000 --- a/BotBase/methods/various.py +++ /dev/null @@ -1,79 +0,0 @@ -from pyrogram.errors import RPCError, FloodWait -import time -from pyrogram import CallbackQuery -import logging - - -def answer(query: CallbackQuery, sleep: bool = True, *args, **kwargs): - """Answers a query in a way that never triggers exceptions and logs errors - - :param query: The pyrogram.CallbackQuery object to call the method for - :type query: class: CallbackQuery - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - :returns: Whatever the called pyrogram method returns, or an exception if - the method call caused an error - """ - - try: - return query.answer(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def delete_messages(client, sleep: bool = True, *args, **kwargs): - """Deletes messages in a way that never triggers exceptions and logs errors - - :param client: The pyrogram.Client instance to call the method for - :type client: class: Client - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - :returns: Whatever the called pyrogram method returns, or an exception if - the method call caused an error - """ - - try: - return client.delete_messages(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error - - -def get_users(client, sleep: bool = True, *args, **kwargs): - """Calls get_users in a way that never triggers exceptions and logs errors - - :param client: The pyrogram.Client instance to call the method for - :type client: class: Client - :param sleep: If True, the default, the function will call time.sleep() - in case of a FloodWait exception and return the exception object - after the sleep is done, otherwise the ``FloodWait`` exception is returned - immediately - :returns: Whatever the called pyrogram method returns, or an exception if - the method call caused an error - """ - - try: - return client.get_users(*args, **kwargs) - except FloodWait as fw: - logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") - if sleep: - time.sleep(fw.x) - return fw - except RPCError as generic_error: - logging.error(f"An exception occurred: {generic_error}") - return generic_error diff --git a/BotBase/modules/antiflood.py b/BotBase/modules/antiflood.py index 572a0a0..111c4ac 100644 --- a/BotBase/modules/antiflood.py +++ b/BotBase/modules/antiflood.py @@ -55,7 +55,7 @@ def anti_flood(client, update): if FLOOD_NOTICE: wrapper.send_message(user_id, FLOOD_NOTICE) if DELETE_MESSAGES: - wrapper.delete_messages(chat, filter(bool, updates)) + wrapper.delete_messages(chat, updates) else: if user_id in MESSAGES: del MESSAGES[user_id] diff --git a/README.md b/README.md index 09cbcdd..f455348 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The available commands are: - `/whisper ID msg`: Send `msg` to a specific user given its ID. HTML and markdown formatting supported - `/update ID`: Updates the user's info in the database, if they've changed - `/busy`: Sets your admin status as busy/not busy to silence/unsilence support requests to you -- `/userbyname`: Same as `getuser`, but takes an username (without the @) as input. Note that if the database contains multiple users with the same username, due to old data for instance, only the first entry is returned +- `/userbyname`: Same as `getuser`, but takes an username (case-insentive, with or without the @) as input. Note that if the database contains multiple users with the same username, due to old data for instance, only the first entry is returned ### Plugins - Antiflood