wip - still not working
This commit is contained in:
@ -10,6 +10,8 @@ from telegram.constants import ParseMode
|
||||
from config import TELEGRAM_BOT_TOKEN, DEVELOPER_CHAT_ID, BOT_NAME
|
||||
|
||||
|
||||
import asyncio
|
||||
from typing import Callable, Any
|
||||
import time
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
@ -67,7 +69,7 @@ class Log:
|
||||
# Set up success logger for accounting CSV
|
||||
|
||||
def __init__(self):
|
||||
logger = logging.getLogger(__name__)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
#logging.basicConfig(level=logging.INFO)
|
||||
|
||||
@ -109,11 +111,34 @@ def safe_get_property(info, property_name, default='Unknown'):
|
||||
value = info.get(property_name, default)
|
||||
return str(value) if value is not None else str(default)
|
||||
|
||||
async def async_safe_call(func: Callable, *args: Any, **kwargs: Any) -> Any:
|
||||
"""
|
||||
Safely call a function that might be synchronous, asynchronous, or a coroutine object.
|
||||
|
||||
:param func: The function to call, or a coroutine object
|
||||
:param args: Positional arguments to pass to the function
|
||||
:param kwargs: Keyword arguments to pass to the function
|
||||
:return: The result of the function call, or None if func is not callable or a coroutine
|
||||
"""
|
||||
if func is None:
|
||||
return None
|
||||
|
||||
if callable(func):
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
return await func(*args, **kwargs)
|
||||
else:
|
||||
return func(*args, **kwargs)
|
||||
elif asyncio.iscoroutine(func):
|
||||
# If func is already a coroutine object, just await it
|
||||
return await func
|
||||
else:
|
||||
logging.warning(f"Expected a callable or coroutine, but got {type(func)}: {func}")
|
||||
return None
|
||||
|
||||
|
||||
# Create a global instance of TelegramUtils
|
||||
telegram_utils = TelegramUtils()
|
||||
log = Log()
|
||||
log = Log().logger
|
||||
# You can add more Telegram-related methods to the TelegramUtils class if needed
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user