|
2 | 2 | Módulo para funciones auxiliares |
3 | 3 | """ |
4 | 4 |
|
5 | | -from typing import Optional |
| 5 | +from typing import TYPE_CHECKING |
6 | 6 |
|
7 | | -from discord import Embed, Message |
8 | | -from discord.ext.commands import Bot, Context |
9 | | -from discord.ui import View |
| 7 | +from discord import Interaction, Message, Thread |
| 8 | +from discord.app_commands import check as appcheck |
10 | 9 |
|
11 | 10 | from ..archivos import cargar_json |
12 | 11 | from ..constantes import (ALGORITMOS_ESSAYA_ID, DEFAULT_PREFIX, |
13 | 12 | PROPERTIES_PATH, ROL_DIEGO_ID, ROL_DOCENTE_ID) |
14 | 13 |
|
| 14 | +if TYPE_CHECKING: |
15 | 15 |
|
16 | | -def es_rol_valido(ctx: Context) -> bool: |
| 16 | + from ..lector import Lector |
| 17 | + |
| 18 | + |
| 19 | +def es_rol_valido(): |
17 | 20 | """ |
18 | 21 | Verifica si está en el servidor del curso, y si es así, |
19 | 22 | si se tienen los roles correspondientes. |
20 | 23 | """ |
21 | 24 |
|
22 | | - return not all((ctx.guild.id == ALGORITMOS_ESSAYA_ID, |
23 | | - all([role.id not in (ROL_DIEGO_ID, ROL_DOCENTE_ID) for role in ctx.author.roles]))) |
| 25 | + def predicado(interaction: Interaction) -> bool: |
| 26 | + """ |
| 27 | + Crea el check correspondiente. |
| 28 | + """ |
| 29 | + |
| 30 | + return not all((interaction.guild.id == ALGORITMOS_ESSAYA_ID, |
| 31 | + all([role.id not in (ROL_DIEGO_ID, ROL_DOCENTE_ID) |
| 32 | + for role in interaction.user.roles]))) |
| 33 | + |
| 34 | + return appcheck(predicado) |
| 35 | + |
| 36 | + |
| 37 | +def es_hilo(): |
| 38 | + """ |
| 39 | + Verifica si la interacción ocurrió en un hilo. |
| 40 | + """ |
| 41 | + |
| 42 | + def predicado(interaction: Interaction) -> bool: |
| 43 | + """ |
| 44 | + Crea el check correspondiente. |
| 45 | + """ |
| 46 | + |
| 47 | + return isinstance(interaction.channel, Thread) |
| 48 | + |
| 49 | + return appcheck(predicado) |
24 | 50 |
|
25 | 51 |
|
26 | | -async def mandar_dm(ctx: Context, |
27 | | - contenido: Optional[str]=None, |
28 | | - vista: Optional[View]=None, |
29 | | - embed: Optional[Embed]=None) -> None: |
| 52 | +def get_prefijo_por_id(guild_id: int) -> str: |
30 | 53 | """ |
31 | | - Manda un mensaje por privado. |
| 54 | + Devuelve el prefijo de invocación de comandos dependiendo |
| 55 | + del guild donde se esté. |
32 | 56 | """ |
33 | 57 |
|
34 | | - await ctx.author.create_dm() |
35 | | - mensaje_enviado = await ctx.author.dm_channel.send(content=contenido, view=vista, embed=embed) |
36 | | - vista.msg = mensaje_enviado |
37 | | - await ctx.message.delete() |
| 58 | + return cargar_json(PROPERTIES_PATH)["prefijos"].get(str(guild_id), DEFAULT_PREFIX) |
38 | 59 |
|
39 | 60 |
|
40 | | -def get_prefijo(_bot: Bot, mensaje: Message) -> str: |
| 61 | +def get_prefijo(_bot: "Lector", mensaje: Message) -> str: |
41 | 62 | """ |
42 | 63 | Se fija en el diccionario de prefijos y devuelve el que |
43 | 64 | corresponda al servidor de donde se convoca el comando. |
44 | 65 | """ |
45 | 66 |
|
46 | | - return cargar_json(PROPERTIES_PATH)["prefijos"].get(str(mensaje.guild.id), DEFAULT_PREFIX) |
| 67 | + return get_prefijo_por_id(mensaje.guild.id) |
0 commit comments