1
0
Fork 0
mirror of https://code.lenaisten.de/Lenaisten/lenaverse-bot.git synced 2024-11-21 22:43:01 +00:00

/post command add author and logging

This commit is contained in:
Jörn-Michael Miehe 2023-11-19 17:58:38 +01:00
parent b11c39da18
commit 6f0c6d8f66

View file

@ -1,3 +1,4 @@
import logging
from enum import Enum, auto
import discord
@ -5,6 +6,8 @@ from discord import ui
from .config import CONFIG
_logger = logging.getLogger(__name__)
class Action(Enum):
"""
@ -54,9 +57,11 @@ class PostModal(ui.Modal, title="Post verfassen"):
)
async def on_submit(self, interaction: discord.Interaction):
post_content = f"{self.content.value}\n> Gepostet von <@{interaction.user.id}>"
await interaction.response.send_message(
# Vorschau mit Buttons
content=f"## Post-Vorschau\n\n{self.content.value}",
content=f"## Post-Vorschau\n\n{post_content}",
view=(view := PostConfirm()),
# nur für ausführenden User
ephemeral=True,
@ -67,8 +72,21 @@ class PostModal(ui.Modal, title="Post verfassen"):
if view.action is Action.PUBLISH:
# Post veröffentlichen
_logger.info(
f"User {interaction.user.name}({interaction.user.id}) finished a /post"
)
target = CONFIG.post.target.get(interaction.client)
await target.send(self.content.value)
await target.send(post_content)
elif view.action is Action.ABORT:
_logger.info(
f"User {interaction.user.name}({interaction.user.id}) aborted a /post"
)
elif view.action is Action.TIMEOUT:
_logger.info(
f"User {interaction.user.name}({interaction.user.id}) timeout during /post"
)
@discord.app_commands.command()
@ -79,9 +97,15 @@ async def post(interaction: discord.Interaction):
if interaction.user.id in CONFIG.post.users:
# Verfassen-Dialog anzeigen
_logger.info(
f"User {interaction.user.name}({interaction.user.id}) started a /post"
)
await interaction.response.send_modal(PostModal())
else:
_logger.warning(
f"User {interaction.user.name}({interaction.user.id}) tried to /post"
)
await interaction.response.send_message(
# Zugriff verweigern
content="Du bist nicht berechtigt, den `/post`-Befehl zu benutzen!",