[REPO REFACTOR]: changed to a better git repository structure with branches
This commit is contained in:
24
util/anime.py
Normal file
24
util/anime.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import requests
|
||||
|
||||
class Anime:
|
||||
def __init__(self):
|
||||
self.base_url = f"https://api.waifu.pics/"
|
||||
|
||||
def get(self, type: str, category: str) -> None:
|
||||
if type != "nsfw" and type != "sfw":
|
||||
raise Exception("Type not supported!")
|
||||
|
||||
if not isinstance(category, str):
|
||||
raise Exception("Category must be a string!")
|
||||
|
||||
response = requests.get(f"{self.base_url}/{type}/{category}")
|
||||
if response.status_code != 200:
|
||||
raise Exception("Failed to retrieve data from API!")
|
||||
|
||||
return response.json()["url"]
|
||||
|
||||
def sfw(self, category: str) -> str:
|
||||
return self.get("sfw", category)
|
||||
|
||||
def nsfw(self, category: str) -> str:
|
||||
return self.get("nsfw", category)
|
||||
17
util/files.py
Normal file
17
util/files.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import json
|
||||
|
||||
def read(file: str) -> str:
|
||||
with open(file, "r") as f:
|
||||
return f.read()
|
||||
|
||||
def read_json(file: str) -> dict:
|
||||
with open(file, "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
def write(file: str, content: str) -> None:
|
||||
with open(file, "w") as f:
|
||||
f.write(content)
|
||||
|
||||
def write_json(file: str, content: dict) -> None:
|
||||
with open(file, "w") as f:
|
||||
json.dump(content, f, indent=4, sort_keys=True, separators=(',', ': '), ensure_ascii=False)
|
||||
13
util/logger/colors.py
Normal file
13
util/logger/colors.py
Normal file
@@ -0,0 +1,13 @@
|
||||
class Colors:
|
||||
RED = "\033[91m"
|
||||
GREEN = "\033[92m"
|
||||
YELLOW = "\033[93m"
|
||||
BLUE = "\033[94m"
|
||||
MAGENTA = "\033[95m"
|
||||
CYAN = "\033[96m"
|
||||
WHITE = "\033[97m"
|
||||
RESET = "\033[0m"
|
||||
BOLD = "\033[1m"
|
||||
UNDERLINE = "\033[4m"
|
||||
LIME = "\033[32m"
|
||||
GRAY = "\033[90m"
|
||||
43
util/logger/logger.py
Normal file
43
util/logger/logger.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from .colors import Colors
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
import traceback
|
||||
|
||||
class PypeLogger:
|
||||
@staticmethod
|
||||
def info(message):
|
||||
now = datetime.now(tz=pytz.timezone("Europe/Madrid")).strftime("%H:%M:%S")
|
||||
print(f"{Colors.GRAY}[{now}] {Colors.GREEN}[INFO] {message}{Colors.RESET}")
|
||||
|
||||
@staticmethod
|
||||
def error(message, exception=None):
|
||||
now = datetime.now(tz=pytz.timezone("Europe/Madrid")).strftime("%H:%M:%S")
|
||||
main_error = f"{Colors.GRAY}[{now}] {Colors.RED}[ERROR] {message}{Colors.RESET}"
|
||||
error_messages = [main_error]
|
||||
if exception:
|
||||
exception_message = f"\n{Colors.GRAY}[{now}] {Colors.RED}[ERROR] - Exception: {exception}"
|
||||
traceback_message = f"\n{Colors.GRAY}[{now}] {Colors.RED}[ERROR] - Traceback: {traceback.format_exc()}"
|
||||
error_messages.append(exception_message)
|
||||
error_messages.append(traceback_message)
|
||||
for error_message in error_messages:
|
||||
print(error_message)
|
||||
|
||||
@staticmethod
|
||||
def debug(message):
|
||||
now = datetime.now(tz=pytz.timezone("Europe/Madrid")).strftime("%H:%M:%S")
|
||||
print(f"{Colors.GRAY}[{now}] {Colors.BLUE}[DEBUG] {message}{Colors.RESET}")
|
||||
|
||||
@staticmethod
|
||||
def warning(message):
|
||||
now = datetime.now(tz=pytz.timezone("Europe/Madrid")).strftime("%H:%M:%S")
|
||||
print(f"{Colors.GRAY}[{now}] {Colors.YELLOW}[WARNING] {message}{Colors.RESET}")
|
||||
|
||||
@staticmethod
|
||||
def success(message):
|
||||
now = datetime.now(tz=pytz.timezone("Europe/Madrid")).strftime("%H:%M:%S")
|
||||
print(f"{Colors.GRAY}[{now}] {Colors.LIME}[SUCCESS] {message}{Colors.RESET}")
|
||||
|
||||
@staticmethod
|
||||
def command(message):
|
||||
now = datetime.now(tz=pytz.timezone("Europe/Madrid")).strftime("%H:%M:%S")
|
||||
print(f"{Colors.GRAY}[{now}] {Colors.MAGENTA}[COMMAND] {message}{Colors.RESET}")
|
||||
18
util/messages.py
Normal file
18
util/messages.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
async def respond(context: ContextTypes.DEFAULT_TYPE, chat_id: int, message: str):
|
||||
await context.bot.send_message(
|
||||
chat_id=chat_id,
|
||||
text="✅ Mensaje recibido",
|
||||
disable_notification=True
|
||||
)
|
||||
|
||||
def delete_user_message(func):
|
||||
async def wrapper(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await func(self, update, context)
|
||||
try:
|
||||
await context.bot.delete_message(update.effective_chat.id, update.message.message_id)
|
||||
except:
|
||||
pass
|
||||
return wrapper
|
||||
10
util/numbers.py
Normal file
10
util/numbers.py
Normal file
@@ -0,0 +1,10 @@
|
||||
def is_even(n: int) -> bool:
|
||||
return n % 2 == 0
|
||||
|
||||
def is_prime(n: int) -> bool:
|
||||
if n <= 1:
|
||||
return False
|
||||
for i in range(2, int(n**0.5) + 1):
|
||||
if n % i == 0:
|
||||
return False
|
||||
return True
|
||||
Reference in New Issue
Block a user