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

minimum scope for bot

This commit is contained in:
Jörn-Michael Miehe 2023-11-19 19:36:29 +01:00
parent 3bc24d45af
commit ec01447440
3 changed files with 11 additions and 34 deletions

View file

@ -11,7 +11,6 @@ _logger = logging.getLogger(__name__)
class LenaverseBot(discord.Client):
def __init__(self) -> None:
intents = discord.Intents.default()
intents.message_content = True
super().__init__(intents=intents)

View file

@ -1,4 +1,3 @@
import logging
import os
import tomllib
from typing import Self
@ -6,44 +5,23 @@ from typing import Self
import discord
from pydantic import BaseModel
_logger = logging.getLogger(__name__)
class Post(BaseModel):
channel: int
users: list[int]
class PostTarget(BaseModel):
server: str
channel: str
thread: str
def get(self, client: discord.Client) -> discord.Thread:
def get_channel(
self,
client: discord.Client,
) -> discord.Thread | discord.TextChannel:
"""
Zielkanal für Posts finden
"""
guilds = [guild for guild in client.guilds if guild.name == self.server]
_logger.debug(f"Guilds: {[guild.name for guild in guilds]}")
assert len(guilds) == 1
channel = client.get_channel(self.channel)
assert isinstance(channel, discord.Thread | discord.TextChannel)
channels = [
channel
for channel in guilds[0].channels
if isinstance(channel, discord.TextChannel | discord.ForumChannel)
and channel.name == self.channel
]
_logger.debug(f"channels: {[channel.name for channel in channels]}")
assert len(channels) == 1
threads = [
thread for thread in channels[0].threads if thread.name == self.thread
]
_logger.debug(f"threads: {[thread.name for thread in threads]}")
assert len(threads) == 1
return threads[0]
class Post(BaseModel):
target: PostTarget
users: list[int]
return channel
class Config(BaseModel):

View file

@ -75,7 +75,7 @@ class PostModal(ui.Modal, title="Post verfassen"):
_logger.info(
f"User {interaction.user.name}({interaction.user.id}) published a /post"
)
target = CONFIG.post.target.get(interaction.client)
target = CONFIG.post.get_channel(interaction.client)
await target.send(post_content)
elif view.action is Action.ABORT: