Compare commits
No commits in common. "ba5d897662b683e8b90b2c418234814306a52dd0" and "47415af8683bfc5c36533e2865cbd01a8b99dac5" have entirely different histories.
ba5d897662
...
47415af868
@ -1,7 +1,5 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from cpl_query.extension import List
|
|
||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
|
|
||||||
@ -30,6 +28,3 @@ class ClientUtilsServiceABC(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def presence_game(self, t_key: str): pass
|
async def presence_game(self, t_key: str): pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_auto_complete_list(self, _l: List, current: str, select: Callable = None) -> List: pass
|
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
from typing import Callable
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
from cpl_core.logging import LoggerABC
|
from cpl_core.logging import LoggerABC
|
||||||
|
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
from cpl_query.extension import List
|
|
||||||
from cpl_translation import TranslatePipe
|
from cpl_translation import TranslatePipe
|
||||||
from discord import app_commands
|
|
||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||||
@ -92,17 +88,3 @@ class ClientUtilsService(ClientUtilsServiceABC):
|
|||||||
name = self._t.transform(t_key).format(bot.__version__)
|
name = self._t.transform(t_key).format(bot.__version__)
|
||||||
await self._bot.change_presence(activity=discord.Game(name=name))
|
await self._bot.change_presence(activity=discord.Game(name=name))
|
||||||
self._logger.info(__name__, f'Set presence {name}')
|
self._logger.info(__name__, f'Set presence {name}')
|
||||||
|
|
||||||
def get_auto_complete_list(self, _l: List, current: str, select: Callable = None) -> List:
|
|
||||||
if current != '':
|
|
||||||
if select is None:
|
|
||||||
select = lambda x: x
|
|
||||||
|
|
||||||
sl = _l.select(select)
|
|
||||||
sl = sl.where(lambda x: current in x)
|
|
||||||
if current in sl:
|
|
||||||
sl = sl.skip(sl.index_of(current))
|
|
||||||
|
|
||||||
_l = _l.where(lambda x: x.name in sl)
|
|
||||||
|
|
||||||
return _l.take(25)
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import List as TList, Optional, Any
|
from typing import List as TList, Optional
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
@ -50,11 +50,6 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||||
|
|
||||||
async def _auto_role_auto_complete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
|
||||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
|
||||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
|
||||||
return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in self._client_utils.get_auto_complete_list(auto_roles, current)]
|
|
||||||
|
|
||||||
@commands.hybrid_group(name="auto-role")
|
@commands.hybrid_group(name="auto-role")
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def auto_role(self, ctx: Context):
|
async def auto_role(self, ctx: Context):
|
||||||
@ -160,7 +155,9 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
@remove.autocomplete('auto_role')
|
@remove.autocomplete('auto_role')
|
||||||
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
return await self._auto_role_auto_complete(interaction, current)
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
|
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
||||||
|
return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
|
||||||
|
|
||||||
@auto_role.group()
|
@auto_role.group()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -201,7 +198,9 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
@list.autocomplete('auto_role')
|
@list.autocomplete('auto_role')
|
||||||
async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
return await self._auto_role_auto_complete(interaction, current)
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
|
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
||||||
|
return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
|
||||||
|
|
||||||
@rule.command()
|
@rule.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -256,17 +255,19 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
@add.autocomplete('auto_role')
|
@add.autocomplete('auto_role')
|
||||||
async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
return await self._auto_role_auto_complete(interaction, current)
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
|
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
||||||
|
return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
|
||||||
|
|
||||||
@add.autocomplete('emoji_name')
|
@add.autocomplete('emoji_name')
|
||||||
async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
emojis = List(discord.Emoji, interaction.guild.emojis)
|
emojis = interaction.guild.emojis
|
||||||
return [app_commands.Choice(name=emoji.name, value=emoji.name) for emoji in self._client_utils.get_auto_complete_list(emojis, current, lambda e: e.name)]
|
return [app_commands.Choice(name=emoji.name, value=emoji.name) for emoji in emojis]
|
||||||
|
|
||||||
@add.autocomplete('role_id')
|
@add.autocomplete('role_id')
|
||||||
async def rule_add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def rule_add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
roles = List(discord.Role, interaction.guild.roles)
|
roles = interaction.guild.roles
|
||||||
return [app_commands.Choice(name=role.name, value=str(role.id)) for role in self._client_utils.get_auto_complete_list(roles, current, lambda r: r.name)]
|
return [app_commands.Choice(name=role.name, value=str(role.id)) for role in roles]
|
||||||
|
|
||||||
@rule.command()
|
@rule.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -293,10 +294,4 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
||||||
rules = auto_roles.select_many(lambda ar: self._auto_roles.get_auto_role_rules_by_auto_role_id(ar))
|
rules = auto_roles.select_many(lambda ar: self._auto_roles.get_auto_role_rules_by_auto_role_id(ar))
|
||||||
return [
|
return [app_commands.Choice(name=f'{rule.auto_role_rule_id} {rule.emoji_name} {interaction.guild.get_role(int(rule.role_id))}', value=rule.auto_role_rule_id) for rule in rules]
|
||||||
app_commands.Choice(
|
|
||||||
name=f'{rule.auto_role_rule_id} {rule.emoji_name} {interaction.guild.get_role(int(rule.role_id))}',
|
|
||||||
value=rule.auto_role_rule_id
|
|
||||||
)
|
|
||||||
for rule in self._client_utils.get_auto_complete_list(rules, current, lambda r: r.auto_role_rule_id)
|
|
||||||
]
|
|
||||||
|
@ -93,11 +93,6 @@ class LevelGroup(DiscordCommandABC):
|
|||||||
self._logger.error(__name__, f'Level seeding failed', e)
|
self._logger.error(__name__, f'Level seeding failed', e)
|
||||||
await self._message_service.send_channel_message(channel, self._t.transform('modules.level.seeding_failed'))
|
await self._message_service.send_channel_message(channel, self._t.transform('modules.level.seeding_failed'))
|
||||||
|
|
||||||
async def _level_auto_complete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
|
||||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
|
||||||
levels = self._levels.get_levels_by_server_id(server.server_id).select(lambda l: l.name)
|
|
||||||
return [app_commands.Choice(name=level, value=level) for level in self._client_utils.get_auto_complete_list(levels, current)]
|
|
||||||
|
|
||||||
@commands.hybrid_group()
|
@commands.hybrid_group()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def level(self, ctx: Context):
|
async def level(self, ctx: Context):
|
||||||
@ -245,7 +240,9 @@ class LevelGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
@edit.autocomplete('level')
|
@edit.autocomplete('level')
|
||||||
async def edit_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def edit_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
return await self._level_auto_complete(interaction, current)
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
|
levels = self._levels.get_levels_by_server_id(server.server_id).select(lambda l: l.name)
|
||||||
|
return [app_commands.Choice(name=level, value=level) for level in levels]
|
||||||
|
|
||||||
@edit.autocomplete('color')
|
@edit.autocomplete('color')
|
||||||
async def edit_color_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def edit_color_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
@ -286,7 +283,9 @@ class LevelGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
@remove.autocomplete('level')
|
@remove.autocomplete('level')
|
||||||
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
return await self._level_auto_complete(interaction, current)
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
|
levels = self._levels.get_levels_by_server_id(server.server_id).select(lambda l: l.name)
|
||||||
|
return [app_commands.Choice(name=level, value=level) for level in levels]
|
||||||
|
|
||||||
@level.command()
|
@level.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -393,4 +392,6 @@ class LevelGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
@set.autocomplete('level')
|
@set.autocomplete('level')
|
||||||
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
return await self._level_auto_complete(interaction, current)
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
|
levels = self._levels.get_levels_by_server_id(server.server_id).select(lambda l: l.name)
|
||||||
|
return [app_commands.Choice(name=level, value=level) for level in levels]
|
||||||
|
Loading…
Reference in New Issue
Block a user