Compare commits
2 commits
876d8fe20a
...
f64cfbf1c0
Author | SHA1 | Date | |
---|---|---|---|
f64cfbf1c0 | |||
64cb7bd5a9 |
6 changed files with 135 additions and 52 deletions
31
lenaverse_bot/core/_helpers.py
Normal file
31
lenaverse_bot/core/_helpers.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from pathlib import Path
|
||||
|
||||
import discord
|
||||
from discord.app_commands import locale_str
|
||||
from discord.utils import MISSING
|
||||
|
||||
from lenaverse_bot import __file__ as module_file
|
||||
|
||||
from .config import CONFIG
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def ev_command(
|
||||
name: str,
|
||||
description: str | locale_str = MISSING,
|
||||
):
|
||||
return discord.app_commands.command(
|
||||
name=CONFIG.command_prefix + name,
|
||||
description=description,
|
||||
)
|
|
@ -3,7 +3,6 @@ import logging
|
|||
import discord
|
||||
|
||||
from . import post, verein
|
||||
from .commands import lsstuff
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -13,8 +12,6 @@ class LenaverseBot(discord.Client):
|
|||
super().__init__(intents=discord.Intents.default())
|
||||
|
||||
self.tree = discord.app_commands.CommandTree(self)
|
||||
self.tree.add_command(lsstuff)
|
||||
|
||||
commands = post.COMMANDS + verein.COMMANDS
|
||||
for command in commands:
|
||||
self.tree.add_command(command)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import discord
|
||||
|
||||
|
||||
@discord.app_commands.command()
|
||||
async def lsstuff(interaction: discord.Interaction):
|
||||
msg = ""
|
||||
for guild in interaction.client.guilds:
|
||||
msg += f"\n- {guild.name}"
|
||||
for channel in guild.channels:
|
||||
msg += f"\n - {channel.name}"
|
||||
|
||||
if isinstance(channel, discord.ForumChannel | discord.TextChannel):
|
||||
for thread in channel.threads:
|
||||
msg += f"\n - {thread.name}"
|
||||
|
||||
await interaction.response.send_message(msg, ephemeral=True)
|
|
@ -1,9 +1,11 @@
|
|||
import os
|
||||
import tomllib
|
||||
from typing import Self
|
||||
from typing import Annotated, Self
|
||||
|
||||
import discord
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, StringConstraints
|
||||
|
||||
StrippedStr = Annotated[str, StringConstraints(strip_whitespace=True)]
|
||||
|
||||
|
||||
class Post(BaseModel):
|
||||
|
@ -26,14 +28,29 @@ class Post(BaseModel):
|
|||
return channel
|
||||
|
||||
|
||||
class InfoCommand(BaseModel):
|
||||
description: StrippedStr = "..."
|
||||
content: StrippedStr = ""
|
||||
|
||||
|
||||
class FileCommand(InfoCommand):
|
||||
filename: str = ""
|
||||
|
||||
|
||||
class ClubInfo(BaseModel):
|
||||
linktree: str = ""
|
||||
join_file: str = "Aufnahmeantrag.pdf"
|
||||
join_message: str = ""
|
||||
channels: list[int]
|
||||
|
||||
info: InfoCommand
|
||||
linktree: InfoCommand
|
||||
join: FileCommand
|
||||
fest: InfoCommand
|
||||
aktion: InfoCommand
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
discord_token: str
|
||||
command_prefix: str
|
||||
|
||||
post: Post
|
||||
ev_info: ClubInfo
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from enum import Enum, auto
|
|||
import discord
|
||||
from discord import ui
|
||||
|
||||
from ._helpers import ev_command
|
||||
from .config import CONFIG
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
@ -92,8 +93,8 @@ class PostModal(ui.Modal, title="Post verfassen"):
|
|||
)
|
||||
|
||||
|
||||
@discord.app_commands.command()
|
||||
async def ev_post(interaction: discord.Interaction) -> None:
|
||||
@ev_command(name="post")
|
||||
async def post(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Einen Post im Lenaisten-Bereich verfassen (nur für ausgewählte Mitglieder verfügbar)
|
||||
"""
|
||||
|
@ -118,5 +119,5 @@ async def ev_post(interaction: discord.Interaction) -> None:
|
|||
|
||||
|
||||
COMMANDS = [
|
||||
ev_post,
|
||||
post,
|
||||
]
|
||||
|
|
|
@ -1,46 +1,99 @@
|
|||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import discord
|
||||
|
||||
from lenaverse_bot import __file__ as module_file
|
||||
|
||||
from ._helpers import ev_command, get_files_path
|
||||
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
|
||||
def reply_private(interaction: discord.Interaction, name: str) -> bool:
|
||||
_logger.debug(f"User {interaction.user.name}({interaction.user.id}) used /{name}")
|
||||
return interaction.channel_id not in CONFIG.ev_info.channels
|
||||
|
||||
|
||||
@discord.app_commands.command()
|
||||
async def ev_linktree(interaction: discord.Interaction) -> None:
|
||||
_logger.debug(f"User {interaction.user.name}({interaction.user.id}) used /linktree")
|
||||
@ev_command(
|
||||
name="info",
|
||||
description=CONFIG.ev_info.info.description,
|
||||
)
|
||||
async def info(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Allgemeine Infos zum Verein
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.linktree.strip(),
|
||||
suppress_embeds=True,
|
||||
content=CONFIG.ev_info.info.content,
|
||||
ephemeral=reply_private(interaction, "info"),
|
||||
)
|
||||
|
||||
|
||||
@discord.app_commands.command()
|
||||
async def ev_join(interaction: discord.Interaction) -> None:
|
||||
_logger.debug(f"User {interaction.user.name}({interaction.user.id}) used /join")
|
||||
@ev_command(
|
||||
name="linktree",
|
||||
description=CONFIG.ev_info.linktree.description,
|
||||
)
|
||||
async def linktree(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Links rund um den Verein
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.join_message.strip(),
|
||||
file=discord.File(get_files_path() / CONFIG.ev_info.join_file),
|
||||
content=CONFIG.ev_info.linktree.content,
|
||||
suppress_embeds=True,
|
||||
ephemeral=reply_private(interaction, "linktree"),
|
||||
)
|
||||
|
||||
|
||||
@ev_command(
|
||||
name="join",
|
||||
description=CONFIG.ev_info.join.description,
|
||||
)
|
||||
async def join(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Wie und warum dem Verein beitreten
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.join.content,
|
||||
file=discord.File(get_files_path() / CONFIG.ev_info.join.filename),
|
||||
ephemeral=reply_private(interaction, "join"),
|
||||
)
|
||||
|
||||
|
||||
@ev_command(
|
||||
name="fest",
|
||||
description=CONFIG.ev_info.fest.description,
|
||||
)
|
||||
async def fest(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Infos zum nächsten Vereinsfest
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.fest.content,
|
||||
ephemeral=reply_private(interaction, "fest"),
|
||||
)
|
||||
|
||||
|
||||
@ev_command(
|
||||
name="aktion",
|
||||
description=CONFIG.ev_info.aktion.description,
|
||||
)
|
||||
async def aktion(interaction: discord.Interaction) -> None:
|
||||
"""
|
||||
Infos zu aktuellen Aktionen
|
||||
"""
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=CONFIG.ev_info.aktion.content,
|
||||
ephemeral=reply_private(interaction, "aktion"),
|
||||
)
|
||||
|
||||
|
||||
COMMANDS = [
|
||||
ev_linktree,
|
||||
ev_join,
|
||||
info,
|
||||
linktree,
|
||||
join,
|
||||
fest,
|
||||
aktion,
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue