Updated localization and moved some commands

This commit is contained in:
bacon
2024-03-09 18:54:26 +03:00
parent 3bd30239ae
commit 01db1c254d
9 changed files with 89 additions and 82 deletions

View File

@@ -1,9 +1,7 @@
from asyncio import sleep
from typing import List
import disnake
from disnake import Option, OptionType, OptionChoice
from disnake import Option, OptionType, Localized
from disnake.ext import commands, tasks
from lib.Comands import read_json, write_json
@@ -68,10 +66,13 @@ class Admin(commands.Cog, name='Admin'):
await member.add_roles(role)
@commands.slash_command(
name="set_guest_role",
description="Set Default bot role",
name="set_default_role",
description=Localized("Set Default bot role", key="DEF_ROLE"),
options=[
Option("role", "Specify role", OptionType.role, required=True),
Option("role",
"Specify role",
OptionType.role,
required=True),
]
)
@commands.has_permissions(administrator=True)
@@ -90,7 +91,10 @@ class Admin(commands.Cog, name='Admin'):
name="set_prefix",
description="Setting up bot prefix",
options=[
Option("prefix", "Specify prefix", OptionType.string, required=True),
Option("prefix",
"Specify prefix",
OptionType.string,
required=True),
]
)
@commands.has_permissions(administrator=True)
@@ -99,29 +103,37 @@ class Admin(commands.Cog, name='Admin'):
await inter.response.send_message(f"Prefix set to: `{prefix}`", ephemeral=True)
@commands.guild_only()
@commands.has_permissions(administrator=True)
@commands.slash_command(
name="set_trigger_role",
description="Setting up role to trigger bot",
description=Localized("Setting up role to trigger bot", key="KEY_ROLE"),
options=[
Option("role", "Specify role", OptionType.role, required=True),
Option("role",
Localized("Specify role", key="SETUP_ROLE"),
OptionType.role,
required=True),
]
)
@commands.has_permissions(administrator=True)
async def set_trigger_role(self, inter: disnake.ApplicationCommandInteraction, role):
await write_json(inter.guild.id, "tigger_role", role.id)
await inter.response.send_message(f"Role to trigger set to : `{role.name}`", ephemeral=True)
await inter.response.send_message(f"Role set to: `{role.name}`", ephemeral=True)
@commands.slash_command(
name="set_bot_role",
description="Set Default bot role",
description=Localized("Set bot role", key="BOT_ROLE"),
options=[
Option("role", "Specify role", OptionType.role, required=True),
Option("role",
Localized("Specify role", key="SETUP_ROLE"),
OptionType.role,
required=True)
]
)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def set_bot_role(self, ctx, role):
await write_json(ctx.guild.id, "bot_role", role.id)
await write_json(ctx.guild.id,
"bot_role",
role.id)
await ctx.send(f"Set up bot role to: `{role.name}`", ephemeral=True)
@set_bot_role.error
@@ -131,42 +143,6 @@ class Admin(commands.Cog, name='Admin'):
await inter.response.send_message("You don`t have permissions", ephemeral=True)
logger.error(prefix)
@commands.has_permissions(administrator=True)
@commands.slash_command(
name="set_time",
description="Read list of tracks for user",
options=[
Option("seconds", "specify max duration", OptionType.integer, required=True),
]
)
async def set_time(self,
inter: disnake.ApplicationCommandInteraction,
seconds: commands.Range[int, 5, 30]):
await write_json(inter.guild.id, "seconds", seconds)
await inter.response.send_message(f"Change max audio duration to {seconds} sec", ephemeral=True)
@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(Admin(bot)) # adding a cog

View File

@@ -5,7 +5,6 @@ from disnake import OptionChoice, Option, OptionType, Member, VoiceState
from disnake.ext import commands
from lib.Logger import logger
from lib.DB_Worker import read_db
from lib.Player import play_audio
from lib.ListGenerator import ListGenerator
@@ -30,19 +29,11 @@ class Audio(commands.Cog, name='Audio'):
# Prepare list of audio
from lib.Comands import read_json
_role = await read_json(member.guild.id, 'tigger_role')
# Read audio from DB
audio_db = await read_db(member.guild.id, member.id, 'defaulttracks')
audio: list = []
if audio_db is not None:
audio = audio_db.split(', ')
else:
for _a in ListGenerator('audio'):
audio.append(_a.name)
for _a in ListGenerator('audio'):
audio.append(_a.name)
if audio_db is not None:
logger.info('Play audio from DB')
await play_audio(f'audio/{random.choice(audio)}', self.bot, after.channel)
elif len(member.roles) == 1 or _role is None:
if len(member.roles) == 1 or _role is None:
logger.info('Skip playing by role')
elif any(str(role.id) in _role for role in member.roles):
logger.info('Play audio from list by role')

View File

@@ -1,4 +1,10 @@
from typing import List
import disnake
from disnake import OptionChoice
from disnake.ext import commands
from lib.Comands import write_json
from lib.Logger import logger
@@ -10,6 +16,28 @@ class Fun(commands.Cog, name='Fun'):
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

View File

@@ -1,8 +1,7 @@
import disnake
from disnake import Option, OptionType, Colour
from disnake import Option, OptionType, Colour, Localized
from disnake.ext import commands
from lib.DB_Worker import DBReader
from lib.Logger import logger
@@ -17,7 +16,9 @@ class General(commands.Cog):
@commands.slash_command(
name="info",
options=[
Option("user", "Specify any user", OptionType.user),
Option("user",
"Specify any user",
OptionType.user),
]
)
async def info(self, inter: disnake.ApplicationCommandInteraction, user=None):
@@ -49,7 +50,7 @@ class General(commands.Cog):
f"Nickname: {user.nick}\n"
f"Joined at: {user.joined_at.strftime('%A, %B %d %Y @ %H:%M:%S')}", inline=False)
emb.add_field(name="Roles list", value=f"{roles}")
emb.set_footer(text=f"Information requested by: {inter.author.display_name}")
emb.set_footer(text=f"{Localized('Information requested by', key='REQUEST_INFO')}: {inter.author.display_name}")
await inter.response.send_message(embed=emb, ephemeral=True)