Closes #2
This commit is contained in:
26
cogs/data.py
26
cogs/data.py
@@ -7,8 +7,9 @@ from discord import ApplicationContext, Embed, File, option
|
||||
from discord import utils as ds_utils
|
||||
from discord.commands import SlashCommandGroup
|
||||
from discord.ext import commands
|
||||
from classes.holo_user import HoloUser
|
||||
from libbot.pycord.classes import PycordBot
|
||||
|
||||
from classes.holo_user import HoloUser
|
||||
from enums.colors import Color
|
||||
from modules.database import col_users
|
||||
from modules.utils import config_get
|
||||
@@ -18,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Data(commands.Cog):
|
||||
def __init__(self, client):
|
||||
def __init__(self, client: PycordBot):
|
||||
self.client = client
|
||||
|
||||
data = SlashCommandGroup("data", "Керування даними користувачів")
|
||||
@@ -34,11 +35,11 @@ class Data(commands.Cog):
|
||||
async def data_export_cmd(self, ctx: ApplicationContext, kind: str):
|
||||
await ctx.defer()
|
||||
holo_user = HoloUser(ctx.author)
|
||||
if (ctx.user.id in await config_get("admins")) or (
|
||||
if (ctx.user.id in self.client.config["bot"]["owners"]) or (
|
||||
await holo_user.is_council(ctx.author)
|
||||
):
|
||||
logging.info(
|
||||
f"Moderator {guild_name(ctx.user)} exported current users list"
|
||||
"Moderator %s exported current users list", guild_name(ctx.user)
|
||||
)
|
||||
makedirs("tmp", exist_ok=True)
|
||||
uuid = str(uuid4())
|
||||
@@ -63,7 +64,8 @@ class Data(commands.Cog):
|
||||
)
|
||||
else:
|
||||
logging.info(
|
||||
f"User {guild_name(ctx.user)} tried to use /export but permission denied"
|
||||
"User %s tried to use /export but permission denied",
|
||||
guild_name(ctx.user),
|
||||
)
|
||||
await ctx.respond(
|
||||
embed=Embed(
|
||||
@@ -99,11 +101,12 @@ class Data(commands.Cog):
|
||||
async def data_migrate_cmd(self, ctx: ApplicationContext, kind: str):
|
||||
await ctx.defer()
|
||||
holo_user = HoloUser(ctx.author)
|
||||
if (ctx.user.id in await config_get("admins")) or (
|
||||
if (ctx.user.id in self.client.config["bot"]["owners"]) or (
|
||||
await holo_user.is_council(ctx.author)
|
||||
):
|
||||
logging.info(
|
||||
f"Moderator {guild_name(ctx.user)} started migration of all members to the database"
|
||||
"Moderator %s started migration of all members to the database",
|
||||
guild_name(ctx.user),
|
||||
)
|
||||
|
||||
if kind == "Користувачі":
|
||||
@@ -121,7 +124,7 @@ class Data(commands.Cog):
|
||||
|
||||
col_users.insert_one(document=user)
|
||||
logging.info(
|
||||
f"Added DB record for user {member.id} during migration"
|
||||
"Added DB record for user %s during migration", member.id
|
||||
)
|
||||
|
||||
await ctx.respond(
|
||||
@@ -133,7 +136,8 @@ class Data(commands.Cog):
|
||||
)
|
||||
else:
|
||||
logging.info(
|
||||
f"User {guild_name(ctx.user)} tried to use /migrate but permission denied"
|
||||
"User %s tried to use /migrate but permission denied",
|
||||
guild_name(ctx.user),
|
||||
)
|
||||
await ctx.respond(
|
||||
embed=Embed(
|
||||
@@ -157,3 +161,7 @@ class Data(commands.Cog):
|
||||
color=Color.fail,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def setup(client: PycordBot):
|
||||
client.add_cog(Data(client))
|
||||
|
Reference in New Issue
Block a user