from typing import List, Dict, Optional, Union, Callable, Tuple from inspect import signature from bson import ObjectId from django.utils.translation import gettext_lazy as _ from django.urls import reverse from flags import CommandScopeCollection, CommandScope, ChannelType, BotFeature from msghandle.models import TextMessageEventObject, HandledMessageEventText from mongodb.factory import BotFeatureUsageDataManager from JellyBot.systemconfig import HostUrl from extutils.checker import arg_type_ensure, NonSafeDataTypeConverter, TypeCastingFailed from extutils.logger import LoggerSkeleton from extutils.strtrans import type_translation logger = LoggerSkeleton("sys.botcmd", logger_name_env="BOT_CMD") @dataclass class CommandParameter: name: str annotation_name: str @dataclass class CommandFunction: arg_count: int arg_help: List[str] fn: callable cmd_node: 'CommandNode' cmd_feature: BotFeature
import os import time from datetime import datetime from threading import Thread import pymongo from pymongo import errors from extutils.logger import LoggerSkeleton __all__ = ["backup_collection"] logger = LoggerSkeleton("mongo.backup", logger_name_env="MONGO_BACKUP") target_mongo_url = os.environ.get("MONGO_BACKUP_URL") if not target_mongo_url: logger.logger.error("MongoDB Backup service not activated.") logger.logger.error( "Specify `MONGO_BACKUP_URL` in the environment variables " "with the connection string of the target instance.") target_client = None if target_mongo_url: target_client = pymongo.MongoClient(target_mongo_url) def backup_collection(org_client: pymongo.MongoClient, db_name: str, col_name: str, is_single_db: bool, backup_interval: int): if not target_client: logger.logger.warning( "Attempted to backup the data while the backup service is not activated."
import time import inspect from dataclasses import dataclass from typing import Any from extutils.logger import LoggerSkeleton __all__ = ["exec_timing", "exec_timing_ns", "exec_timing_result"] exec_logger = LoggerSkeleton("utils.exectimer", logger_name_env="TIME_EXEC") @dataclass class ExecutionResult: return_: Any execution_ns: int caller_stack: inspect.FrameInfo @property def execution_us(self) -> float: return self.execution_ns / 1000 @property def execution_ms(self) -> float: return self.execution_us / 1000 def __repr__(self): return f"{self.execution_us:.2f} us - " \ f"Line {self.caller_stack.lineno} {self.caller_stack.function} in {self.caller_stack.filename}"
import os import time from threading import Thread import requests from extutils.logger import LoggerSkeleton __all__ = ["activate_ddns_update"] logger = LoggerSkeleton("sys.ddnsupdate", logger_name_env="DDNS_UPDATE") enabled = True ddns_password = os.environ.get("DDNS_PASSWORD") if not ddns_password: logger.logger.error("DDNS_PASSWORD not found in environment variables.") enabled = False ddns_host = os.environ.get("DDNS_HOST") if not ddns_host: logger.logger.error("DDNS_HOST not found in environment variables.") enabled = False ddns_domain = os.environ.get("DDNS_DOMAIN") if not ddns_domain: logger.logger.error("DDNS_DOMAIN not found in environment variables.") enabled = False def ddns_update(interval_sec: int, retry_sec: int = 60): while True:
from extutils.logger import LoggerSkeleton logger = LoggerSkeleton("sys.handle", logger_name_env="EVT_HANDLER")
from extutils.logger import LoggerSkeleton __all__ = ["LINE", "ExtraKey", "event_dest_fmt"] LINE = LoggerSkeleton("sys.line", logger_name_env="LINE") LINE_INTERNAL = LoggerSkeleton("linebot", logger_name_env="LINE_INTERNAL") class ExtraKey: Event = "event" Destination = "dest" event_dest_fmt = "%(asctime)s %(name)s[%(levelname)s]: %(message)s\n\tEvent: %(event)s\n\tDestination: %(dest)s"
from extutils.logger import LoggerSkeleton logger = LoggerSkeleton("mongo.main", logger_name_env="MONGO_UTILS")
from extutils.logger import LoggerSkeleton __all__ = ["DISCORD", "DISCORD_INTERNAL"] DISCORD = LoggerSkeleton("sys.discord", logger_name_env="DISCORD") DISCORD_INTERNAL = LoggerSkeleton("discord", logger_name_env="DISCORD_INTERNAL")