fixed start after move

This commit is contained in:
bacon
2024-03-18 02:27:01 +03:00
parent 76d1625346
commit 98e71f66e9
43 changed files with 30 additions and 27 deletions

View File

@@ -1,5 +0,0 @@
"""
integral_lib
~~~~~~~~~~~~~
Some libs for the bot which help him
"""

View File

@@ -1,5 +1,5 @@
__version__ = '0.0.7' __version__ = '0.0.7'
__title__ = "bot" __title__ = "src"
__author__ = "baconborn" __author__ = "baconborn"
from typing import NamedTuple, Literal from typing import NamedTuple, Literal

View File

@@ -11,7 +11,7 @@ from integral_lib.Logger import logger
class Admin(commands.Cog, name='Admin'): class Admin(commands.Cog, name='Admin'):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot # a defining bot as global var in class self.bot = bot # a defining src as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners @commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self): async def on_ready(self):
@@ -54,7 +54,7 @@ class Admin(commands.Cog, name='Admin'):
async def on_member_join(self, member): async def on_member_join(self, member):
await fill_bd(member.name, member.id, member.bot, member.nick, member.guild.id) await fill_bd(member.name, member.id, member.bot, member.nick, member.guild.id)
bot_role = read_json(member.guild.id, 'bot_role') # Get bot role bot_role = read_json(member.guild.id, 'bot_role') # Get src role
guest_role = read_json(member.guild.id, 'guest_role') # Get guest role guest_role = read_json(member.guild.id, 'guest_role') # Get guest role
if bot_role or guest_role: if bot_role or guest_role:
@@ -67,7 +67,7 @@ class Admin(commands.Cog, name='Admin'):
@commands.slash_command( @commands.slash_command(
name="set_default_role", name="set_default_role",
description=Localized("Set Default bot role", key="DEF_ROLE"), description=Localized("Set Default src role", key="DEF_ROLE"),
options=[ options=[
Option("role", Option("role",
"Specify role", "Specify role",
@@ -78,7 +78,7 @@ class Admin(commands.Cog, name='Admin'):
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
async def set_guest_role(self, inter: disnake.ApplicationCommandInteraction, role): async def set_guest_role(self, inter: disnake.ApplicationCommandInteraction, role):
await write_json(inter.guild.id, "guest_role", role.id) await write_json(inter.guild.id, "guest_role", role.id)
await inter.response.send_message(f"Set up bot role to: `{role.name}`", ephemeral=True) await inter.response.send_message(f"Set up src role to: `{role.name}`", ephemeral=True)
@commands.command(name="set_prefix") @commands.command(name="set_prefix")
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
@@ -89,7 +89,7 @@ class Admin(commands.Cog, name='Admin'):
@commands.guild_only() @commands.guild_only()
@commands.slash_command( @commands.slash_command(
name="set_prefix", name="set_prefix",
description="Setting up bot prefix", description="Setting up src prefix",
options=[ options=[
Option("prefix", Option("prefix",
"Specify prefix", "Specify prefix",
@@ -106,7 +106,7 @@ class Admin(commands.Cog, name='Admin'):
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
@commands.slash_command( @commands.slash_command(
name="set_trigger_role", name="set_trigger_role",
description=Localized("Setting up role to trigger bot", key="KEY_ROLE"), description=Localized("Setting up role to trigger src", key="KEY_ROLE"),
options=[ options=[
Option("role", Option("role",
Localized("Specify role", key="SETUP_ROLE"), Localized("Specify role", key="SETUP_ROLE"),
@@ -120,7 +120,7 @@ class Admin(commands.Cog, name='Admin'):
@commands.slash_command( @commands.slash_command(
name="set_bot_role", name="set_bot_role",
description=Localized("Set bot role", key="BOT_ROLE"), description=Localized("Set src role", key="BOT_ROLE"),
options=[ options=[
Option("role", Option("role",
Localized("Specify role", key="SETUP_ROLE"), Localized("Specify role", key="SETUP_ROLE"),
@@ -134,7 +134,7 @@ class Admin(commands.Cog, name='Admin'):
await write_json(ctx.guild.id, await write_json(ctx.guild.id,
"bot_role", "bot_role",
role.id) role.id)
await ctx.send(f"Set up bot role to: `{role.name}`", ephemeral=True) await ctx.send(f"Set up src role to: `{role.name}`", ephemeral=True)
@set_bot_role.error @set_bot_role.error
@set_trigger_role.error @set_trigger_role.error

View File

@@ -27,7 +27,7 @@ class Audio(commands.Cog, name='Audio'):
logger.info('Skip playing by Game') logger.info('Skip playing by Game')
else: else:
# Prepare list of audio # Prepare list of audio
from bot.integral_lib.Comands import read_json from src.integral_lib.Comands import read_json
_role = await read_json(member.guild.id, 'tigger_role') _role = await read_json(member.guild.id, 'tigger_role')
audio: list = [] audio: list = []
for _a in ListGenerator('audio'): for _a in ListGenerator('audio'):

View File

@@ -10,7 +10,7 @@ from integral_lib.Logger import logger
class Fun(commands.Cog, name='Fun'): class Fun(commands.Cog, name='Fun'):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot # defining bot as global var in class self.bot = bot # defining src as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners @commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self): async def on_ready(self):
@@ -19,7 +19,7 @@ class Fun(commands.Cog, name='Fun'):
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
@commands.slash_command( @commands.slash_command(
name="set_bot_channel", name="set_bot_channel",
description="Set channel which iterate with bot", description="Set channel which iterate with src",
) )
async def set_bot_channel(self, inter: disnake.ApplicationCommandInteraction, channel: str): async def set_bot_channel(self, inter: disnake.ApplicationCommandInteraction, channel: str):

View File

@@ -8,7 +8,7 @@ from integral_lib.Logger import logger
class Testing(commands.Cog, name='Testing'): class Testing(commands.Cog, name='Testing'):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot # defining bot as global var in class self.bot = bot # defining src as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners @commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self): async def on_ready(self):

View File

@@ -7,7 +7,7 @@ from integral_lib.Logger import logger
class General(commands.Cog): class General(commands.Cog):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot # defining bot as global var in class self.bot = bot # defining src as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners @commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self): async def on_ready(self):

View File

@@ -12,20 +12,20 @@ from integral_lib.Logger import logger
class BotInfo(commands.Cog, name='Bot Info'): class BotInfo(commands.Cog, name='Bot Info'):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot # defining bot as global var in class self.bot = bot # defining src as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners @commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self): async def on_ready(self):
logger.info(f'Cog {__name__.split(".")[1]} is ready!.') logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
@commands.slash_command(name="info_bot", @commands.slash_command(name="info_bot",
description='Shows general info about bot') # this is for making a command description='Shows general info about src') # this is for making a command
async def info_bot(self, inter: ApplicationCommandInteraction): async def info_bot(self, inter: ApplicationCommandInteraction):
_pid = os.getpid() _pid = os.getpid()
_process = psutil.Process(_pid) _process = psutil.Process(_pid)
emb = disnake.Embed( emb = disnake.Embed(
title="General information", title="General information",
description="General information on about bot", description="General information on about src",
) )
emb.set_thumbnail(self.bot.user.avatar.url) emb.set_thumbnail(self.bot.user.avatar.url)
emb.add_field(name="System info:", value=f"Memory Usage: {round(_process.memory_info().rss / 2 ** 20, 2)} Mb\n" emb.add_field(name="System info:", value=f"Memory Usage: {round(_process.memory_info().rss / 2 ** 20, 2)} Mb\n"

View File

@@ -38,7 +38,7 @@ def work_with_cogs(what_do: str,
Perform the specified action on the given cog or list of cogs. Perform the specified action on the given cog or list of cogs.
Args: Args:
what_do (str): The action to perform (load, unload, reload, disable, enable). what_do (str): The action to perform (load, unload, reload, disable, enable).
bot (InteractionBotBase): The bot instance to work with. src (InteractionBotBase): The src instance to work with.
cog (str | list): The name of the cog or a list of cogs to work with. cog (str | list): The name of the cog or a list of cogs to work with.
Raises: Raises:
ValueError: If the action is not recognized. ValueError: If the action is not recognized.

View File

@@ -66,7 +66,7 @@ async def write_json(guild: int, param_name: str, param: str or int):
def determine_prefix(bot: commands.Bot, msg): def determine_prefix(bot: commands.Bot, msg):
""" """
Determine the per-server bot prefix based on the given message object. Determine the per-server src prefix based on the given message object.
:param bot: Disnake Bot object :param bot: Disnake Bot object
:param msg: Disnake msg object :param msg: Disnake msg object

View File

@@ -0,0 +1,5 @@
"""
integral_lib
~~~~~~~~~~~~~
Some libs for the src which help him
"""

View File

@@ -1,14 +1,17 @@
import sys
import pytest import pytest
from disnake.ext.commands.common_bot_base import CommonBotBase from disnake.ext.commands.common_bot_base import CommonBotBase
from mock import mock from mock import mock
from integral_lib.CogsPrep import cog_list, work_with_cogs sys.path.append('src')
from integral_lib import CogsPrep
def test_cog_list(): def test_cog_list():
with mock.patch('integral_lib.CogsPrep.listdir') as MockClass: with mock.patch('integral_lib.CogsPrep.listdir') as MockClass:
MockClass.return_value = ['cog1.py', 'cog2.py'] MockClass.return_value = ['cog1.py', 'cog2.py']
result = cog_list() result = CogsPrep.cog_list()
assert result == ['cog1', 'cog2'] assert result == ['cog1', 'cog2']
@@ -18,7 +21,7 @@ def test_work_with_cogs(what_do, cog):
with mock.patch('integral_lib.CogsPrep.rename') as mock_rename: with mock.patch('integral_lib.CogsPrep.rename') as mock_rename:
mock_rename.return_value = None mock_rename.return_value = None
mock_bot = mock.MagicMock(spec=CommonBotBase) mock_bot = mock.MagicMock(spec=CommonBotBase)
result = work_with_cogs(what_do, mock_bot, cog) result = CogsPrep.work_with_cogs(what_do, mock_bot, cog)
if what_do in ['load', 'enable']: if what_do in ['load', 'enable']:
assert mock_bot.load_extension.called assert mock_bot.load_extension.called
elif what_do in ['unload', 'disable']: elif what_do in ['unload', 'disable']: