From c5ef1f687e7294bd277c919a10589359f1da9b86 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:34:31 +0530 Subject: [PATCH 1/5] Add some docstrings for framework modules --- framework/isobot/colors.py | 2 ++ framework/isobot/currency.py | 2 ++ framework/isobot/embedengine.py | 1 + 3 files changed, 5 insertions(+) diff --git a/framework/isobot/colors.py b/framework/isobot/colors.py index bb859784..3455ec47 100644 --- a/framework/isobot/colors.py +++ b/framework/isobot/colors.py @@ -1,6 +1,8 @@ """Library used for stdout colors.""" + class Colors: """Contains general stdout colors.""" + cyan = '\033[96m' red = '\033[91m' green = '\033[92m' diff --git a/framework/isobot/currency.py b/framework/isobot/currency.py index cbb6c228..2df06bb2 100644 --- a/framework/isobot/currency.py +++ b/framework/isobot/currency.py @@ -1,3 +1,5 @@ +"""The isobot module for managing the currency db""" + import json import discord import datetime diff --git a/framework/isobot/embedengine.py b/framework/isobot/embedengine.py index f4c358fa..d8eb2246 100644 --- a/framework/isobot/embedengine.py +++ b/framework/isobot/embedengine.py @@ -1,4 +1,5 @@ """The library used for designing and outputting Discord embeds.""" + import discord from discord import Color From 574d9e1827070e2c213432952c82319b8c97c62e Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:35:13 +0530 Subject: [PATCH 2/5] Simplify and shorten module import structures --- main.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 54cefd2b..68f30b30 100644 --- a/main.py +++ b/main.py @@ -9,14 +9,10 @@ import api.auth import utils.logger import utils.ping -from framework import * from math import floor from random import randint -import framework.isobot.currency -import framework.isobot.colors -import framework.isobank.authorize -import framework.isobank.manager -import framework.isobot.embedengine +from framework.isobot import currency, colors, embedengine +from framework.isobank import authorize, manager from discord import ApplicationContext, option from discord.ext import commands from discord.ext.commands import * @@ -61,8 +57,8 @@ def save(): except Exception as e: utils.logger.error(f"Failed to make log file: {e}", nolog=True) #Framework Module Loader -colors = framework.isobot.colors.Colors() -currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log") +colors = colors.Colors() +currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log") # Theme Loader themes = False # True: enables themes; False: disables themes; From 265a51027f430c0abb15b20df7a264e01d63ddf2 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 30 Jun 2023 21:10:27 +0530 Subject: [PATCH 3/5] Shorten some more imports --- main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 68f30b30..fb638dca 100644 --- a/main.py +++ b/main.py @@ -7,8 +7,7 @@ import discord import asyncio import api.auth -import utils.logger -import utils.ping +from utils import logger, ping from math import floor from random import randint from framework.isobot import currency, colors, embedengine @@ -47,14 +46,14 @@ def save(): os.mkdir('logs') try: open('logs/info-log.txt', 'x', encoding="utf-8") - utils.logger.info("Created info log", nolog=True) + logger.info("Created info log", nolog=True) time.sleep(0.5) open('logs/error-log.txt', 'x', encoding="utf-8") - utils.logger.info("Created error log", nolog=True) + logger.info("Created error log", nolog=True) time.sleep(0.5) open('logs/currency.log', 'x', encoding="utf-8") - utils.logger.info("Created currency log", nolog=True) - except Exception as e: utils.logger.error(f"Failed to make log file: {e}", nolog=True) + logger.info("Created currency log", nolog=True) + except Exception as e: logger.error(f"Failed to make log file: {e}", nolog=True) #Framework Module Loader colors = colors.Colors() @@ -88,7 +87,7 @@ async def on_ready(): await client.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name="GitHub"), status=discord.Status.idle) print(f'[main/Log] {colors.green}Status set to IDLE. Rich presence set.{colors.end}') print("[main/Flask] Starting pinger service...") - utils.ping.host() + ping.host() time.sleep(5) @client.event From 28ea7693e69d883bdf51dcf3d50e75338d069e47 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 30 Jun 2023 21:10:59 +0530 Subject: [PATCH 4/5] Shorten even more imports --- cogs/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cogs/utils.py b/cogs/utils.py index 5cfa9c87..bd1b7a0c 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -6,8 +6,7 @@ import psutil import math import openai -import framework.isobot.embedengine -import framework.isobot.currency +from framework.isobot import currency, embedengine from discord import option, ApplicationContext from discord.ext import commands from cogs.levelling import get_level, get_xp @@ -15,7 +14,7 @@ # Variables color = discord.Color.random() -currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log") +currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log") openai.api_key = os.getenv("chatgpt_API_KEY") chatgpt_conversation = dict() @@ -54,7 +53,7 @@ async def repo(self, ctx: ApplicationContext): @option(name="footer_icon_url", description="The icon you want to show in the embed's footer (URL ONLY)", type=str, default=None) async def embedbuilder(self, ctx: ApplicationContext, title: str, description: str, image_url: str = None, thumbnail_url: str = None, color: int = None, footer_text: str = None, footer_icon_url: str = None): await ctx.respond("Embed Built!", ephemeral=True) - await ctx.channel.send(embed=framework.isobot.embedengine.embed(title, description, image=image_url, thumbnail=thumbnail_url, color=color, footer_text=footer_text, footer_img=footer_icon_url)) + await ctx.channel.send(embed=embedengine.embed(title, description, image=image_url, thumbnail=thumbnail_url, color=color, footer_text=footer_text, footer_img=footer_icon_url)) @commands.slash_command( name='whoami', From b912d045433dc5673505f9d6fad1696cfc4ec0e7 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 30 Jun 2023 21:11:25 +0530 Subject: [PATCH 5/5] Remove redundant `discord.Color` import line --- framework/isobot/embedengine.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/framework/isobot/embedengine.py b/framework/isobot/embedengine.py index d8eb2246..9ddf9368 100644 --- a/framework/isobot/embedengine.py +++ b/framework/isobot/embedengine.py @@ -1,7 +1,6 @@ """The library used for designing and outputting Discord embeds.""" import discord -from discord import Color def embed(title: str, desc: str, *, image: str = None, thumbnail: str = None, color:int=None, footer_text: str = None, footer_img: str = None): """Designs a Discord embed. @@ -11,8 +10,8 @@ def embed(title: str, desc: str, *, image: str = None, thumbnail: str = None, co - If the color is set as "rand", then it will return the embed with a random color. - If a color is not set, it will appear as Discord's blurple embed color. """ - if color == -1: color = Color.random() - elif color == None: color = Color.blurple() + if color == -1: color = discord.Color.random() + elif color == None: color = discord.Color.blurple() local_embed = discord.Embed( title=title, description=desc,