modified: bot.py

This commit is contained in:
SimolZimol
2025-08-18 09:50:06 +02:00
parent ce3d4dc9ef
commit a6b9459a0c

38
bot.py
View File

@@ -744,27 +744,27 @@ def save_chat_history(channel_id, messages):
@client.hybrid_command() @client.hybrid_command()
async def startlivechat(ctx): async def startlivechat(ctx):
"""Startet den Live-Chat im aktuellen Kanal.""" """Starts the live chat in the current channel."""
channel_id = ctx.channel.id channel_id = ctx.channel.id
if channel_id in live_chats and live_chats[channel_id]["active"]: if channel_id in live_chats and live_chats[channel_id]["active"]:
await ctx.send("Live-Chat ist bereits aktiv.") await ctx.send("Live chat is already active.")
return return
# Lade oder initialisiere die Chat-Historie # Lade oder initialisiere die Chat-Historie
history = load_chat_history(channel_id) history = load_chat_history(channel_id)
live_chats[channel_id] = {"messages": history, "active": True} live_chats[channel_id] = {"messages": history, "active": True}
await ctx.send("Live-Chat gestartet. Nachrichten werden verarbeitet.") await ctx.send("Live chat started. Messages will be processed.")
@client.hybrid_command() @client.hybrid_command()
async def stoplivechat(ctx): async def stoplivechat(ctx):
"""Beendet den Live-Chat im aktuellen Kanal.""" """Stops the live chat in the current channel."""
channel_id = ctx.channel.id channel_id = ctx.channel.id
if channel_id in live_chats: if channel_id in live_chats:
live_chats[channel_id]["active"] = False live_chats[channel_id]["active"] = False
await ctx.send("Live-Chat wurde beendet.") await ctx.send("Live chat has been stopped.")
else: else:
await ctx.send("Kein aktiver Live-Chat in diesem Kanal.") await ctx.send("No active live chat in this channel.")
@client.event @client.event
async def on_message(message): async def on_message(message):
@@ -934,12 +934,12 @@ def get_current_datetime():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S") return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def calculate_xp_needed_for_level(level): def calculate_xp_needed_for_level(level):
"""Berechnet die benötigten XP für das nächste Level.""" """Calculates the XP needed for the next level."""
xp_need = 5 * (int(level) ** 2) + 50 * int(level) + 100 xp_need = 5 * (int(level) ** 2) + 50 * int(level) + 100
return int(xp_need) return int(xp_need)
async def add_xp_to_user(user_id, guild_id, xp_gained, member=None): async def add_xp_to_user(user_id, guild_id, xp_gained, member=None):
"""Fügt einem Benutzer XP hinzu und überprüft, ob er ein Level aufsteigt. Aktualisiert auch Benutzerdaten.""" """Adds XP to a user and checks if they level up. Also updates user data."""
# Lade Benutzerdaten (XP, Level, etc.) - mit member-Objekt für neue User # Lade Benutzerdaten (XP, Level, etc.) - mit member-Objekt für neue User
user_data = await load_user_data(user_id, guild_id, member) user_data = await load_user_data(user_id, guild_id, member)
@@ -1025,7 +1025,7 @@ async def add_xp_to_user(user_id, guild_id, xp_gained, member=None):
@client.hybrid_command() @client.hybrid_command()
async def level(ctx, user: discord.User = None): async def level(ctx, user: discord.User = None):
"""Zeigt den aktuellen Level und XP des Benutzers oder einer anderen Person an.""" """Shows the current level and XP of the user or another person."""
guild_id = ctx.guild.id guild_id = ctx.guild.id
# Wenn kein User angegeben wurde, zeige das eigene Level # Wenn kein User angegeben wurde, zeige das eigene Level
@@ -1058,7 +1058,7 @@ async def level(ctx, user: discord.User = None):
@client.hybrid_command() @client.hybrid_command()
async def leaderboard(ctx): async def leaderboard(ctx):
"""Zeigt die besten Benutzer im XP-Leaderboard an.""" """Shows the top users in the XP leaderboard."""
guild_id = ctx.guild.id guild_id = ctx.guild.id
connection = connect_to_database() connection = connect_to_database()
cursor = connection.cursor() cursor = connection.cursor()
@@ -1202,7 +1202,7 @@ async def points(ctx):
@client.hybrid_command() @client.hybrid_command()
async def permissionlevel(ctx): async def permissionlevel(ctx):
"""Displays the authorisation level and rank of the user.""" """Displays the authorization level and rank of the user."""
user_id = ctx.author.id user_id = ctx.author.id
guild_id = ctx.guild.id guild_id = ctx.guild.id
@@ -1281,6 +1281,7 @@ async def resetpoints(ctx, user: discord.User):
@client.hybrid_command() @client.hybrid_command()
async def shutdown_(ctx): async def shutdown_(ctx):
"""Shuts down the bot (Admin only)."""
user_perms = load_user_data_sync(ctx.author.id, ctx.guild.id) user_perms = load_user_data_sync(ctx.author.id, ctx.guild.id)
if 8 <= user_perms["permission"]: if 8 <= user_perms["permission"]:
await ctx.send("Shutting down the bot...") await ctx.send("Shutting down the bot...")
@@ -1291,6 +1292,7 @@ async def shutdown_(ctx):
@client.hybrid_command() @client.hybrid_command()
async def owner_command(ctx): async def owner_command(ctx):
"""Syncs the bot's slash commands (Owner only)."""
try: try:
user_perms = load_user_data_sync(ctx.author.id, ctx.guild.id) user_perms = load_user_data_sync(ctx.author.id, ctx.guild.id)
if 10 <= user_perms["permission"]: if 10 <= user_perms["permission"]:
@@ -1464,7 +1466,7 @@ async def vision(ctx, image_url: str):
@client.hybrid_command() @client.hybrid_command()
async def addbackgrounddata(ctx, *, data: str): async def addbackgrounddata(ctx, *, data: str):
"""Adds additional background data to the file.""" """Adds additional background data to the file (Owner only)."""
if commands.is_owner(): if commands.is_owner():
try: try:
with open("background_data.txt", "a", encoding="utf-8") as file: with open("background_data.txt", "a", encoding="utf-8") as file:
@@ -1478,7 +1480,7 @@ async def addbackgrounddata(ctx, *, data: str):
@client.hybrid_command() @client.hybrid_command()
async def summarize(ctx, number: int): async def summarize(ctx, number: int):
"""Summarizes the last x messages in the chat.""" """Summarizes the last x messages in the chat (Admin only)."""
if not features["summarize"]: if not features["summarize"]:
await ctx.send("Sorry, the summarize feature is currently disabled.") await ctx.send("Sorry, the summarize feature is currently disabled.")
return return
@@ -1525,7 +1527,7 @@ async def summarize(ctx, number: int):
@client.hybrid_command() @client.hybrid_command()
async def join(ctx): async def join(ctx):
"""Bot joins a voice channel.""" """Makes the bot join a voice channel."""
if ctx.author.voice: if ctx.author.voice:
channel = ctx.author.voice.channel channel = ctx.author.voice.channel
await channel.connect() await channel.connect()
@@ -1535,7 +1537,7 @@ async def join(ctx):
@client.hybrid_command() @client.hybrid_command()
async def leave(ctx): async def leave(ctx):
"""Bot leaves the voice channel.""" """Makes the bot leave the voice channel."""
if ctx.voice_client: if ctx.voice_client:
await ctx.voice_client.disconnect() await ctx.voice_client.disconnect()
await ctx.send("Left the voice channel.") await ctx.send("Left the voice channel.")
@@ -1544,7 +1546,7 @@ async def leave(ctx):
@client.hybrid_command() @client.hybrid_command()
async def toggle_feature(ctx, feature: str, state: str): async def toggle_feature(ctx, feature: str, state: str):
"""Allows admin to enable or disable features.""" """Allows admin to enable or disable bot features."""
guild_id = ctx.guild.id guild_id = ctx.guild.id
user_id = ctx.author.id user_id = ctx.author.id
user_data = load_user_data_sync(user_id, guild_id) user_data = load_user_data_sync(user_id, guild_id)
@@ -1653,7 +1655,7 @@ async def download_and_save_profile_image(user_id, discord_url):
@client.hybrid_command() @client.hybrid_command()
async def addnotes(ctx, type: str, *, source: str): async def addnotes(ctx, type: str, *, source: str):
"""Adds a note that can be consulted later.""" """Adds a note that can be consulted later. Use 'txt' for text files or 'url' for website URLs."""
await ctx.defer() # Signalisiert, dass die Bearbeitung des Befehls begonnen hat await ctx.defer() # Signalisiert, dass die Bearbeitung des Befehls begonnen hat
user_id = ctx.author.id user_id = ctx.author.id
@@ -1700,7 +1702,7 @@ async def addnotes(ctx, type: str, *, source: str):
@client.hybrid_command() @client.hybrid_command()
async def asknotes(ctx, *, question: str): async def asknotes(ctx, *, question: str):
"""Asks a question about the saved notes.""" """Asks a question about your saved notes."""
await ctx.defer() await ctx.defer()
user_id = ctx.author.id user_id = ctx.author.id