From cd4effda1ebddaa992348bdbe95ead4bb8d88f8a Mon Sep 17 00:00:00 2001 From: Bene Date: Wed, 9 Apr 2025 22:09:10 +0200 Subject: [PATCH] added list of channelnames --- Dockerfile | 5 +++++ bot.py | 35 +++++++++++++++++++++++++++++++++-- channelnames.json | 18 ++++++++++++++++++ docker-compose.yml | 2 -- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 channelnames.json diff --git a/Dockerfile b/Dockerfile index 0fefda2..1cb2a19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,14 @@ WORKDIR /app # Copy the requirements.txt and the script to the container COPY requirements.txt . COPY bot.py . +COPY channelnames.json config/ + +# Create necessary directories +RUN mkdir -p data # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # Run the bot CMD ["python", "bot.py"] + diff --git a/bot.py b/bot.py index 1c146a3..aabdf96 100644 --- a/bot.py +++ b/bot.py @@ -1,7 +1,31 @@ import os +import json import discord +import random # hinzugefügt from discord.ext import commands +DATA_FILE = "data/channel_data.json" + +# Lade Trick-Namen aus der JSON-Datei im config-Ordner +try: + with open(os.path.join(os.path.dirname(__file__), "config", "channelnames.json"), "r") as f: + TRICK_NAMES = json.load(f) +except FileNotFoundError: + TRICK_NAMES = ["Default Trick"] + +def load_created_channels(): + try: + with open(DATA_FILE, "r") as f: + data = json.load(f) + return set(data.get("created_channels", [])) + except FileNotFoundError: + return set() + +def save_created_channels(channels: set): + os.makedirs(os.path.dirname(DATA_FILE), exist_ok=True) + with open(DATA_FILE, "w") as f: + json.dump({"created_channels": list(channels)}, f) + intents = discord.Intents.default() intents.guilds = True intents.voice_states = True @@ -11,6 +35,8 @@ bot = commands.Bot(command_prefix='!', intents=intents) token = os.getenv('BOT_TOKEN') join_to_create_channel_id = int(os.getenv('JOINTOCREATE_CHANNEL_ID')) +created_channels = load_created_channels() + @bot.event async def on_ready(): print('Ready!') @@ -18,15 +44,20 @@ async def on_ready(): @bot.event async def on_voice_state_update(member, before, after): if after.channel and after.channel.id == join_to_create_channel_id: + trick_name = random.choice(TRICK_NAMES) # zufälliger Trick-Name new_channel = await after.channel.guild.create_voice_channel( - name=f"🔊 {member.display_name}'s Channel", + name=f"🔊 {trick_name}", category=after.channel.category, reason='Created by JoinToCreate bot' ) + created_channels.add(new_channel.id) + save_created_channels(created_channels) await member.move_to(new_channel) if before.channel and len(before.channel.members) == 0 and before.channel.id != join_to_create_channel_id: - if before.channel.name.startswith('🔊'): + if before.channel.id in created_channels: await before.channel.delete(reason='No members left in the bot-created channel') + created_channels.remove(before.channel.id) + save_created_channels(created_channels) bot.run(token) diff --git a/channelnames.json b/channelnames.json new file mode 100644 index 0000000..14188e4 --- /dev/null +++ b/channelnames.json @@ -0,0 +1,18 @@ +[ + "Barrel Roll", + "Split-S", + "Inverted Flip", + "Power Loop", + "Torque Roll", + "Double Flip", + "Side Barrel", + "Forward Flip", + "Reverse Flip", + "Vortex", + "Rapid Roll", + "Snap Roll", + "Tail Slide", + "Immelmann", + "Bahrani", + "Matty" +] diff --git a/docker-compose.yml b/docker-compose.yml index 619760d..213ef8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: discord-bot: image: git.degnedict.de/bene/join2create:latest