Skip to content

Commit

Permalink
[Fix] Linting and formatting via Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
FluxC0 authored and github-actions[bot] committed Apr 5, 2024
1 parent 5fc8cbf commit da7e7d0
Showing 1 changed file with 56 additions and 64 deletions.
120 changes: 56 additions & 64 deletions tux/cogs/utility/note.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json
import pathlib as path

import discord
from discord import app_commands
from discord.ext import commands
from loguru import logger
import json
import pathlib as path

from tux.utils.constants import Constants as CONST

Path = path.Path
storage_file = Path("config/settings.json")
storage = json.loads(storage_file.read_text())
Expand All @@ -13,7 +16,9 @@
class Note(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot

group = app_commands.Group(name="note", description="Note Commands")

@staticmethod
def create_embed(
title: str = "", description: str = "", color: int = CONST.COLORS["SUCCESS"]
Expand All @@ -22,80 +27,67 @@ def create_embed(
embed = discord.Embed(title=title, description=description, color=color)
embed.set_author(name="Info", icon_url="https://cdn3.emoji.gg/emojis/3228-info.png")
return embed

@group.command(name="write", description="")

async def write(self, interaction: discord.Interaction, user: discord.Member, note: str):
user_id = user.id
data = {
"user": user_id,
"note": note


}

embed = self.create_embed("Note Added", f"Note added for {user.display_name}")


with Path.open(storage_file, "w") as file:
json.dump(data,file, indent=4)
logger.info("Note added")
await interaction.response.send_message(embed=embed)

user_id = user.id
data = {"user": user_id, "note": note}

embed = self.create_embed("Note Added", f"Note added for {user.display_name}")

with Path.open(storage_file, "w") as file:
json.dump(data, file, indent=4)
logger.info("Note added")
await interaction.response.send_message(embed=embed)

@group.command(name="read", description="")
async def read(self, interaction: discord.Interaction, user: discord.Member):
user_id = user.id
with Path.open(storage_file, "r") as file:
data = json.load(file)
user_note = next((entry["note"] for entry in data if entry["user"] == user_id), None)
user_id = user.id
with Path.open(storage_file, "r") as file:
data = json.load(file)
user_note = next((entry["note"] for entry in data if entry["user"] == user_id), None)

if user_note:
if user_note:
embed = self.create_embed(
title="Note Found",
description=f"Note for {user.display_name}: {user_note}",
color=CONST.COLORS["INFO"],
)
await interaction.response.send_message(embed=embed)
else:
embed = self.create_embed(
title="Note Not Found",
description=f"No note found for {user.display_name}",
color=CONST.COLORS["ERROR"],
)
await interaction.response.send_message(embed=embed)

@group.command(name="delete", description="Delete a note.")
async def delete(self, interaction: discord.Interaction, user: discord.Member):
user_id = user.id
with Path.open(storage_file, "r") as file:
data = json.load(file)
updated_data = [entry for entry in data if entry["user"] != user_id]
if len(data) == len(updated_data):
embed = self.create_embed(
title="Note Found",
description=f"Note for {user.display_name}: {user_note}",
color=CONST.COLORS["INFO"]
title="Note Delete Error",
description=f"No note found for {user.display_name}!",
color=CONST.COLORS["ERROR"],
)
logger.error("Note delete error - Note not found")
await interaction.response.send_message(embed=embed)
else:
with Path.open(storage_file, "w") as file:
json.dump(updated_data, file, indent=4)

embed = self.create_embed(
title="Note Not Found",
description=f"No note found for {user.display_name}",
color=CONST.COLORS["ERROR"],

title="Note Deleted",
description=f"Note deleted for {user.display_name}.",
color=CONST.COLORS["SUCCESS"],
)
logger.info("Note deleted")
await interaction.response.send_message(embed=embed)
@group.command(name="delete", description="Delete a note.")
async def delete(self, interaction: discord.Interaction, user: discord.Member):
user_id = user.id
with Path.open(storage_file, "r") as file:
data = json.load(file)
updated_data = [entry for entry in data if entry["user"] != user_id]
if len(data) == len(updated_data):
embed = self.create_embed(
title="Note Delete Error",
description=f"No note found for {user.display_name}!",
color=CONST.COLORS["ERROR"]
)
logger.error("Note delete error - Note not found")
await interaction.response.send_message(embed=embed)
else:
with Path.open(storage_file, "w") as file:
json.dump(updated_data, file, indent=4)

embed = self.create_embed(
title="Note Deleted",
description=f"Note deleted for {user.display_name}.",
color=CONST.COLORS["SUCCESS"]
)
logger.info("Note deleted")
await interaction.response.send_message(embed=embed)








async def setup(bot: commands.Bot) -> None:
await bot.add_cog(Note(bot))
await bot.add_cog(Note(bot))

0 comments on commit da7e7d0

Please sign in to comment.