mirror of https://github.com/nocturn9x/BotBase.git
Partially translated the config to italian and minor fixes
This commit is contained in:
parent
fc110099f8
commit
53cb245aca
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue