added list of channelnames

This commit is contained in:
2025-04-09 22:09:10 +02:00
parent 954d0b329d
commit cd4effda1e
4 changed files with 56 additions and 4 deletions

View File

@@ -6,9 +6,14 @@ WORKDIR /app
# Copy the requirements.txt and the script to the container # Copy the requirements.txt and the script to the container
COPY requirements.txt . COPY requirements.txt .
COPY bot.py . COPY bot.py .
COPY channelnames.json config/
# Create necessary directories
RUN mkdir -p data
# Install dependencies # Install dependencies
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Run the bot # Run the bot
CMD ["python", "bot.py"] CMD ["python", "bot.py"]

35
bot.py
View File

@@ -1,7 +1,31 @@
import os import os
import json
import discord import discord
import random # hinzugefügt
from discord.ext import commands 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 = discord.Intents.default()
intents.guilds = True intents.guilds = True
intents.voice_states = True intents.voice_states = True
@@ -11,6 +35,8 @@ bot = commands.Bot(command_prefix='!', intents=intents)
token = os.getenv('BOT_TOKEN') token = os.getenv('BOT_TOKEN')
join_to_create_channel_id = int(os.getenv('JOINTOCREATE_CHANNEL_ID')) join_to_create_channel_id = int(os.getenv('JOINTOCREATE_CHANNEL_ID'))
created_channels = load_created_channels()
@bot.event @bot.event
async def on_ready(): async def on_ready():
print('Ready!') print('Ready!')
@@ -18,15 +44,20 @@ async def on_ready():
@bot.event @bot.event
async def on_voice_state_update(member, before, after): async def on_voice_state_update(member, before, after):
if after.channel and after.channel.id == join_to_create_channel_id: 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( new_channel = await after.channel.guild.create_voice_channel(
name=f"🔊 {member.display_name}'s Channel", name=f"🔊 {trick_name}",
category=after.channel.category, category=after.channel.category,
reason='Created by JoinToCreate bot' reason='Created by JoinToCreate bot'
) )
created_channels.add(new_channel.id)
save_created_channels(created_channels)
await member.move_to(new_channel) 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 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') 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) bot.run(token)

18
channelnames.json Normal file
View File

@@ -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"
]

View File

@@ -1,5 +1,3 @@
version: '3.8'
services: services:
discord-bot: discord-bot:
image: git.degnedict.de/bene/join2create:latest image: git.degnedict.de/bene/join2create:latest