updated structure

This commit is contained in:
bacon
2024-03-17 22:03:27 +03:00
parent 4e535f6580
commit d22c3ca6b6
44 changed files with 955 additions and 948 deletions

View File

@@ -0,0 +1,43 @@
from typing import List
import disnake
from disnake import OptionChoice
from disnake.ext import commands
from bot.lib import logger
from bot.lib import write_json
class Fun(commands.Cog, name='Fun'):
def __init__(self, bot: commands.Bot):
self.bot = bot # defining bot as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self):
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
@commands.has_permissions(administrator=True)
@commands.slash_command(
name="set_bot_channel",
description="Set channel which iterate with bot",
)
async def set_bot_channel(self, inter: disnake.ApplicationCommandInteraction, channel: str):
await write_json(inter.guild.id,
"channel",
disnake.utils.find(lambda d: d.name == channel, inter.guild.channels).id)
await inter.response.send_message(f"Channel set up to {channel}", ephemeral=True)
@set_bot_channel.autocomplete('channel')
async def _list_text_channels(self,
inter: disnake.ApplicationCommandInteraction,
current: str) -> List[OptionChoice]:
_list = [r.name for r in inter.guild.text_channels]
return [
OptionChoice(name=choice, value=choice)
for choice in _list if current in choice
]
def setup(bot): # an extension must have a setup function
bot.add_cog(Fun(bot)) # adding a cog

29
bot/cogs/disabled/test.py Normal file
View File

@@ -0,0 +1,29 @@
import disnake
from disnake import Option
from disnake.ext import commands
from bot.lib import YandexPlayer
from bot.lib import logger
class Testing(commands.Cog, name='Testing'):
def __init__(self, bot: commands.Bot):
self.bot = bot # defining bot as global var in class
@commands.Cog.listener() # this is a decorator for events/listeners
async def on_ready(self):
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
@commands.slash_command(name='play', description='play audio test from yandex.music', options=[
Option(name='search',
description='seach track/artist',
required=True),
])
async def play(self, inter: disnake.ApplicationCommandInteraction, search: str):
# TODO add yandex_music player with queue, playlists
result = YandexPlayer.search(search)
await inter.response.send_message(result, ephemeral=True)
def setup(bot): # an extension must have a setup function
bot.add_cog(Testing(bot)) # adding a cog