1
0
Fork 0
mirror of https://code.lenaisten.de/Lenaisten/lenaverse-bot.git synced 2024-11-25 08:13:00 +00:00

add /join and /linktree commands

This commit is contained in:
Jörn-Michael Miehe 2023-11-20 00:26:23 +01:00
parent 59ce255fda
commit 26a48cce46
5 changed files with 55 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import discord
from .commands import lsstuff from .commands import lsstuff
from .post import ev_post from .post import ev_post
from .verein import ev_join, ev_linktree
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -14,6 +15,8 @@ class LenaverseBot(discord.Client):
self.tree = discord.app_commands.CommandTree(self) self.tree = discord.app_commands.CommandTree(self)
self.tree.add_command(ev_post) self.tree.add_command(ev_post)
self.tree.add_command(ev_join)
self.tree.add_command(ev_linktree)
self.tree.add_command(lsstuff) self.tree.add_command(lsstuff)
async def setup_hook(self): async def setup_hook(self):

View file

@ -7,8 +7,10 @@ from pydantic import BaseModel
class Post(BaseModel): class Post(BaseModel):
channel: int # users authorized to posts
users: list[int] users: list[int]
# where to put posts
channel: int
def get_channel( def get_channel(
self, self,
@ -24,9 +26,16 @@ class Post(BaseModel):
return channel return channel
class ClubInfo(BaseModel):
linktree: str = ""
join_file: str = "Aufnahmeantrag.pdf"
join_message: str = ""
class Config(BaseModel): class Config(BaseModel):
discord_token: str discord_token: str
post: Post post: Post
ev_info: ClubInfo
@classmethod @classmethod
def get(cls) -> Self: def get(cls) -> Self:

View file

@ -106,7 +106,7 @@ async def ev_post(interaction: discord.Interaction) -> None:
else: else:
# Zugriff verweigern # Zugriff verweigern
_logger.warning( _logger.info(
f"User {interaction.user.name}({interaction.user.id}) tried to /post" f"User {interaction.user.name}({interaction.user.id}) tried to /post"
) )
await interaction.response.send_message( await interaction.response.send_message(

View file

@ -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),
)

View file

@ -1,6 +1,7 @@
[tool.poetry] [tool.poetry]
authors = ["Jörn-Michael Miehe <joern-michael.miehe@lenaisten.de>"] authors = ["Jörn-Michael Miehe <joern-michael.miehe@lenaisten.de>"]
description = "" description = ""
include = ["lenaverse_bot/files/*"]
name = "lenaverse_bot" name = "lenaverse_bot"
readme = "README.md" readme = "README.md"
version = "0.1.0" version = "0.1.0"