modified: bot.py

This commit is contained in:
SimolZimol
2024-09-05 14:42:35 +02:00
parent 37d32b3faf
commit 8f47e44f60

58
bot.py
View File

@@ -30,6 +30,12 @@ OPENAI_BASE_URL = os.getenv("OPENAI_BASE_URL")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
OWNER_ID = int(os.getenv("OWNER_ID")) OWNER_ID = int(os.getenv("OWNER_ID"))
features = {
"askmultus": bool(int(os.getenv("ASKMULTUS_ENABLED", 0))),
"vision": bool(int(os.getenv("VISION_ENABLED", 0)))
}
# Erstelle einen Ordner für die Logs, wenn er noch nicht existiert # Erstelle einen Ordner für die Logs, wenn er noch nicht existiert
LOGS_DIR = "logs" LOGS_DIR = "logs"
if not os.path.exists(LOGS_DIR): if not os.path.exists(LOGS_DIR):
@@ -80,8 +86,6 @@ intents = discord.Intents.default()
intents.message_content = True intents.message_content = True
intents.reactions = True intents.reactions = True
python = sys.executable python = sys.executable
vision_enabled = os.getenv("VISION_ENABLED")
askmultus_enabled = os.getenv("ASKMULTUS_ENABLED")
client = commands.Bot(command_prefix='-', intents=intents, owner_id = OWNER_ID) client = commands.Bot(command_prefix='-', intents=intents, owner_id = OWNER_ID)
@@ -417,7 +421,7 @@ async def owner_command(ctx):
@client.hybrid_command() @client.hybrid_command()
async def askmultus(ctx, *, prompt: str): async def askmultus(ctx, *, prompt: str):
"""Submits a prompt to Multus for assistance or information. (5 Points)""" """Submits a prompt to Multus for assistance or information. (5 Points)"""
if not askmultus_enabled: if not features["askmultus"]:
await ctx.send("Sorry, the askmultus feature is currently disabled.") await ctx.send("Sorry, the askmultus feature is currently disabled.")
return return
@@ -520,7 +524,7 @@ async def process_ai_queue():
@client.hybrid_command() @client.hybrid_command()
async def vision(ctx, image_url: str): async def vision(ctx, image_url: str):
"""Analyzes the content of an image.""" """Analyzes the content of an image."""
if not vision_enabled: if not features["vision"]:
await ctx.send("Sorry, the vision feature is currently disabled.") await ctx.send("Sorry, the vision feature is currently disabled.")
return return
@@ -580,7 +584,6 @@ async def addbackgrounddata(ctx, *, data: str):
await ctx.send("You don't have the necessary permissions to use this command.") await ctx.send("You don't have the necessary permissions to use this command.")
@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."""
@@ -641,39 +644,24 @@ async def leave(ctx):
await ctx.send("Left the voice channel.") await ctx.send("Left the voice channel.")
else: else:
await ctx.send("I am not in a voice channel.") await ctx.send("I am not in a voice channel.")
@client.hybrid_command() @client.hybrid_command()
async def switch(ctx, mode: str, state: str): @commands.has_permissions(administrator=True)
"""Switches the state of a specified mode (vision/askmultus).""" async def toggle_feature(ctx, feature: str, state: str):
global vision_enabled """Enables or disables a feature like askmultus or vision."""
global askmultus_enabled global features
mode = mode.lower() if feature.lower() not in features:
state = state.lower() await ctx.send(f"Feature {feature} not found.")
user_perms = load_user_data(ctx.author.id) return
if 5 < user_perms["permission"]:
if mode == "vision": if state.lower() == "on":
if state == "on": features[feature.lower()] = True
vision_enabled = True await ctx.send(f"Feature {feature} enabled.")
await ctx.send("Vision mode enabled.") elif state.lower() == "off":
elif state == "off": features[feature.lower()] = False
vision_enabled = False await ctx.send(f"Feature {feature} disabled.")
await ctx.send("Vision mode disabled.")
else:
await ctx.send("Invalid state. Please use 'on' or 'off'.")
elif mode == "askmultus":
if state == "on":
askmultus_enabled = True
await ctx.send("AskMultus mode enabled.")
elif state == "off":
askmultus_enabled = False
await ctx.send("AskMultus mode disabled.")
else:
await ctx.send("Invalid state. Please use 'on' or 'off'.")
else:
await ctx.send("Invalid mode. Please specify either 'vision' or 'askmultus'.")
else: else:
await ctx.send("You don't have the necessary permissions to use this command.") await ctx.send("Please specify 'on' or 'off'.")
@client.hybrid_command() @client.hybrid_command()
async def version(ctx): async def version(ctx):