1
0
Fork 0
mirror of https://code.lenaisten.de/Lenaisten/lenaverse-bot.git synced 2024-11-22 15:03: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): class LenaverseBot(discord.Client):
def __init__(self) -> None: def __init__(self) -> None:
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True
super().__init__(intents=intents) super().__init__(intents=intents)

View file

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

View file

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