From a8d3795fdc496bb241327c02950c53247c18152a Mon Sep 17 00:00:00 2001 From: TanguyPcFixe Date: Wed, 1 Jul 2026 21:36:48 +0200 Subject: [PATCH] changed delivery to only show still needed commodities --- main.py | 66 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index 0032d33..7be78f3 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,6 @@ +from idlelib import autocomplete +from random import choices + import discord from discord.ext import commands, tasks from discord.commands import option @@ -7,6 +10,7 @@ from datetime import datetime import aiohttp import os import asyncio +import ast from math import floor @@ -89,6 +93,11 @@ async def getCarriers(ctx: discord.AutocompleteContext): return carrierList +async def getCommodities(ctx: discord.AutocompleteContext): + with open("commodity.needed","r") as f: + listOfCommodities = ast.literal_eval(f.readline()) + return listOfCommodities + ###creates a nice progress bar from two values async def createProgressBar(a,b): @@ -154,6 +163,10 @@ discordToken = readToken("discord.token") gsheetToken = readToken("sheet.token") lastCommandFile = "command.last" +print("hey wassup") + + + #there's a small chance the files don't exist. If they don't we create an empty file. try: with open("station.name", 'r') as f: @@ -176,12 +189,14 @@ async def on_connect(): print("I'm alive, bitch") session = aiohttp.ClientSession() + @bot.event async def on_ready(): - print("I'm ready, bitch") writeToWhatsLeftToHaul.start() writeTocarrierState.start() + print("I'm ready, bitch") + # delivery command @@ -191,31 +206,17 @@ async def on_ready(): # guild_ids=[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 1326 (new rack update!!!!1!1)", min_value=1, max_value=1326), - target: discord.Option(str, choices=['Station', 'Carrier']) - ): +@option("commodity",required=True, + description="The Commodity you want to deliver", + autocomplete=getCommodities) +@option("quantity",required=True, + description="Please be nice and input a value between 1 and 1326 (new rack update!!!!1!1)", + type=int, min_value=1, max_value=1326) +@option("target", required=True, + description="Are you delivering to a carrier or the target station?", + type=str, choices=['Station', 'Carrier']) + +async def delivery(ctx,commodity, quantity,target): author = str(ctx.author) author = author[:author.find(" ")] @@ -411,9 +412,15 @@ async def setCarrierState(ctx, carrier, state): await ctx.followup.send(f"help : Error: {e}") + + + #writes to the whats left to haul channel ever 60 seconds about.. the stuff left to haul. +#also updates the current commodity List @tasks.loop(seconds=60) async def writeToWhatsLeftToHaul(): + + response = await getFromSheet(gsheetToken, "commodity") @@ -423,22 +430,29 @@ async def writeToWhatsLeftToHaul(): values = values.split(",") initial = initial.split(",") + + values = [int(i) for i in values] initial = [int (i) for i in initial] finalDict = {} progressDict = {} + neededCommodity = [] for i in range(len(commodity)): finalDict[commodity[i]] = values[i] if initial[i] > 0: progressDict[commodity[i]] = await createProgressBar(values[i],initial[i]) + neededCommodity.append(commodity[i]) else: progressDict[commodity[i]] = await createProgressBar(1,1) #finalDict = dict(sorted(finalDict.items(), key=lambda item: item[1], reverse=True)) + with open("commodity.needed",'w') as f: + f.write(str(neededCommodity)) + print("values set") channel = bot.get_channel(1519457137234022460) # await channel.purge(limit=1)