dev-prodId #1
65
main.py
65
main.py
|
|
@ -81,6 +81,16 @@ async def getInternalCarrierState():
|
|||
response = await getFromSheet(gsheetToken, "carrier")
|
||||
return response
|
||||
|
||||
###creates a nice progress bar from two values
|
||||
async def createProgressBar(a,b):
|
||||
print(a, b)
|
||||
ratio = floor(((b-a)/b) * 10)
|
||||
|
||||
print(ratio)
|
||||
|
||||
progressBar = f"{'⣿'* ratio}{'.'*(10-ratio)} ({ratio*10}%)"
|
||||
|
||||
return progressBar
|
||||
|
||||
|
||||
|
||||
|
|
@ -232,7 +242,7 @@ async def misc(ctx,
|
|||
data = {
|
||||
"postType":"delivery",
|
||||
"username":author,
|
||||
"commodity": commodity,
|
||||
"commodity": "Misc",
|
||||
"quantity": quantity,
|
||||
"target": target
|
||||
}
|
||||
|
|
@ -431,37 +441,56 @@ async def lefttohaul(ctx):
|
|||
@tasks.loop(seconds=60)
|
||||
async def writeToWhatsLeftToHaul():
|
||||
response = await getFromSheet(gsheetToken, "commodity")
|
||||
print("test")
|
||||
text = "```"
|
||||
|
||||
commodity, values = response.split("|")
|
||||
|
||||
commodity, values, initial = response.split("|")
|
||||
|
||||
commodity = commodity.split(",")
|
||||
values = values.split(",")
|
||||
initial = initial.split(",")
|
||||
|
||||
values = [int(i) for i in values]
|
||||
initial = [int (i) for i in initial]
|
||||
|
||||
print(values, initial)
|
||||
|
||||
finalDict = {}
|
||||
progressDict = {}
|
||||
|
||||
for i in range(len(commodity)):
|
||||
finalDict[commodity[i]] = int(values[i])
|
||||
finalDict[commodity[i]] = values[i]
|
||||
if initial[i] > 0:
|
||||
progressDict[commodity[i]] = await createProgressBar(values[i],initial[i])
|
||||
else:
|
||||
progressDict[commodity[i]] = await createProgressBar(1,1)
|
||||
|
||||
finalDict = dict(sorted(finalDict.items(), key=lambda item: item[1], reverse=True))
|
||||
#finalDict = dict(sorted(finalDict.items(), key=lambda item: item[1], reverse=True))
|
||||
|
||||
|
||||
for key in finalDict:
|
||||
if finalDict[key] > 0:
|
||||
text += f"{key} : {finalDict[key]}\n"
|
||||
print(progressDict)
|
||||
|
||||
channel = bot.get_channel(1519457137234022460)
|
||||
# await channel.purge(limit=1)
|
||||
|
||||
text += "```"
|
||||
|
||||
embed = discord.Embed(title="Estimated remaining amounts and where to get them",
|
||||
colour=discord.Colour(0x29ac08),
|
||||
description=text,
|
||||
timestamp=datetime.now())
|
||||
|
||||
embed = discord.Embed(title="Estimated remaining amounts",
|
||||
colour=discord.Colour(0x29ac08),
|
||||
timestamp=datetime.now())
|
||||
embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
|
||||
|
||||
embed.set_footer(text="This message updates every 60 seconds(ish). Last updated at")
|
||||
embed2 = discord.Embed(title="Current progress",
|
||||
colour=discord.Colour(0x29ac08),
|
||||
timestamp=datetime.now())
|
||||
embed2.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
|
||||
|
||||
|
||||
for key in finalDict:
|
||||
if finalDict[key] > 0:
|
||||
embed.add_field(name=key, value=finalDict[key], inline=True)
|
||||
embed2.add_field(name=key, value=str(progressDict[key]), inline=True)
|
||||
|
||||
|
||||
embed.set_footer(text="This message updates every 60 seconds(ish). Last updated")
|
||||
# if 'station_name' in config.config and 'station_link' in config.config:
|
||||
# embed.set_author(name=u'\U0001F517 ' + config.config['station_name'] + u' \U0001F517',
|
||||
# url=config.config['station_link'])
|
||||
|
|
@ -472,10 +501,10 @@ async def writeToWhatsLeftToHaul():
|
|||
async for oldmsg in channel.history(limit=2):
|
||||
if oldmsg.author == bot.user:
|
||||
found = True
|
||||
await oldmsg.edit(embed=embed)
|
||||
await oldmsg.edit(embeds=[embed, embed2])
|
||||
break
|
||||
if not found:
|
||||
await channel.send(embed=embed)
|
||||
await channel.send(embeds=[embed, embed2])
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user