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 import logging
from random import randint from typing import Any, Union
from typing import Union, Any
import discord import discord
import discord.member import discord.member
from modules.utils import config_get
from modules.database import col_users, col_warnings
try: from modules.database import col_users, col_warnings
from typing import Literal
except ImportError:
from typing_extensions import Literal
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -1,17 +1,13 @@
import logging 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 import utils as ds_utils
from discord.ext import commands from discord.ext import commands
from classes.holo_user import HoloUser
from enums.colors import Color from enums.colors import Color
from modules.scheduled import scheduler
from modules.utils import config_get from modules.utils import config_get
from modules.utils_sync import config_get_sync, guild_name from modules.utils_sync import config_get_sync, guild_name
from modules.scheduled import scheduler
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -1,14 +1,14 @@
from discord import ApplicationContext, Embed, option from discord import ApplicationContext, Embed, option
from discord.abc import GuildChannel
from discord import utils as ds_utils from discord import utils as ds_utils
from discord.abc import GuildChannel
from discord.commands import SlashCommandGroup from discord.commands import SlashCommandGroup
from discord.ext import commands from discord.ext import commands
from classes.holo_user import HoloUser from classes.holo_user import HoloUser
from enums.colors import Color from enums.colors import Color
from modules.database import col_users
from modules.utils import config_get from modules.utils import config_get
from modules.utils_sync import config_get_sync, guild_name from modules.utils_sync import config_get_sync, guild_name
from modules.database import col_users
class CustomChannels(commands.Cog): class CustomChannels(commands.Cog):
@ -17,8 +17,9 @@ class CustomChannels(commands.Cog):
@commands.Cog.listener() @commands.Cog.listener()
async def on_guild_channel_delete(self, channel: GuildChannel): 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", "Керування особистим каналом") customchannel = SlashCommandGroup("customchannel", "Керування особистим каналом")
@ -97,7 +98,9 @@ class CustomChannels(commands.Cog):
): ):
holo_user_ctx = HoloUser(ctx.user) 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: if custom_channel is None:
await ctx.respond( await ctx.respond(
embed=Embed( embed=Embed(
@ -129,7 +132,9 @@ class CustomChannels(commands.Cog):
guild_ids=[config_get_sync("guild")], guild_ids=[config_get_sync("guild")],
) )
@option("confirm", description="Підтвердження операції") @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) holo_user_ctx = HoloUser(ctx.user)
if holo_user_ctx.customchannel is not None: if holo_user_ctx.customchannel is not None:

View File

@ -7,19 +7,20 @@ from modules.utils import config_get
class Logger(commands.Cog): class Logger(commands.Cog):
def __init__(self, client): def __init__(self, client):
self.client = client self.client = client
@commands.Cog.listener() @commands.Cog.listener()
async def on_message(self, message: Message): async def on_message(self, message: Message):
if (
if (message.author != self.client.user) and (message.author.bot == False) and (message.author.system == False): (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: if col_users.find_one({"user": message.author.id}) is None:
user = {} user = {}
defaults = await config_get("user", "defaults") defaults = await config_get("user", "defaults")
user["user"] = message.author.id user["user"] = message.author.id
for key in defaults: for key in defaults:
@ -29,21 +30,33 @@ class Logger(commands.Cog):
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_join(self, member: Member): 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")) if (
rules_chan = ds_utils.get(self.client.get_guild(await config_get("guild")).channels, id=await config_get("rules", "channels", "text")) (member != self.client.user)
and (member.bot == False)
if (member != self.client.user) and (member.bot == False) and (member.system == False): and (member.system == False)
):
await welcome_chan.send(content=(await config_get("welcome", "messages")).format(mention=member.mention, rules=rules_chan.mention)) 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: if col_users.find_one({"user": member.id}) is None:
user = {} user = {}
defaults = await config_get("user", "defaults") defaults = await config_get("user", "defaults")
user["user"] = member.id user["user"] = member.id
for key in defaults: for key in defaults:
user[key] = defaults[key] user[key] = defaults[key]
col_users.insert_one(document=user) col_users.insert_one(document=user)

10
main.py
View File

@ -1,18 +1,16 @@
import asyncio
import logging import logging
from discord import Activity, ActivityType 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.admin import Admin
from cogs.analytics import Analytics from cogs.analytics import Analytics
from cogs.custom_channels import CustomChannels from cogs.custom_channels import CustomChannels
from cogs.data import Data from cogs.data import Data
from cogs.logger import Logger 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( logging.basicConfig(
level=logging.INFO, 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 def json_write(data: Any, path: str) -> None:
async with aiofiles.open(path, mode="w", encoding="utf-8") as f: 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: async def config_get(key: str, *path: str) -> Any: