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