2024-03-18 17:48:12 +00:00
|
|
|
import asyncio
|
2024-07-14 00:39:48 +00:00
|
|
|
from typing import Optional, Dict
|
2024-03-18 17:48:12 +00:00
|
|
|
|
|
|
|
import discord
|
2024-07-08 17:22:17 +00:00
|
|
|
from discord.ext import bridge
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
from lib.constants import CONST
|
|
|
|
from lib.embed_builder import EmbedBuilder
|
2024-07-08 17:22:17 +00:00
|
|
|
from lib.interactions.introduction import (
|
|
|
|
IntroductionStartButtons,
|
|
|
|
IntroductionFinishButtons,
|
|
|
|
)
|
2024-03-18 17:48:12 +00:00
|
|
|
|
|
|
|
|
2024-07-08 17:22:17 +00:00
|
|
|
async def cmd(self, ctx: bridge.Context) -> None:
|
2024-07-13 18:51:43 +00:00
|
|
|
guild: Optional[discord.Guild] = self.client.get_guild(CONST.KRC_GUILD_ID)
|
2024-07-14 00:39:48 +00:00
|
|
|
member: Optional[discord.Member] = (
|
|
|
|
guild.get_member(ctx.author.id) if guild else None
|
|
|
|
)
|
2024-07-13 18:51:43 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
if not guild or not member:
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.respond(
|
|
|
|
embed=EmbedBuilder.create_error_embed(
|
|
|
|
ctx,
|
|
|
|
author_text=CONST.STRINGS["intro_no_guild_author"],
|
|
|
|
description=CONST.STRINGS["intro_no_guild"],
|
|
|
|
footer_text=CONST.STRINGS["intro_service_name"],
|
|
|
|
)
|
|
|
|
)
|
2024-07-08 17:22:17 +00:00
|
|
|
return
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
question_mapping: Dict[str, str] = CONST.KRC_QUESTION_MAPPING
|
2024-07-13 18:51:43 +00:00
|
|
|
channel: Optional[discord.abc.GuildChannel] = guild.get_channel(
|
|
|
|
CONST.KRC_INTRO_CHANNEL_ID
|
|
|
|
)
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
if not channel or isinstance(
|
|
|
|
channel, (discord.ForumChannel, discord.CategoryChannel)
|
2024-07-13 18:51:43 +00:00
|
|
|
):
|
|
|
|
await ctx.respond(
|
|
|
|
embed=EmbedBuilder.create_error_embed(
|
|
|
|
ctx,
|
|
|
|
author_text=CONST.STRINGS["intro_no_channel_author"],
|
|
|
|
description=CONST.STRINGS["intro_no_channel"],
|
|
|
|
footer_text=CONST.STRINGS["intro_service_name"],
|
|
|
|
)
|
|
|
|
)
|
2024-07-08 17:22:17 +00:00
|
|
|
return
|
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
view: IntroductionStartButtons | IntroductionFinishButtons = (
|
|
|
|
IntroductionStartButtons(ctx)
|
|
|
|
)
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.respond(
|
|
|
|
embed=EmbedBuilder.create_embed(
|
|
|
|
ctx,
|
|
|
|
author_text=CONST.STRINGS["intro_service_name"],
|
|
|
|
description=CONST.STRINGS["intro_start"].format(channel.mention),
|
|
|
|
footer_text=CONST.STRINGS["intro_start_footer"],
|
|
|
|
),
|
|
|
|
view=view,
|
|
|
|
)
|
2024-03-18 17:48:12 +00:00
|
|
|
await view.wait()
|
|
|
|
|
2024-03-25 14:48:00 +00:00
|
|
|
if view.clickedStop:
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.send(
|
2024-07-14 00:23:30 +00:00
|
|
|
embed=EmbedBuilder.create_error_embed(
|
2024-07-13 18:51:43 +00:00
|
|
|
ctx,
|
|
|
|
author_text=CONST.STRINGS["intro_stopped_author"],
|
|
|
|
description=CONST.STRINGS["intro_stopped"],
|
2024-07-14 00:23:30 +00:00
|
|
|
footer_text=CONST.STRINGS["intro_service_name"],
|
2024-07-13 18:51:43 +00:00
|
|
|
)
|
|
|
|
)
|
2024-07-08 17:22:17 +00:00
|
|
|
return
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
if view.clickedStart:
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-08 17:22:17 +00:00
|
|
|
def check(message: discord.Message) -> bool:
|
|
|
|
return message.author == ctx.author and isinstance(
|
|
|
|
message.channel, discord.DMChannel
|
|
|
|
)
|
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
answer_mapping: Dict[str, str] = {}
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-03-25 14:48:00 +00:00
|
|
|
for key, question in question_mapping.items():
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.send(
|
|
|
|
embed=EmbedBuilder.create_embed(
|
|
|
|
ctx,
|
|
|
|
author_text=key,
|
|
|
|
description=question,
|
|
|
|
footer_text=CONST.STRINGS["intro_question_footer"],
|
|
|
|
)
|
|
|
|
)
|
2024-03-18 17:48:12 +00:00
|
|
|
|
|
|
|
try:
|
2024-07-08 17:22:17 +00:00
|
|
|
answer: discord.Message = await self.client.wait_for(
|
|
|
|
"message", check=check, timeout=120
|
|
|
|
)
|
2024-07-14 00:39:48 +00:00
|
|
|
answer_content: str = answer.content.replace("\n", " ")
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
if len(answer_content) > 200:
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.send(
|
|
|
|
embed=EmbedBuilder.create_error_embed(
|
|
|
|
ctx,
|
|
|
|
author_text=CONST.STRINGS["intro_too_long_author"],
|
|
|
|
description=CONST.STRINGS["intro_too_long"],
|
|
|
|
footer_text=CONST.STRINGS["intro_service_name"],
|
|
|
|
)
|
|
|
|
)
|
2024-07-08 17:22:17 +00:00
|
|
|
return
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
answer_mapping[key] = answer_content
|
|
|
|
|
2024-03-18 17:48:12 +00:00
|
|
|
except asyncio.TimeoutError:
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.send(
|
|
|
|
embed=EmbedBuilder.create_error_embed(
|
|
|
|
ctx,
|
|
|
|
author_text=CONST.STRINGS["intro_timeout_author"],
|
|
|
|
description=CONST.STRINGS["intro_timeout"],
|
|
|
|
footer_text=CONST.STRINGS["intro_service_name"],
|
|
|
|
)
|
|
|
|
)
|
2024-07-08 17:22:17 +00:00
|
|
|
return
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
description: str = "".join(
|
|
|
|
CONST.STRINGS["intro_preview_field"].format(key, value)
|
|
|
|
for key, value in answer_mapping.items()
|
|
|
|
)
|
2024-07-13 18:51:43 +00:00
|
|
|
|
2024-07-14 00:39:48 +00:00
|
|
|
preview: discord.Embed = EmbedBuilder.create_embed(
|
2024-07-13 18:51:43 +00:00
|
|
|
ctx,
|
|
|
|
author_text=ctx.author.name,
|
|
|
|
author_icon_url=ctx.author.display_avatar.url,
|
|
|
|
description=description,
|
|
|
|
footer_text=CONST.STRINGS["intro_service_name"],
|
|
|
|
)
|
2024-07-08 17:22:17 +00:00
|
|
|
view = IntroductionFinishButtons(ctx)
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-03-25 14:48:00 +00:00
|
|
|
await ctx.send(embed=preview, view=view)
|
|
|
|
await view.wait()
|
2024-03-18 17:48:12 +00:00
|
|
|
|
2024-03-25 14:48:00 +00:00
|
|
|
if view.clickedConfirm:
|
2024-07-08 17:22:17 +00:00
|
|
|
await channel.send(
|
2024-07-14 00:39:48 +00:00
|
|
|
embed=preview,
|
|
|
|
content=CONST.STRINGS["intro_content"].format(ctx.author.mention),
|
2024-07-08 17:22:17 +00:00
|
|
|
)
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.send(
|
|
|
|
embed=EmbedBuilder.create_embed(
|
|
|
|
ctx,
|
|
|
|
description=CONST.STRINGS["intro_post_confirmation"].format(
|
|
|
|
channel.mention
|
|
|
|
),
|
|
|
|
)
|
2024-07-08 17:22:17 +00:00
|
|
|
)
|
2024-03-25 14:48:00 +00:00
|
|
|
else:
|
2024-07-13 18:51:43 +00:00
|
|
|
await ctx.send(
|
2024-07-14 00:23:30 +00:00
|
|
|
embed=EmbedBuilder.create_error_embed(
|
2024-07-13 18:51:43 +00:00
|
|
|
ctx,
|
|
|
|
author_text=CONST.STRINGS["intro_stopped_author"],
|
|
|
|
description=CONST.STRINGS["intro_stopped"],
|
2024-07-14 00:23:30 +00:00
|
|
|
footer_text=CONST.STRINGS["intro_service_name"],
|
2024-07-13 18:51:43 +00:00
|
|
|
)
|
|
|
|
)
|