Updated localization and moved some commands
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
__version__ = '0.0.6'
|
__version__ = '0.0.7'
|
||||||
__title__ = "Pisya_bot"
|
__title__ = "Pisya_bot"
|
||||||
__author__ = "baconborn"
|
__author__ = "baconborn"
|
||||||
|
|
||||||
@@ -13,4 +13,4 @@ class VersionInfo(NamedTuple):
|
|||||||
serial: int
|
serial: int
|
||||||
|
|
||||||
|
|
||||||
version_info: VersionInfo = VersionInfo(major=0, minor=0, micro=6, releaselevel="alpha", serial=0)
|
version_info: VersionInfo = VersionInfo(major=0, minor=0, micro=7, releaselevel="alpha", serial=0)
|
||||||
|
|||||||
22
bot.py
22
bot.py
@@ -6,7 +6,7 @@ import disnake
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from disnake import OptionType, Option, Localized
|
from disnake import OptionType, Option, Localized
|
||||||
from disnake.ext import commands
|
from disnake.ext import commands
|
||||||
from __init__ import version_info as ver, __version__
|
from __init__ import __version__
|
||||||
from lib.CogsPrep import work_with_cogs, cog_list
|
from lib.CogsPrep import work_with_cogs, cog_list
|
||||||
from lib.Comands import determine_prefix
|
from lib.Comands import determine_prefix
|
||||||
from lib.Logger import logger
|
from lib.Logger import logger
|
||||||
@@ -44,15 +44,15 @@ async def on_ready():
|
|||||||
logger.info('Bot started')
|
logger.info('Bot started')
|
||||||
logger.info(f'Disnake version {disnake.__version__}')
|
logger.info(f'Disnake version {disnake.__version__}')
|
||||||
logger.info(f'We have logged in as {bot.user}')
|
logger.info(f'We have logged in as {bot.user}')
|
||||||
logger.info(f'Version of bot is - v{__version__}-{ver.releaselevel}')
|
logger.info(f'Version of bot is - v{__version__}')
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
name="cog",
|
name='cog',
|
||||||
options=[
|
options=[
|
||||||
Option(
|
Option(
|
||||||
'cog',
|
name=Localized('cog', key="COG".lower()),
|
||||||
description="specify cog",
|
description=Localized("cog file", key="COG_FILE"),
|
||||||
type=OptionType.string
|
type=OptionType.string
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@@ -69,7 +69,7 @@ async def slash_cogs(inter: disnake.ApplicationCommandInteraction):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@slash_cogs.sub_command(description=Localized("Enables Cog", key="ENABLES_COG"))
|
@slash_cogs.sub_command(description=Localized("Enables Cog", key="ENABLE_COG"))
|
||||||
async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
|||||||
await inter.response.send_message(f'Cog {cog} is enabled', ephemeral=True)
|
await inter.response.send_message(f'Cog {cog} is enabled', ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
@slash_cogs.sub_command(description='Disables Cog')
|
@slash_cogs.sub_command(description=Localized("Disables Cog", key="DISABLE_COG"))
|
||||||
async def disable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
async def disable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ async def disable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
|||||||
await inter.response.send_message(f'Cog {cog} is disabled', ephemeral=True)
|
await inter.response.send_message(f'Cog {cog} is disabled', ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
@slash_cogs.sub_command(description='Loads Cog')
|
@slash_cogs.sub_command(description=Localized("Loads Cog", key="LOAD_COG"))
|
||||||
async def load(inter: disnake.ApplicationCommandInteraction, cog: str):
|
async def load(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ async def load(inter: disnake.ApplicationCommandInteraction, cog: str):
|
|||||||
await inter.response.send_message(f'Cog {cog} is loaded', ephemeral=True)
|
await inter.response.send_message(f'Cog {cog} is loaded', ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
@slash_cogs.sub_command(description='Unloads Cog')
|
@slash_cogs.sub_command(description=Localized("Unload Cog", key="UNLOAD_COG"))
|
||||||
async def unload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
async def unload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ async def unload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
|||||||
await inter.response.send_message(f'Cog {cog} is unload', ephemeral=True)
|
await inter.response.send_message(f'Cog {cog} is unload', ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
@slash_cogs.sub_command(description='Reloads Cog')
|
@slash_cogs.sub_command(description=Localized("Reloads Cog", key="RELOAD_COG"))
|
||||||
async def reload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
async def reload(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ async def _cog_opt(inter: disnake.ApplicationCommandInteraction, current: str):
|
|||||||
|
|
||||||
@slash_cogs.error
|
@slash_cogs.error
|
||||||
async def cogs_error(inter: disnake.ApplicationCommandInteraction):
|
async def cogs_error(inter: disnake.ApplicationCommandInteraction):
|
||||||
await inter.response.send_message('Error', ephemeral=True)
|
await inter.response.send_message(Localized("Error", key="EROR"), ephemeral=True)
|
||||||
logger.error(f'User {inter.author} tries to use cogs func')
|
logger.error(f'User {inter.author} tries to use cogs func')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
from disnake import Option, OptionType, OptionChoice
|
from disnake import Option, OptionType, Localized
|
||||||
|
|
||||||
from disnake.ext import commands, tasks
|
from disnake.ext import commands, tasks
|
||||||
|
|
||||||
from lib.Comands import read_json, write_json
|
from lib.Comands import read_json, write_json
|
||||||
@@ -68,10 +66,13 @@ class Admin(commands.Cog, name='Admin'):
|
|||||||
await member.add_roles(role)
|
await member.add_roles(role)
|
||||||
|
|
||||||
@commands.slash_command(
|
@commands.slash_command(
|
||||||
name="set_guest_role",
|
name="set_default_role",
|
||||||
description="Set Default bot role",
|
description=Localized("Set Default bot role", key="DEF_ROLE"),
|
||||||
options=[
|
options=[
|
||||||
Option("role", "Specify role", OptionType.role, required=True),
|
Option("role",
|
||||||
|
"Specify role",
|
||||||
|
OptionType.role,
|
||||||
|
required=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
@@ -90,7 +91,10 @@ class Admin(commands.Cog, name='Admin'):
|
|||||||
name="set_prefix",
|
name="set_prefix",
|
||||||
description="Setting up bot prefix",
|
description="Setting up bot prefix",
|
||||||
options=[
|
options=[
|
||||||
Option("prefix", "Specify prefix", OptionType.string, required=True),
|
Option("prefix",
|
||||||
|
"Specify prefix",
|
||||||
|
OptionType.string,
|
||||||
|
required=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=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)
|
await inter.response.send_message(f"Prefix set to: `{prefix}`", ephemeral=True)
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
@commands.slash_command(
|
@commands.slash_command(
|
||||||
name="set_trigger_role",
|
name="set_trigger_role",
|
||||||
description="Setting up role to trigger bot",
|
description=Localized("Setting up role to trigger bot", key="KEY_ROLE"),
|
||||||
options=[
|
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):
|
async def set_trigger_role(self, inter: disnake.ApplicationCommandInteraction, role):
|
||||||
await write_json(inter.guild.id, "tigger_role", role.id)
|
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(
|
@commands.slash_command(
|
||||||
name="set_bot_role",
|
name="set_bot_role",
|
||||||
description="Set Default bot role",
|
description=Localized("Set bot role", key="BOT_ROLE"),
|
||||||
options=[
|
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.guild_only()
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def set_bot_role(self, ctx, role):
|
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)
|
await ctx.send(f"Set up bot role to: `{role.name}`", ephemeral=True)
|
||||||
|
|
||||||
@set_bot_role.error
|
@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)
|
await inter.response.send_message("You don`t have permissions", ephemeral=True)
|
||||||
logger.error(prefix)
|
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
|
def setup(bot): # an extension must have a setup function
|
||||||
bot.add_cog(Admin(bot)) # adding a cog
|
bot.add_cog(Admin(bot)) # adding a cog
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from disnake import OptionChoice, Option, OptionType, Member, VoiceState
|
|||||||
from disnake.ext import commands
|
from disnake.ext import commands
|
||||||
|
|
||||||
from lib.Logger import logger
|
from lib.Logger import logger
|
||||||
from lib.DB_Worker import read_db
|
|
||||||
from lib.Player import play_audio
|
from lib.Player import play_audio
|
||||||
from lib.ListGenerator import ListGenerator
|
from lib.ListGenerator import ListGenerator
|
||||||
|
|
||||||
@@ -30,19 +29,11 @@ class Audio(commands.Cog, name='Audio'):
|
|||||||
# Prepare list of audio
|
# Prepare list of audio
|
||||||
from lib.Comands import read_json
|
from lib.Comands import read_json
|
||||||
_role = await read_json(member.guild.id, 'tigger_role')
|
_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 = []
|
audio: list = []
|
||||||
if audio_db is not None:
|
for _a in ListGenerator('audio'):
|
||||||
audio = audio_db.split(', ')
|
audio.append(_a.name)
|
||||||
else:
|
|
||||||
for _a in ListGenerator('audio'):
|
|
||||||
audio.append(_a.name)
|
|
||||||
|
|
||||||
if audio_db is not None:
|
if len(member.roles) == 1 or _role is 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:
|
|
||||||
logger.info('Skip playing by role')
|
logger.info('Skip playing by role')
|
||||||
elif any(str(role.id) in _role for role in member.roles):
|
elif any(str(role.id) in _role for role in member.roles):
|
||||||
logger.info('Play audio from list by role')
|
logger.info('Play audio from list by role')
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
import disnake
|
||||||
|
from disnake import OptionChoice
|
||||||
from disnake.ext import commands
|
from disnake.ext import commands
|
||||||
|
|
||||||
|
from lib.Comands import write_json
|
||||||
from lib.Logger import logger
|
from lib.Logger import logger
|
||||||
|
|
||||||
|
|
||||||
@@ -10,6 +16,28 @@ class Fun(commands.Cog, name='Fun'):
|
|||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
|
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
|
def setup(bot): # an extension must have a setup function
|
||||||
bot.add_cog(Fun(bot)) # adding a cog
|
bot.add_cog(Fun(bot)) # adding a cog
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import disnake
|
import disnake
|
||||||
from disnake import Option, OptionType, Colour
|
from disnake import Option, OptionType, Colour, Localized
|
||||||
from disnake.ext import commands
|
from disnake.ext import commands
|
||||||
|
|
||||||
from lib.DB_Worker import DBReader
|
|
||||||
from lib.Logger import logger
|
from lib.Logger import logger
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +16,9 @@ class General(commands.Cog):
|
|||||||
@commands.slash_command(
|
@commands.slash_command(
|
||||||
name="info",
|
name="info",
|
||||||
options=[
|
options=[
|
||||||
Option("user", "Specify any user", OptionType.user),
|
Option("user",
|
||||||
|
"Specify any user",
|
||||||
|
OptionType.user),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
async def info(self, inter: disnake.ApplicationCommandInteraction, user=None):
|
async def info(self, inter: disnake.ApplicationCommandInteraction, user=None):
|
||||||
@@ -49,7 +50,7 @@ class General(commands.Cog):
|
|||||||
f"Nickname: {user.nick}\n"
|
f"Nickname: {user.nick}\n"
|
||||||
f"Joined at: {user.joined_at.strftime('%A, %B %d %Y @ %H:%M:%S')}", inline=False)
|
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.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)
|
await inter.response.send_message(embed=emb, ephemeral=True)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ work_with_cogs: loads, reloads and unloads cogs files
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import traceback
|
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ client = Client(os.getenv('Yandex_Token')).init()
|
|||||||
|
|
||||||
def _search(_str: str, _type: str):
|
def _search(_str: str, _type: str):
|
||||||
search_result = client.search(_str, type_=_type)
|
search_result = client.search(_str, type_=_type)
|
||||||
|
print(search_result)
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
{
|
{
|
||||||
"ENABLES_COG": "Включение кога",
|
|
||||||
"COG_FILE": "Выберите ког файл",
|
"COG_FILE": "Выберите ког файл",
|
||||||
|
"ENABLE_COG": "Включение кога",
|
||||||
|
"DISABLE_COG": "Отключение кога",
|
||||||
|
"LOAD_COG": "Загрузка кога",
|
||||||
|
"UNLOAD_COG": "Выгрузка кога",
|
||||||
|
"RELOAD_COG": "Перезагрузка кога",
|
||||||
|
"SLASH_COG": "Работа с когами(модулями)",
|
||||||
"SLASH_INFO": "Отобрадение информации о пользователе",
|
"SLASH_INFO": "Отобрадение информации о пользователе",
|
||||||
"SLASH_COG": "Работа с когами(модулями)"
|
"ERROR": "Ошибка",
|
||||||
|
"COG": "ког",
|
||||||
|
"DEF_ROLE": "Установка стандартной роли",
|
||||||
|
"KEY_ROLE": "Установка роли-триггера",
|
||||||
|
"BOT_ROLE": "Установка роли бота",
|
||||||
|
"SETUP_ROLE": "Укажите роль",
|
||||||
|
"SET_ROLE": "Роль установлена"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user