optimised imports
This commit is contained in:
55
bot.py
55
bot.py
@@ -3,12 +3,11 @@ import asyncio
|
||||
from os import getenv
|
||||
from os.path import isfile
|
||||
|
||||
import disnake
|
||||
from disnake import OptionType, Option, Localized
|
||||
from disnake.ext import commands
|
||||
from disnake import OptionType, Option, Localized, ApplicationCommandInteraction, Intents, __version__
|
||||
from disnake.ext.commands import Bot, is_owner
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from __init__ import __version__
|
||||
from __init__ import __version__ as ver
|
||||
from lib.CogsPrep import work_with_cogs, cog_list
|
||||
from lib.Comands import determine_prefix
|
||||
from lib.Logger import logger
|
||||
@@ -22,19 +21,19 @@ if not isfile(getenv('CONF_FILE')):
|
||||
with open(getenv('CONF_FILE'), 'a', encoding='utf-8') as f:
|
||||
f.write("")
|
||||
|
||||
intents = disnake.Intents(messages=True,
|
||||
guilds=True,
|
||||
message_content=True,
|
||||
voice_states=True,
|
||||
members=True,
|
||||
presences=True
|
||||
)
|
||||
intents = Intents(messages=True,
|
||||
guilds=True,
|
||||
message_content=True,
|
||||
voice_states=True,
|
||||
members=True,
|
||||
presences=True
|
||||
)
|
||||
|
||||
bot = commands.Bot(command_prefix=determine_prefix,
|
||||
intents=intents,
|
||||
reload=True,
|
||||
test_guilds=[648126669122568215]
|
||||
)
|
||||
bot = Bot(command_prefix=determine_prefix,
|
||||
intents=intents,
|
||||
reload=True,
|
||||
test_guilds=[648126669122568215]
|
||||
)
|
||||
|
||||
bot.i18n.load("locale/")
|
||||
|
||||
@@ -44,9 +43,9 @@ asyncio.run(work_with_cogs('load', bot, asyncio.run(cog_list())))
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
logger.info('Bot started')
|
||||
logger.info(f'Disnake version {disnake.__version__}')
|
||||
logger.info(f'Disnake version {__version__}')
|
||||
logger.info(f'We have logged in as {bot.user}')
|
||||
logger.info(f'Version of bot is - v{__version__}')
|
||||
logger.info(f'Version of bot is - v{ver}')
|
||||
|
||||
|
||||
@bot.slash_command(
|
||||
@@ -59,8 +58,8 @@ async def on_ready():
|
||||
)
|
||||
]
|
||||
)
|
||||
@commands.is_owner()
|
||||
async def slash_cogs(inter: disnake.ApplicationCommandInteraction):
|
||||
@is_owner()
|
||||
async def slash_cogs(inter: ApplicationCommandInteraction):
|
||||
"""
|
||||
Working with cogs (modules) {{SLASH_COG}}
|
||||
|
||||
@@ -72,7 +71,7 @@ async def slash_cogs(inter: disnake.ApplicationCommandInteraction):
|
||||
|
||||
|
||||
@slash_cogs.sub_command(description=Localized("Enables Cog", key="ENABLE_COG"))
|
||||
async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
async def enable(inter: ApplicationCommandInteraction, cog: str):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
@@ -85,7 +84,7 @@ async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
|
||||
|
||||
@slash_cogs.sub_command(description=Localized("Disables Cog", key="DISABLE_COG"))
|
||||
async def disable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
async def disable(inter: ApplicationCommandInteraction, cog: str):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
@@ -98,7 +97,7 @@ async def disable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
|
||||
|
||||
@slash_cogs.sub_command(description=Localized("Loads Cog", key="LOAD_COG"))
|
||||
async def load(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
async def load(inter: ApplicationCommandInteraction, cog: str):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
@@ -111,7 +110,7 @@ async def load(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
|
||||
|
||||
@slash_cogs.sub_command(description=Localized("Unload Cog", key="UNLOAD_COG"))
|
||||
async def unload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
async def unload(inter: ApplicationCommandInteraction, cog: str):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
@@ -124,7 +123,7 @@ async def unload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
|
||||
|
||||
@slash_cogs.sub_command(description=Localized("Reloads Cog", key="RELOAD_COG"))
|
||||
async def reload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
async def reload(inter: ApplicationCommandInteraction, cog: str):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
@@ -140,21 +139,21 @@ async def reload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||
@unload.autocomplete('cog')
|
||||
@load.autocomplete('cog')
|
||||
@reload.autocomplete('cog')
|
||||
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, current: str):
|
||||
async def _cog_opt(inter: ApplicationCommandInteraction, current: str):
|
||||
current = current.lower()
|
||||
_list = await cog_list(fold='./cogs/')
|
||||
return [choice for choice in _list if current in choice.lower()]
|
||||
|
||||
|
||||
@enable.autocomplete('cog')
|
||||
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, current: str):
|
||||
async def _cog_opt(inter: ApplicationCommandInteraction, current: str):
|
||||
current = current.lower()
|
||||
_list = await cog_list(fold='./cogs/disabled/')
|
||||
return [choice for choice in _list if current in choice.lower()]
|
||||
|
||||
|
||||
@slash_cogs.error
|
||||
async def cogs_error(inter: disnake.ApplicationCommandInteraction):
|
||||
async def cogs_error(inter: ApplicationCommandInteraction):
|
||||
await inter.response.send_message(Localized("Error", key="EROR"), ephemeral=True)
|
||||
logger.error(f'User {inter.author} tries to use cogs func')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user