This commit is contained in:
Profitroll 2024-06-23 12:05:03 +02:00
parent d168821fb5
commit f67375ff4f
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2
12 changed files with 114 additions and 51 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

9
locale/en.json Normal file
View File

@ -0,0 +1,9 @@
{
"metadata": {
"flag": "🇬🇧",
"name": "English",
"codes": [
"en"
]
}
}

9
locale/uk.json Normal file
View File

@ -0,0 +1,9 @@
{
"metadata": {
"flag": "🇺🇦",
"name": "Українська",
"codes": [
"uk"
]
}
}

19
main.py
View File

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

View File

@ -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)
client = PycordBot(intents=intents)

View File

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