From e14c93f07f6913889dfffa7b67ff874d479868e5 Mon Sep 17 00:00:00 2001 From: Renovate Date: Sun, 23 Jun 2024 12:17:10 +0300 Subject: [PATCH 1/3] Update dependency apscheduler to v3.10.4 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fbb1aa1..144f375 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiofiles==23.1.0 -apscheduler==3.10.1 +apscheduler==3.10.4 py-cord[speed]==2.4.1 pymongo==4.3.3 requests==2.30.0 From ed190bc07e6ad68133f022c2643f1ca285e29e90 Mon Sep 17 00:00:00 2001 From: Renovate Date: Sun, 23 Jun 2024 12:17:14 +0300 Subject: [PATCH 2/3] Update dependency aiofiles to v23.2.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fbb1aa1..40c45f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiofiles==23.1.0 +aiofiles==23.2.1 apscheduler==3.10.1 py-cord[speed]==2.4.1 pymongo==4.3.3 From f67375ff4f238c55ba8fbb3e7470cfb2ed38c5f5 Mon Sep 17 00:00:00 2001 From: profitroll Date: Sun, 23 Jun 2024 12:05:03 +0200 Subject: [PATCH 3/3] Closes #2 --- cogs/admin.py | 24 +++++++++++++++++------- cogs/analytics.py | 7 ++++++- cogs/custom_channels.py | 19 ++++++++++++------- cogs/data.py | 26 +++++++++++++++++--------- cogs/fun.py | 15 +++++++++++++-- cogs/logger.py | 7 ++++++- config_example.json | 14 +++++++++++--- locale/en.json | 9 +++++++++ locale/uk.json | 9 +++++++++ main.py | 19 +++++-------------- modules/client.py | 5 +++-- requirements.txt | 11 ++++++----- 12 files changed, 114 insertions(+), 51 deletions(-) create mode 100644 locale/en.json create mode 100644 locale/uk.json diff --git a/cogs/admin.py b/cogs/admin.py index 89f365f..067dab7 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -3,6 +3,7 @@ import logging from discord import ApplicationContext, Embed, User, option, slash_command from discord import utils as ds_utils from discord.ext import commands +from libbot.pycord.classes import PycordBot from enums.colors import Color from modules.scheduled import scheduler @@ -13,7 +14,7 @@ logger = logging.getLogger(__name__) class Admin(commands.Cog): - def __init__(self, client): + def __init__(self, client: PycordBot): self.client = client # @slash_command( @@ -111,9 +112,12 @@ class Admin(commands.Cog): amount: int, user: User, ): - if ctx.user.id in await config_get("admins"): + if ctx.user.id in self.client.config["bot"]["owners"]: logging.info( - f"User {ctx.user.id} removed {amount} message(s) in {ctx.channel.id}" + "User %s removed %s message(s) in %s", + ctx.user.id, + amount, + ctx.channel.id, ) await ctx.respond( embed=Embed(description="Видаляю..."), ephemeral=True, delete_after=2.0 @@ -126,7 +130,8 @@ class Admin(commands.Cog): ) else: logging.warning( - f"User {guild_name(ctx.user)} tried to use /clear but permission denied" + "User %s tried to use /clear but permission denied", + guild_name(ctx.user), ) await ctx.respond( embed=Embed( @@ -158,8 +163,8 @@ class Admin(commands.Cog): ) async def reboot_cmd(self, ctx: ApplicationContext): await ctx.defer(ephemeral=True) - if ctx.user.id in await config_get("admins"): - logging.info(f"Calling shutdown initiated by {guild_name(ctx.user)}") + if ctx.user.id in self.client.config["bot"]["owners"]: + logging.info("Calling shutdown initiated by %s", guild_name(ctx.user)) await ctx.respond( embed=Embed( title="Вимикаюсь...", @@ -171,7 +176,8 @@ class Admin(commands.Cog): exit() else: logging.warning( - f"User {guild_name(ctx.user)} tried to use /reboot but permission denied" + "User %s tried to use /reboot but permission denied", + guild_name(ctx.user), ) await ctx.respond( embed=Embed( @@ -195,3 +201,7 @@ class Admin(commands.Cog): color=Color.fail, ), ) + + +def setup(client: PycordBot): + client.add_cog(Admin(client)) diff --git a/cogs/analytics.py b/cogs/analytics.py index 64228ed..e08d204 100644 --- a/cogs/analytics.py +++ b/cogs/analytics.py @@ -2,6 +2,7 @@ import logging from discord import Cog, Message from discord.ext import commands +from libbot.pycord.classes import PycordBot from modules.database import col_analytics @@ -9,7 +10,7 @@ logger = logging.getLogger(__name__) class Analytics(commands.Cog): - def __init__(self, client): + def __init__(self, client: PycordBot): self.client = client @Cog.listener() @@ -54,3 +55,7 @@ class Analytics(commands.Cog): "attachments": attachments, } ) + + +def setup(client: PycordBot): + client.add_cog(Analytics(client)) diff --git a/cogs/custom_channels.py b/cogs/custom_channels.py index 30257ae..14c04a7 100644 --- a/cogs/custom_channels.py +++ b/cogs/custom_channels.py @@ -3,6 +3,7 @@ from discord import utils as ds_utils from discord.abc import GuildChannel from discord.commands import SlashCommandGroup from discord.ext import commands +from libbot.pycord.classes import PycordBot from classes.holo_user import HoloUser from enums.colors import Color @@ -12,7 +13,7 @@ from modules.utils_sync import config_get_sync, guild_name class CustomChannels(commands.Cog): - def __init__(self, client): + def __init__(self, client: PycordBot): self.client = client @commands.Cog.listener() @@ -80,7 +81,7 @@ class CustomChannels(commands.Cog): await ctx.respond( embed=Embed( title="Помилка виконання", - description=f"У вас вже є особистий канал.\nДля редагування каналу є `/customchannel edit` або просто відкрийте меню керування вашим каналом.", + description="У вас вже є особистий канал.\nДля редагування каналу є `/customchannel edit` або просто відкрийте меню керування вашим каналом.", color=Color.fail, ) ) @@ -105,7 +106,7 @@ class CustomChannels(commands.Cog): await ctx.respond( embed=Embed( title="Канал не знайдено", - description=f"Канал, вказаний як ваш, не існує. Можливо, його було вручну видалено раніше.", + description="Канал, вказаний як ваш, не існує. Можливо, його було вручну видалено раніше.", color=Color.fail, ) ) @@ -146,7 +147,7 @@ class CustomChannels(commands.Cog): await ctx.respond( embed=Embed( title="Канал не знайдено", - description=f"Канал, вказаний як ваш, не існує. Можливо, його було вручну видалено раніше.", + description="Канал, вказаний як ваш, не існує. Можливо, його було вручну видалено раніше.", color=Color.fail, ) ) @@ -156,7 +157,7 @@ class CustomChannels(commands.Cog): await ctx.respond( embed=Embed( title="Підтвердження не надано", - description=f"Для підтвердження операції додайте до команди параметр `confirm` зі значенням `True`.", + description="Для підтвердження операції додайте до команди параметр `confirm` зі значенням `True`.", color=Color.fail, ) ) @@ -166,7 +167,7 @@ class CustomChannels(commands.Cog): await ctx.respond( embed=Embed( title="Канал знищено", - description=f"Ви відмовились від каналу та видалили його.", + description="Ви відмовились від каналу та видалили його.", color=Color.default, ) ) @@ -175,7 +176,11 @@ class CustomChannels(commands.Cog): await ctx.respond( embed=Embed( title="Помилка виконання", - description=f"У вас немає особистого каналу.", + description="У вас немає особистого каналу.", color=Color.fail, ) ) + + +def setup(client: PycordBot): + client.add_cog(CustomChannels(client)) diff --git a/cogs/data.py b/cogs/data.py index fae6605..86ec308 100644 --- a/cogs/data.py +++ b/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)) diff --git a/cogs/fun.py b/cogs/fun.py index 7ddadfc..c539b09 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -2,6 +2,7 @@ import logging from discord import ApplicationContext, Embed, User, option, slash_command from discord.ext import commands +from libbot.pycord.classes import PycordBot from WaifuPicsPython import WaifuAsync from modules.utils import config_get @@ -13,7 +14,7 @@ wafiu_pics = WaifuAsync() class Fun(commands.Cog): - def __init__(self, client): + def __init__(self, client: PycordBot): self.client = client @slash_command( @@ -36,7 +37,13 @@ class Fun(commands.Cog): image = await wafiu_pics.sfw(action) logger.info( - f"User {guild_name(ctx.user)} ({ctx.user.id}) {action_verb} {guild_name(user)} ({user.id}) with image {image}" + "User %s (%s) %s %s (%s) with image %s", + guild_name(ctx.user), + ctx.user.id, + action_verb, + guild_name(user), + user.id, + image, ) embed = Embed( @@ -46,3 +53,7 @@ class Fun(commands.Cog): embed.set_image(url=image) await ctx.respond(embed=embed) + + +def setup(client: PycordBot): + client.add_cog(Fun(client)) diff --git a/cogs/logger.py b/cogs/logger.py index b949926..a3d3d61 100644 --- a/cogs/logger.py +++ b/cogs/logger.py @@ -1,13 +1,14 @@ from discord import Member, Message from discord import utils as ds_utils from discord.ext import commands +from libbot.pycord.classes import PycordBot from modules.database import col_users from modules.utils import config_get class Logger(commands.Cog): - def __init__(self, client): + def __init__(self, client: PycordBot): self.client = client @commands.Cog.listener() @@ -60,3 +61,7 @@ class Logger(commands.Cog): user[key] = defaults[key] col_users.insert_one(document=user) + + +def setup(client: PycordBot): + client.add_cog(Logger(client)) diff --git a/config_example.json b/config_example.json index 6f80821..a3cca7e 100644 --- a/config_example.json +++ b/config_example.json @@ -1,8 +1,16 @@ { - "token": "", - "owner": 0, + "locale": "en", + "debug": false, "guild": 0, - "admins": [], + "bot": { + "owners": [ + 0 + ], + "debug_guilds": [ + 0 + ], + "bot_token": "" + }, "status": { "type": "playing", "message": "on your nerves" diff --git a/locale/en.json b/locale/en.json new file mode 100644 index 0000000..7318a31 --- /dev/null +++ b/locale/en.json @@ -0,0 +1,9 @@ +{ + "metadata": { + "flag": "🇬🇧", + "name": "English", + "codes": [ + "en" + ] + } +} \ No newline at end of file diff --git a/locale/uk.json b/locale/uk.json new file mode 100644 index 0000000..88449f1 --- /dev/null +++ b/locale/uk.json @@ -0,0 +1,9 @@ +{ + "metadata": { + "flag": "🇺🇦", + "name": "Українська", + "codes": [ + "uk" + ] + } +} \ No newline at end of file diff --git a/main.py b/main.py index 3cac432..27c1f16 100644 --- a/main.py +++ b/main.py @@ -2,12 +2,6 @@ import logging from discord import Activity, ActivityType -from cogs.admin import Admin -from cogs.analytics import Analytics -from cogs.custom_channels import CustomChannels -from cogs.data import Data -from cogs.fun import Fun -from cogs.logger import Logger from modules.client import client from modules.scheduled import scheduler from modules.utils import config_get @@ -31,7 +25,7 @@ except ImportError: @client.event async def on_ready(): - logger.info(f"Logged in as {client.user}") + logger.info("Logged in as %s", client.user) activity_type = await config_get("type", "status") activity_message = await config_get("message", "status") @@ -63,16 +57,13 @@ async def on_ready(): else: return - logger.info(f"Set activity type to {activity_type} with message {activity_message}") + logger.info( + "Set activity type to %s with message %s", activity_type, activity_message + ) def main(): - client.add_cog(Admin(client)) - client.add_cog(Analytics(client)) - client.add_cog(CustomChannels(client)) - client.add_cog(Data(client)) - client.add_cog(Fun(client)) - client.add_cog(Logger(client)) + client.load_extension("cogs") try: scheduler.start() diff --git a/modules/client.py b/modules/client.py index 8b973b7..407b54e 100644 --- a/modules/client.py +++ b/modules/client.py @@ -1,5 +1,6 @@ -from discord import Intents, Bot +from discord import Intents +from libbot.pycord.classes import PycordBot intents = Intents().all() intents.members = True -client = Bot(intents=intents) \ No newline at end of file +client = PycordBot(intents=intents) diff --git a/requirements.txt b/requirements.txt index af35fb9..0b6c225 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ aiofiles==23.2.1 apscheduler==3.10.4 -py-cord[speed]==2.4.1 -pymongo==4.3.3 -requests==2.30.0 -ujson==5.7.0 -WaifuPicsPython==0.2.0 \ No newline at end of file +pymongo~=4.7.3 +requests~=2.32.3 +ujson~=5.10.0 +WaifuPicsPython==0.2.0 +--extra-index-url https://git.end-play.xyz/api/packages/profitroll/pypi/simple +libbot[speed,pycord]==3.2.2 \ No newline at end of file