dev-prodId #1
66
main.py
66
main.py
|
|
@ -1,3 +1,6 @@
|
||||||
|
from idlelib import autocomplete
|
||||||
|
from random import choices
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
from discord.commands import option
|
from discord.commands import option
|
||||||
|
|
@ -7,6 +10,7 @@ from datetime import datetime
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import ast
|
||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -89,6 +93,11 @@ async def getCarriers(ctx: discord.AutocompleteContext):
|
||||||
return carrierList
|
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
|
###creates a nice progress bar from two values
|
||||||
async def createProgressBar(a,b):
|
async def createProgressBar(a,b):
|
||||||
|
|
@ -154,6 +163,10 @@ discordToken = readToken("discord.token")
|
||||||
gsheetToken = readToken("sheet.token")
|
gsheetToken = readToken("sheet.token")
|
||||||
lastCommandFile = "command.last"
|
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.
|
#there's a small chance the files don't exist. If they don't we create an empty file.
|
||||||
try:
|
try:
|
||||||
with open("station.name", 'r') as f:
|
with open("station.name", 'r') as f:
|
||||||
|
|
@ -176,12 +189,14 @@ async def on_connect():
|
||||||
print("I'm alive, bitch")
|
print("I'm alive, bitch")
|
||||||
session = aiohttp.ClientSession()
|
session = aiohttp.ClientSession()
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("I'm ready, bitch")
|
|
||||||
writeToWhatsLeftToHaul.start()
|
writeToWhatsLeftToHaul.start()
|
||||||
writeTocarrierState.start()
|
writeTocarrierState.start()
|
||||||
|
|
||||||
|
print("I'm ready, bitch")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# delivery command
|
# delivery command
|
||||||
|
|
@ -191,31 +206,17 @@ async def on_ready():
|
||||||
# guild_ids=[401372086746087425],
|
# guild_ids=[401372086746087425],
|
||||||
description= "sends your delivery to the bot!"
|
description= "sends your delivery to the bot!"
|
||||||
)
|
)
|
||||||
async def delivery(ctx,
|
@option("commodity",required=True,
|
||||||
commodity:discord.Option(str, choices=[
|
description="The Commodity you want to deliver",
|
||||||
"Aluminium",
|
autocomplete=getCommodities)
|
||||||
"Ceramic Composites",
|
@option("quantity",required=True,
|
||||||
"CMM Composite",
|
description="Please be nice and input a value between 1 and 1326 (new rack update!!!!1!1)",
|
||||||
"Computer Components",
|
type=int, min_value=1, max_value=1326)
|
||||||
"Copper",
|
@option("target", required=True,
|
||||||
"Food Cartridges",
|
description="Are you delivering to a carrier or the target station?",
|
||||||
"Fruit and Vegetables",
|
type=str, choices=['Station', 'Carrier'])
|
||||||
"Insulating Membrane",
|
|
||||||
"Liquid Oxygen",
|
async def delivery(ctx,commodity, quantity,target):
|
||||||
"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'])
|
|
||||||
):
|
|
||||||
|
|
||||||
author = str(ctx.author)
|
author = str(ctx.author)
|
||||||
author = author[:author.find(" ")]
|
author = author[:author.find(" ")]
|
||||||
|
|
@ -411,9 +412,15 @@ async def setCarrierState(ctx, carrier, state):
|
||||||
await ctx.followup.send(f"help : Error: {e}")
|
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.
|
#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)
|
@tasks.loop(seconds=60)
|
||||||
async def writeToWhatsLeftToHaul():
|
async def writeToWhatsLeftToHaul():
|
||||||
|
|
||||||
|
|
||||||
response = await getFromSheet(gsheetToken, "commodity")
|
response = await getFromSheet(gsheetToken, "commodity")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -423,22 +430,29 @@ async def writeToWhatsLeftToHaul():
|
||||||
values = values.split(",")
|
values = values.split(",")
|
||||||
initial = initial.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 = []
|
||||||
|
|
||||||
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 createProgressBar(values[i],initial[i])
|
progressDict[commodity[i]] = await createProgressBar(values[i],initial[i])
|
||||||
|
neededCommodity.append(commodity[i])
|
||||||
else:
|
else:
|
||||||
progressDict[commodity[i]] = await createProgressBar(1,1)
|
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))
|
||||||
|
|
||||||
|
with open("commodity.needed",'w') as f:
|
||||||
|
f.write(str(neededCommodity))
|
||||||
|
print("values set")
|
||||||
|
|
||||||
channel = bot.get_channel(1519457137234022460)
|
channel = bot.get_channel(1519457137234022460)
|
||||||
# await channel.purge(limit=1)
|
# await channel.purge(limit=1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user