Extend commands

This commit is contained in:
2022-09-07 21:36:09 +03:00
parent 013b33731b
commit 5d96b76541
12 changed files with 136 additions and 110 deletions

28
bot.py
View File

@@ -1,12 +1,13 @@
#!/usr/bin/env python3
import asyncio
import os
from typing import List
import disnake
from disnake import OptionChoice, OptionType, Option
from disnake.ext import commands
from __init__ import version_info as ver
from lib import work_with_cogs
from lib import work_with_cogs, cog_list
from lib import preload_checks, determine_prefix
from lib import logger
@@ -27,7 +28,7 @@ bot = commands.Bot(command_prefix=determine_prefix,
)
asyncio.run(work_with_cogs('load', bot))
asyncio.run(work_with_cogs('load', bot, cog_list()))
@bot.event
@@ -51,19 +52,34 @@ async def on_ready():
OptionChoice("unload", "unload"),
OptionChoice("reload", "reload")
]
),
Option(
'cog',
description="specify cog",
type=OptionType.string
)
]
)
@commands.is_owner()
async def slash_cogs(inter, what_do):
await work_with_cogs(what_do, bot)
async def slash_cogs(inter, what_do, cog: str = cog_list()) -> None:
print(type(inter.guild.text_channels))
await work_with_cogs(what_do, bot, cog)
await inter.response.send_message(f'Cogs are {what_do}ed', ephemeral=True)
@slash_cogs.autocomplete('cog')
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, current: str) -> List[OptionChoice]:
_list = cog_list()
return [
OptionChoice(name=choice, value=choice)
for choice in _list if current.lower() in choice.lower()
]
@slash_cogs.error
async def cogs_error(inter, what_do):
await inter.response.send_message(f'{what_do}', ephemeral=True)
logger.error(f'User {inter.author} tries to use cogs func')
await inter.response.send_message(f'Error', ephemeral=True)
logger.error(f'User {inter.author} tries to use cogs func\n{what_do}\n')
bot.run(os.getenv('TOKEN'))