From 26a48cce465e00982414c3fdfca771162526b6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 20 Nov 2023 00:26:23 +0100 Subject: [PATCH] add /join and /linktree commands --- lenaverse_bot/core/bot.py | 3 +++ lenaverse_bot/core/config.py | 11 +++++++++- lenaverse_bot/core/post.py | 2 +- lenaverse_bot/core/verein.py | 40 ++++++++++++++++++++++++++++++++++++ pyproject.toml | 1 + 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 lenaverse_bot/core/verein.py diff --git a/lenaverse_bot/core/bot.py b/lenaverse_bot/core/bot.py index bfdb585..3b6385a 100644 --- a/lenaverse_bot/core/bot.py +++ b/lenaverse_bot/core/bot.py @@ -4,6 +4,7 @@ import discord from .commands import lsstuff from .post import ev_post +from .verein import ev_join, ev_linktree _logger = logging.getLogger(__name__) @@ -14,6 +15,8 @@ class LenaverseBot(discord.Client): self.tree = discord.app_commands.CommandTree(self) self.tree.add_command(ev_post) + self.tree.add_command(ev_join) + self.tree.add_command(ev_linktree) self.tree.add_command(lsstuff) async def setup_hook(self): diff --git a/lenaverse_bot/core/config.py b/lenaverse_bot/core/config.py index 2c32d46..6d0058c 100644 --- a/lenaverse_bot/core/config.py +++ b/lenaverse_bot/core/config.py @@ -7,8 +7,10 @@ from pydantic import BaseModel class Post(BaseModel): - channel: int + # users authorized to posts users: list[int] + # where to put posts + channel: int def get_channel( self, @@ -24,9 +26,16 @@ class Post(BaseModel): return channel +class ClubInfo(BaseModel): + linktree: str = "" + join_file: str = "Aufnahmeantrag.pdf" + join_message: str = "" + + class Config(BaseModel): discord_token: str post: Post + ev_info: ClubInfo @classmethod def get(cls) -> Self: diff --git a/lenaverse_bot/core/post.py b/lenaverse_bot/core/post.py index 5c7b390..fd532aa 100644 --- a/lenaverse_bot/core/post.py +++ b/lenaverse_bot/core/post.py @@ -106,7 +106,7 @@ async def ev_post(interaction: discord.Interaction) -> None: else: # Zugriff verweigern - _logger.warning( + _logger.info( f"User {interaction.user.name}({interaction.user.id}) tried to /post" ) await interaction.response.send_message( diff --git a/lenaverse_bot/core/verein.py b/lenaverse_bot/core/verein.py new file mode 100644 index 0000000..ad8d472 --- /dev/null +++ b/lenaverse_bot/core/verein.py @@ -0,0 +1,40 @@ +import logging +from pathlib import Path + +import discord + +from lenaverse_bot import __file__ as module_file + +from .config import CONFIG + +_logger = logging.getLogger(__name__) + + +def get_files_path() -> Path: + module_path = Path(module_file) + + if module_path.is_file(): + module_path = module_path.parent + + result = module_path / "files" + assert result.is_dir() + + return result + + +@discord.app_commands.command() +async def ev_linktree(interaction: discord.Interaction) -> None: + _logger.debug(f"User {interaction.user.name}({interaction.user.id}) used /linktree") + await interaction.response.send_message( + content=CONFIG.ev_info.linktree.strip(), + suppress_embeds=True, + ) + + +@discord.app_commands.command() +async def ev_join(interaction: discord.Interaction) -> None: + _logger.debug(f"User {interaction.user.name}({interaction.user.id}) used /join") + await interaction.response.send_message( + content=CONFIG.ev_info.join_message.strip(), + file=discord.File(get_files_path() / CONFIG.ev_info.join_file), + ) diff --git a/pyproject.toml b/pyproject.toml index 88f7f8c..e2e80ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [tool.poetry] authors = ["Jörn-Michael Miehe "] description = "" +include = ["lenaverse_bot/files/*"] name = "lenaverse_bot" readme = "README.md" version = "0.1.0"