Skip to content

Commit

Permalink
style: format code with Autopep8, Black and Ruff Formatter
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in b5eceb1 according to the output
from Autopep8, Black and Ruff Formatter.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Jan 11, 2025
1 parent b5eceb1 commit 1613307
Show file tree
Hide file tree
Showing 16 changed files with 9,111 additions and 6,309 deletions.
334 changes: 209 additions & 125 deletions Cogs/ai.py

Large diffs are not rendered by default.

371 changes: 241 additions & 130 deletions Cogs/anime.py

Large diffs are not rendered by default.

413 changes: 263 additions & 150 deletions Cogs/help.py

Large diffs are not rendered by default.

351 changes: 202 additions & 149 deletions Cogs/information.py

Large diffs are not rendered by default.

251 changes: 168 additions & 83 deletions Cogs/memo.py

Large diffs are not rendered by default.

2,905 changes: 1,577 additions & 1,328 deletions Cogs/pokemon.py

Large diffs are not rendered by default.

3,021 changes: 1,818 additions & 1,203 deletions Cogs/quest.py

Large diffs are not rendered by default.

163 changes: 84 additions & 79 deletions Cogs/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from Imports.discord_imports import *
from Imports.log_imports import *
import Data.const as const
import Data.const as const
from Data.const import primary_color, timestamp_gen


Expand All @@ -20,74 +20,84 @@ def __init__(self, bot):
self.bot = bot
self.start_time = time.time()
self.memory_check.start()
self.image_file = 'Data/commands/help/help_embed_images.json'



self.image_file = "Data/commands/help/help_embed_images.json"

async def get_latest_python_version(self):
latest_version = subprocess.check_output(['python', '-c', 'import sys; print("{}.{}.{}".format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro))']).decode().strip()
latest_version = (
subprocess.check_output(
[
"python",
"-c",
'import sys; print("{}.{}.{}".format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro))',
]
)
.decode()
.strip()
)
return latest_version

@commands.Cog.listener()
async def on_ready(self):
logger.info(f"{Fore.YELLOW}[System cog] Bot is ready.{Style.RESET_ALL}")
logger.info(
f"{Fore.YELLOW}[System cog] Bot is ready.{Style.RESET_ALL}")

@commands.command(name='ping')
@commands.command(name="ping")
async def ping(self, ctx):
try:
python_version = platform.python_version()
python_version_info = f"{python_version} {'Up to Date' if python_version >= await self.get_latest_python_version() else 'Outdated'}"

system_info = f"{platform.system()} {platform.processor()}"

threshold = 200
lag = self.bot.latency * 1000
pos_neg = f"{'+' if lag < threshold else '-'}"
gateway_latency = f"{round(lag)}ms"

cpu_usage_value = psutil.cpu_percent()
mem_usage_value = psutil.virtual_memory().percent

cpu_status = "Good" if cpu_usage_value < 80 else "Bad"
mem_status = "Good" if mem_usage_value < 80 else "Bad"

color = discord.Color.green() if lag < threshold else discord.Color.red()

embed = discord.Embed(title='', description=f"```diff\n{pos_neg} Pong: {gateway_latency}```", color=color, timestamp=datetime.now())
embed.set_footer(text=f'Requested by {ctx.author}', icon_url=ctx.author.avatar)
color = discord.Color.green() if lag < threshold else discord.Color.red()






embed = discord.Embed(
title="",
description=f"```diff\n{pos_neg} Pong: {gateway_latency}```",
color=color,
timestamp=datetime.now(),
)
embed.set_footer(
text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar
)


await ctx.reply(f"{ctx.message.author.mention}",embed=embed, mention_author=False)
await ctx.reply(
f"{ctx.message.author.mention}", embed=embed, mention_author=False
)

except Exception as e:
await const.error_custom_embed(self.bot, ctx, e, title="Ping")
logger.error(f"[System cog] Error occurred while sending ping embed: {e}")

logger.error(
f"[System cog] Error occurred while sending ping embed: {e}")

def cog_unload(self):
logger.info(f"{Fore.RED}[System cog] Unloaded{Style.RESET_ALL}")
@commands.command(name='uptime')

@commands.command(name="uptime")
async def uptime(self, ctx):
"""Shows how long the bot has been running."""
bot_uptime = timestamp_gen(self.start_time)

bot_uptime = timestamp_gen(self.start_time)

embed = discord.Embed(
title="How Long Has Bot Been Awake?",
description=f"The bot was been running {bot_uptime}",
color=primary_color(),
timestamp=datetime.now()
timestamp=datetime.now(),
)
embed.set_footer(text="Uptime", icon_url=self.bot.user.avatar)
await ctx.reply(embed=embed, mention_author=False)
await ctx.reply(embed=embed, mention_author=False)

@tasks.loop(minutes=10)
async def memory_check(self):
"""Periodically checks and optimizes memory usage."""
Expand All @@ -111,7 +121,7 @@ def log_memory_usage(self):
"""Logs the bot's current memory usage."""
process = psutil.Process(os.getpid())
memory_info = process.memory_info()
memory_usage = memory_info.rss / (1024 ** 2) # Convert bytes to MB
memory_usage = memory_info.rss / (1024**2) # Convert bytes to MB
print(f"Current memory usage: {memory_usage:.2f} MB")

@commands.command()
Expand All @@ -120,7 +130,9 @@ async def optimize(self, ctx):
"""Manually triggers memory optimization."""
self.optimize_memory()
memory_usage = self.get_memory_usage()
await ctx.send(f"Memory optimization completed. Current usage: {memory_usage:.2f} MB")
await ctx.send(
f"Memory optimization completed. Current usage: {memory_usage:.2f} MB"
)

@commands.command()
@commands.is_owner()
Expand All @@ -133,86 +145,80 @@ def get_memory_usage(self):
"""Returns the current memory usage of the bot."""
process = psutil.Process(os.getpid())
memory_info = process.memory_info()
return memory_info.rss / (1024 ** 2) # Convert bytes to MB
@commands.command(name='credit')
return memory_info.rss / (1024**2) # Convert bytes to MB

@commands.command(name="credit")
async def credit(self, ctx):
try:

with open('Data/commands/system/credits.json', 'r') as f:
with open("Data/commands/system/credits.json", "r") as f:
credit_data = json.load(f)


embed = discord.Embed(
title=f'{credit_data["title"]}',
timestamp=datetime.now(),
color=primary_color()
color=primary_color(),
)


emoji = '<:ty:1285850367065587762>'
reply = '<:reply:1285852466704809984>'
image_url = 'https://static1.cbrimages.com/wordpress/wp-content/uploads/2022/11/Spy-x-family-ep-18-Loid-and-Anya-studying.jpg?q=50&fit=crop&w=1100&h=618&dpr=1.5'
emoji = "<:ty:1285850367065587762>"
reply = "<:reply:1285852466704809984>"
image_url = "https://static1.cbrimages.com/wordpress/wp-content/uploads/2022/11/Spy-x-family-ep-18-Loid-and-Anya-studying.jpg?q=50&fit=crop&w=1100&h=618&dpr=1.5"
for developer in credit_data["developers"]:
embed.add_field(name='', value=f'**{emoji} | {developer["name"]}**\n{reply} {developer["role"]}', inline=False)

embed.add_field(
name="",
value=f'**{emoji} | {developer["name"]}**\n{reply} {developer["role"]}',
inline=False,
)

embed.set_image(url=image_url)


embed.set_footer(text='- w - thanks for using our bot')


embed.set_footer(text="- w - thanks for using our bot")

await ctx.reply(embed=embed, mention_author=False)

except Exception as e:

await ctx.send(f"An error occurred while trying to load the credits: {e}")


@commands.command(name="set_image")
async def set_image(self, ctx, cog_name: str):
"""Command to change the image URL of a specific cog. Accepts attachments or image URLs."""
cog_name = cog_name.lower()

valid_cogs = ['anime', 'information', 'system', 'quest', 'ai', 'pokemon']
valid_cogs = ["anime", "information",
"system", "quest", "ai", "pokemon"]
if cog_name not in valid_cogs:
await ctx.send(f"Invalid cog name. Valid cogs are: {', '.join(valid_cogs)}.")
await ctx.send(
f"Invalid cog name. Valid cogs are: {', '.join(valid_cogs)}."
)
return


if len(ctx.message.attachments) > 0:

image_url = ctx.message.attachments[0].url
elif len(ctx.message.content.split()) > 1:

image_url = ctx.message.content.split()[1]
else:
await ctx.send("No image URL or attachment found. Please attach an image or provide an image URL.")
await ctx.send(
"No image URL or attachment found. Please attach an image or provide an image URL."
)
return



if os.path.exists(self.image_file):
with open(self.image_file, 'r') as f:
with open(self.image_file, "r") as f:
help_embed = json.load(f)
else:
help_embed = {}


if cog_name not in help_embed:
help_embed[cog_name] = {}

help_embed[cog_name]['thumbnail_url'] = image_url
help_embed[cog_name]["thumbnail_url"] = image_url


with open(self.image_file, 'w') as f:
with open(self.image_file, "w") as f:
json.dump(help_embed, f, indent=4)


embed = discord.Embed(
title=f"Thumbnail for `{cog_name}` Updated",
description=f"The thumbnail for `{cog_name}` has been successfully updated!",
color=discord.Color.green()
color=discord.Color.green(),
)
embed.set_thumbnail(url=image_url)
await ctx.reply(embed=embed, mention_author=False)
Expand All @@ -222,35 +228,34 @@ async def get_image(self, ctx, cog_name: str):
"""Command to retrieve the image URL of a specific cog."""
cog_name = cog_name.lower()

valid_cogs = ['anime', 'information', 'system', 'quest', 'ai', 'pokemon']
valid_cogs = ["anime", "information",
"system", "quest", "ai", "pokemon"]
if cog_name not in valid_cogs:
await ctx.send(f"Invalid cog name. Valid cogs are: {', '.join(valid_cogs)}.")
await ctx.send(
f"Invalid cog name. Valid cogs are: {', '.join(valid_cogs)}."
)
return


if os.path.exists(self.image_file):
with open(self.image_file, 'r') as f:
with open(self.image_file, "r") as f:
help_embed = json.load(f)
else:
await ctx.send("No images have been set yet.")
return


if cog_name in help_embed and 'thumbnail_url' in help_embed[cog_name]:
image_url = help_embed[cog_name]['thumbnail_url']


if cog_name in help_embed and "thumbnail_url" in help_embed[cog_name]:
image_url = help_embed[cog_name]["thumbnail_url"]

embed = discord.Embed(
title=f"Thumbnail for `{cog_name}`",
description=f"The current thumbnail for `{cog_name}` is:",
color=discord.Color.blue()
color=discord.Color.blue(),
)
embed.set_thumbnail(url=image_url)
await ctx.reply(embed=embed, mention_author=False)
else:
await ctx.reply(embed=embed, mention_author=False)



def setup(bot):
bot.add_cog(System(bot))
Loading

0 comments on commit 1613307

Please sign in to comment.