Compare commits
No commits in common. "9a35c7c430d084f6ae3d91c36788124010653df3" and "4f6a0017d3917fc3da937ce0698e6d9575b6f814" have entirely different histories.
9a35c7c430
...
4f6a0017d3
21
main.py
21
main.py
|
|
@ -3,7 +3,6 @@ from discord.ext import commands
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
import aiohttp
|
|
||||||
|
|
||||||
|
|
||||||
### reads token files
|
### reads token files
|
||||||
|
|
@ -12,16 +11,6 @@ def readToken(filePath):
|
||||||
return f.readline()
|
return f.readline()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### takes a json, returns a http code
|
|
||||||
async def postToSheet(data, gsheetToken):
|
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
async with session.post(gsheetToken, json=data) as response:
|
|
||||||
print("Status:", response.status)
|
|
||||||
return response.status
|
|
||||||
|
|
||||||
|
|
||||||
bot = commands.Bot()
|
bot = commands.Bot()
|
||||||
|
|
||||||
# various tokens
|
# various tokens
|
||||||
|
|
@ -62,7 +51,7 @@ async def delivery(ctx,
|
||||||
"Water",
|
"Water",
|
||||||
"Water Purifiers"
|
"Water Purifiers"
|
||||||
]),
|
]),
|
||||||
quantity: discord.Option(discord.SlashCommandOptionType.integer, description="Please be nice and input a value between 1 and 1238 (unless fdev touched something again)", min_value=1, max_value=1238),
|
quantity: discord.Option(discord.SlashCommandOptionType.integer, description="Please be nice and input a value between 1 and 1238 (unless fdev touched something again)") ,
|
||||||
target: discord.Option(str, choices=['Station', 'Carrier'])
|
target: discord.Option(str, choices=['Station', 'Carrier'])
|
||||||
):
|
):
|
||||||
|
|
||||||
|
|
@ -83,12 +72,12 @@ async def delivery(ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await postToSheet(data, gsheetToken)
|
response = requests.post(gsheetToken, json.dumps(data), headers={"Content-Type": "application/json"})
|
||||||
if response == 200:
|
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!")
|
await ctx.followup.send(f"your delivery of {quantity} of {commodity} to a {target} has been added to the sheet!")
|
||||||
print(f"[{dt.isoformat(dt.now())}]{author} delivery of {quantity} of {commodity} to a {target}")
|
print(f"[{dt.isoformat(dt.now())}]{author} delivery of {quantity} of {commodity} to a {target}")
|
||||||
else:
|
else:
|
||||||
await ctx.followup.send(f"Failed to log delivery (HTTP {response}). Please contact the yellow people if that keeps happening")
|
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:
|
except Exception as e:
|
||||||
await ctx.followup.send(f"help : Error: {e}")
|
await ctx.followup.send(f"help : Error: {e}")
|
||||||
|
|
||||||
|
|
@ -110,7 +99,7 @@ async def changeSheetUrl(ctx,
|
||||||
with open("sheet.token",'w') as f:
|
with open("sheet.token",'w') as f:
|
||||||
f.write(url)
|
f.write(url)
|
||||||
|
|
||||||
await ctx.followup.send(f"URL has been set to {url}")
|
await ctx.followup.send(f"URL has been set")
|
||||||
gsheetToken = readToken("sheet.token")
|
gsheetToken = readToken("sheet.token")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.followup.send(f"something shat the bed")
|
await ctx.followup.send(f"something shat the bed")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user