dev-prodId #2

Merged
Taledo merged 4 commits from dev-prodId into main 2026-07-31 18:46:30 +00:00
Showing only changes of commit 26d6c39369 - Show all commits

View File

@ -286,115 +286,121 @@ class IdaCogs(commands.Cog):
#writes to the whats left to haul channel ever 60 seconds about.. the stuff left to haul. #writes to the whats left to haul channel ever 60 seconds about.. the stuff left to haul.
#also updates the current commodity List #also updates the current commodity List
@tasks.loop(seconds=60) @tasks.loop(seconds=120)
async def writeToWhatsLeftToHaul(self): async def writeToWhatsLeftToHaul(self):
try:
response = await helpers.getFromSheet(self.session, self.gsheetToken, "commodity")
response = await helpers.getFromSheet(self.session, self.gsheetToken, "commodity") print(response)
commodity, values, initial = response.split("|")
print(response) commodity = commodity.split(",")
commodity, values, initial = response.split("|") values = values.split(",")
initial = initial.split(",")
commodity = commodity.split(",")
values = values.split(",")
initial = initial.split(",")
values = [int(i) for i in values] values = [int(i) for i in values]
initial = [int (i) for i in initial] initial = [int (i) for i in initial]
finalDict = {} finalDict = {}
progressDict = {} progressDict = {}
neededCommodity = [] neededCommodity = []
for i in range(len(commodity)): for i in range(len(commodity)):
finalDict[commodity[i]] = values[i] finalDict[commodity[i]] = values[i]
if initial[i] > 0: if initial[i] > 0:
progressDict[commodity[i]] = await helpers.createProgressBar(values[i],initial[i]) progressDict[commodity[i]] = await helpers.createProgressBar(values[i],initial[i])
else: else:
progressDict[commodity[i]] = await helpers.createProgressBar(1,1) progressDict[commodity[i]] = await helpers.createProgressBar(1,1)
if values[i] > 0: if values[i] > 0:
neededCommodity.append(commodity[i]) neededCommodity.append(commodity[i])
#finalDict = dict(sorted(finalDict.items(), key=lambda item: item[1], reverse=True)) #finalDict = dict(sorted(finalDict.items(), key=lambda item: item[1], reverse=True))
self.commodities = neededCommodity self.commodities = neededCommodity
embed = discord.Embed(title="Estimated remaining amounts", embed = discord.Embed(title="Estimated remaining amounts",
colour=discord.Colour(0xffdd55), colour=discord.Colour(0xffdd55),
timestamp=datetime.now()) timestamp=datetime.now())
embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png") embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
embed2 = discord.Embed(title="Current progress", embed2 = discord.Embed(title="Current progress",
colour=discord.Colour(0x002f80), colour=discord.Colour(0x002f80),
timestamp=datetime.now()) timestamp=datetime.now())
embed2.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png") embed2.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
for key in finalDict: for key in finalDict:
if finalDict[key] > 0: if finalDict[key] > 0:
embed.add_field(name=key, value=finalDict[key], inline=True) embed.add_field(name=key, value=finalDict[key], inline=True)
embed2.add_field(name=key, value=str(progressDict[key]), inline=True) embed2.add_field(name=key, value=str(progressDict[key]), inline=True)
embed2.set_footer(text="This message updates every 60 seconds(ish). Last updated") embed2.set_footer(text="This message updates every 120 seconds(ish). Last updated")
embed.set_author(name=u'\U0001F517 ' + self.stationName + u' \U0001F517', embed.set_author(name=u'\U0001F517 ' + self.stationName + u' \U0001F517',
url=self.stationUrl) url=self.stationUrl)
embed2.set_author(name=u'\U0001F517 ' + self.stationName + u' \U0001F517', embed2.set_author(name=u'\U0001F517 ' + self.stationName + u' \U0001F517',
url=self.stationUrl) url=self.stationUrl)
channel = self.bot.get_channel(self.whatsLeftToHaulChannelId) channel = self.bot.get_channel(self.whatsLeftToHaulChannelId)
found = False found = False
async for oldmsg in channel.history(limit=2): async for oldmsg in channel.history(limit=2):
if oldmsg.author == self.bot.user: if oldmsg.author == self.bot.user:
found = True found = True
await oldmsg.edit(embeds=[embed, embed2]) await oldmsg.edit(embeds=[embed, embed2])
break break
if not found: if not found:
await channel.send(embeds=[embed, embed2]) await channel.send(embeds=[embed, embed2])
except Exception as e:
print("Something bad happened in the whatlefttohaul function :(")
#writes the carriers state to... the carrier state channel. Seriously, who is writing this? #writes the carriers state to... the carrier state channel. Seriously, who is writing this?
@tasks.loop(seconds=60) @tasks.loop(seconds=120)
async def writeTocarrierState(self): async def writeTocarrierState(self):
response = await helpers.getInternalCarrierState(self.session, self.gsheetToken) try:
carrierState = await helpers.parseCarrierState(response) response = await helpers.getInternalCarrierState(self.session, self.gsheetToken)
carrierState = await helpers.parseCarrierState(response)
channel = self.bot.get_channel(self.carrierStatsChannel) channel = self.bot.get_channel(self.carrierStatsChannel)
embed = discord.Embed(title="Carriers State", embed = discord.Embed(title="Carriers State",
colour=discord.Colour(0x29ac08), colour=discord.Colour(0x29ac08),
timestamp=datetime.now()) timestamp=datetime.now())
embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png") embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
embed.set_author(name=u'\U0001F517 ' + self.stationName + u' \U0001F517', embed.set_author(name=u'\U0001F517 ' + self.stationName + u' \U0001F517',
url=self.stationUrl) url=self.stationUrl)
embed.set_footer(text="This message updates every 60 seconds(ish). Last updated") embed.set_footer(text="This message updates every 120 seconds(ish). Last updated")
for carrier, state in carrierState.items(): for carrier, state in carrierState.items():
embed.add_field(name=carrier, value=state, inline=True) embed.add_field(name=carrier, value=state, inline=True)
found = False found = False
async for oldmsg in channel.history(limit=2): async for oldmsg in channel.history(limit=2):
if oldmsg.author == self.bot.user: if oldmsg.author == self.bot.user:
found = True found = True
await oldmsg.edit(embed=embed) await oldmsg.edit(embed=embed)
break break
if not found: if not found:
await channel.send(embed=embed) await channel.send(embed=embed)
except Exception as e:
print("Something bad happened in the carrierState function :(")
def setup(bot): # this is called by Pycord to setup the cog def setup(bot): # this is called by Pycord to setup the cog
bot.add_cog(IdaCogs(bot)) # add the cog to the bot bot.add_cog(IdaCogs(bot)) # add the cog to the bot