From 5ff49ed0523d4b7fd1c8c337a889fa92d8e7307c Mon Sep 17 00:00:00 2001 From: profitroll Date: Sat, 6 May 2023 18:56:01 +0200 Subject: [PATCH] Sorted, formatted, removed unused imports --- classes/holo_user.py | 12 +++--------- cogs/admin.py | 8 ++------ cogs/custom_channels.py | 17 +++++++++++------ cogs/logger.py | 39 ++++++++++++++++++++++++++------------- main.py | 10 ++++------ modules/utils.py | 4 +++- 6 files changed, 49 insertions(+), 41 deletions(-) diff --git a/classes/holo_user.py b/classes/holo_user.py index 20e472b..0696301 100644 --- a/classes/holo_user.py +++ b/classes/holo_user.py @@ -1,16 +1,10 @@ -from datetime import datetime, timezone import logging -from random import randint -from typing import Union, Any +from typing import Any, Union + import discord import discord.member -from modules.utils import config_get -from modules.database import col_users, col_warnings -try: - from typing import Literal -except ImportError: - from typing_extensions import Literal +from modules.database import col_users, col_warnings logger = logging.getLogger(__name__) diff --git a/cogs/admin.py b/cogs/admin.py index f91d3a5..7aa11ed 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -1,17 +1,13 @@ import logging -from datetime import timedelta -from os import getpid, system -from typing import Union -from discord import ApplicationContext, Embed, User, slash_command, option +from discord import ApplicationContext, Embed, User, option, slash_command from discord import utils as ds_utils from discord.ext import commands -from classes.holo_user import HoloUser from enums.colors import Color +from modules.scheduled import scheduler from modules.utils import config_get from modules.utils_sync import config_get_sync, guild_name -from modules.scheduled import scheduler logger = logging.getLogger(__name__) diff --git a/cogs/custom_channels.py b/cogs/custom_channels.py index e1dca7d..30257ae 100644 --- a/cogs/custom_channels.py +++ b/cogs/custom_channels.py @@ -1,14 +1,14 @@ from discord import ApplicationContext, Embed, option -from discord.abc import GuildChannel from discord import utils as ds_utils +from discord.abc import GuildChannel from discord.commands import SlashCommandGroup from discord.ext import commands from classes.holo_user import HoloUser from enums.colors import Color +from modules.database import col_users from modules.utils import config_get from modules.utils_sync import config_get_sync, guild_name -from modules.database import col_users class CustomChannels(commands.Cog): @@ -17,8 +17,9 @@ class CustomChannels(commands.Cog): @commands.Cog.listener() async def on_guild_channel_delete(self, channel: GuildChannel): - col_users.find_one_and_update({"customchannel": channel.id}, {"$set": {"customchannel": None}}) - + col_users.find_one_and_update( + {"customchannel": channel.id}, {"$set": {"customchannel": None}} + ) customchannel = SlashCommandGroup("customchannel", "Керування особистим каналом") @@ -97,7 +98,9 @@ class CustomChannels(commands.Cog): ): holo_user_ctx = HoloUser(ctx.user) - custom_channel = ds_utils.get(ctx.guild.channels, id=holo_user_ctx.customchannel) + custom_channel = ds_utils.get( + ctx.guild.channels, id=holo_user_ctx.customchannel + ) if custom_channel is None: await ctx.respond( embed=Embed( @@ -129,7 +132,9 @@ class CustomChannels(commands.Cog): guild_ids=[config_get_sync("guild")], ) @option("confirm", description="Підтвердження операції") - async def customchannel_remove_cmd(self, ctx: ApplicationContext, confirm: bool = False): + async def customchannel_remove_cmd( + self, ctx: ApplicationContext, confirm: bool = False + ): holo_user_ctx = HoloUser(ctx.user) if holo_user_ctx.customchannel is not None: diff --git a/cogs/logger.py b/cogs/logger.py index 6c36bb7..b949926 100644 --- a/cogs/logger.py +++ b/cogs/logger.py @@ -7,19 +7,20 @@ from modules.utils import config_get class Logger(commands.Cog): - def __init__(self, client): self.client = client @commands.Cog.listener() async def on_message(self, message: Message): - - if (message.author != self.client.user) and (message.author.bot == False) and (message.author.system == False): - + if ( + (message.author != self.client.user) + and (message.author.bot == False) + and (message.author.system == False) + ): if col_users.find_one({"user": message.author.id}) is None: user = {} defaults = await config_get("user", "defaults") - + user["user"] = message.author.id for key in defaults: @@ -29,21 +30,33 @@ class Logger(commands.Cog): @commands.Cog.listener() async def on_member_join(self, member: Member): + welcome_chan = ds_utils.get( + self.client.get_guild(await config_get("guild")).channels, + id=await config_get("welcome", "channels", "text"), + ) + rules_chan = ds_utils.get( + self.client.get_guild(await config_get("guild")).channels, + id=await config_get("rules", "channels", "text"), + ) - welcome_chan = ds_utils.get(self.client.get_guild(await config_get("guild")).channels, id=await config_get("welcome", "channels", "text")) - rules_chan = ds_utils.get(self.client.get_guild(await config_get("guild")).channels, id=await config_get("rules", "channels", "text")) - - if (member != self.client.user) and (member.bot == False) and (member.system == False): - - await welcome_chan.send(content=(await config_get("welcome", "messages")).format(mention=member.mention, rules=rules_chan.mention)) + if ( + (member != self.client.user) + and (member.bot == False) + and (member.system == False) + ): + await welcome_chan.send( + content=(await config_get("welcome", "messages")).format( + mention=member.mention, rules=rules_chan.mention + ) + ) if col_users.find_one({"user": member.id}) is None: user = {} defaults = await config_get("user", "defaults") - + user["user"] = member.id for key in defaults: user[key] = defaults[key] - col_users.insert_one(document=user) \ No newline at end of file + col_users.insert_one(document=user) diff --git a/main.py b/main.py index e58a2b1..6267f49 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,16 @@ -import asyncio import logging from discord import Activity, ActivityType -from modules.scheduled import scheduler -from modules.client import client -from modules.utils import config_get -from modules.utils_sync import config_get_sync - from cogs.admin import Admin from cogs.analytics import Analytics from cogs.custom_channels import CustomChannels from cogs.data import Data from cogs.logger import Logger +from modules.client import client +from modules.scheduled import scheduler +from modules.utils import config_get +from modules.utils_sync import config_get_sync logging.basicConfig( level=logging.INFO, diff --git a/modules/utils.py b/modules/utils.py index a7d005e..8a4f34a 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -12,7 +12,9 @@ async def json_read(path: str) -> Any: async def json_write(data: Any, path: str) -> None: async with aiofiles.open(path, mode="w", encoding="utf-8") as f: - await f.write(dumps(data, ensure_ascii=False, escape_forward_slashes=False, indent=4)) + await f.write( + dumps(data, ensure_ascii=False, escape_forward_slashes=False, indent=4) + ) async def config_get(key: str, *path: str) -> Any: