From 2eacdd3a014a97c1ec4e785581551b47d28603cf Mon Sep 17 00:00:00 2001 From: TanguyPcFixe Date: Mon, 14 Jul 2025 22:41:19 +0200 Subject: [PATCH] v1, works but is shit --- main.py | 109 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 93 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index da891ee..257a57d 100644 --- a/main.py +++ b/main.py @@ -1,29 +1,106 @@ import discord +from discord.ext import commands +import requests +import json - +### reads token files def readToken(filePath): with open(filePath, 'r') as f: - return f.readline() + return f.readline()[:-1] -intents = discord.Intents.default() -intents.message_content = True -token = readToken("token.token") +bot = commands.Bot() + +# various tokens +discordToken = readToken("discord.token") +gsheetToken = readToken("sheet.token") + +# default command to see if the bot has lived +@bot.listen() +async def on_connect(): + print("I'm alive, bitch") + +# delivery command +@bot.slash_command( + name="delivery", + guild_ids=[1349222984837107797, 401372086746087425], + description= "sends your delivery to the bot!" +) +async def delivery(ctx, + commodity:discord.Option(str, choices=[ + "Aluminium", + "Ceramic Composites", + "CMM Composite", + "Computer Components", + "Copper", + "Food Cartridges", + "Fruit and Vegetables", + "Insulating Membrane", + "Liquid Oxygen", + "Medical Diagnostic Equipment", + "Non-Lethal Weapons", + "Polymers", + "Power Generators", + "Semiconductors", + "Steel", + "Superconductors", + "Titanium", + "Water", + "Water Purifiers" + ]), + quantity: discord.Option(discord.SlashCommandOptionType.integer, description="Please be nice and input a value between 1 and 794") , + target: discord.Option(str, choices=['Station', 'Carrier']) + ): + + if quantity > 794 or quantity < 1: + await ctx.respond(f"Quantity must be inbetween 1 and 794 (the clipper ain't out yet.)") + return 0 + + author = str(ctx.author) + author = author[:author.find(" ")] + + await ctx.defer() + + data = { + "username":author, + "commodity": commodity, + "quantity": quantity, + "target": target + } + + try: + response = requests.post(gsheetToken, json.dumps(data), headers={"Content-Type": "application/json"}) + if response.status_code == 200: + await ctx.followup.send(f"your delivery of {quantity} of {commodity} to a {target} has been added to the sheet!") + else: + await ctx.followup.send(f"Failed to log delivery (HTTP {response.status_code}). Please contact the yellow people if that keeps happening") + except Exception as e: + await ctx.followup.send(f"help : Error: {e}") -client = discord.Client(intents=intents) -@client.event -async def on_ready(): - print(f'We have logged in as {client.user}') -@client.event -async def on_message(message): - if message.author == client.user: - return +#change url command +@bot.slash_command( + name="change-sheet-url", + guild_ids=[1349222984837107797, 401372086746087425], + description= "changes the URL of the active sheet, use with caution" +) +async def changeSheetUrl(ctx, + url:discord.Option(discord.SlashCommandOptionType.string, description="the new URL") + ): + await ctx.defer() + try: + with open("sheet.token",'w') as f: + f.write(url) - if message.content.startswith('$hello'): - await message.channel.send('Hello!') + await ctx.followup.send(f"URL has been set") + except Exception as e: + await ctx.followup.send(f"something shat the bed") -client.run(token) \ No newline at end of file + + + +#run the damn thing +bot.run(discordToken) \ No newline at end of file