Sorted, formatted, removed unused imports

This commit is contained in:
Profitroll 2023-05-06 18:56:01 +02:00
parent 640ab65e7a
commit 5ff49ed052
6 changed files with 49 additions and 41 deletions

View File

@ -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__)

View File

@ -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__)

View File

@ -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:

View File

@ -7,15 +7,16 @@ 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")
@ -29,13 +30,25 @@ 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 = {}

10
main.py
View File

@ -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,

View File

@ -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: