mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
Add POST requests to fetch method for Kheina API
This commit is contained in:
parent
4ba0ce153d
commit
a6431ca4c3
1 changed files with 28 additions and 11 deletions
|
@ -84,19 +84,36 @@ last_commands = {}
|
||||||
asession = aiohttp.ClientSession()
|
asession = aiohttp.ClientSession()
|
||||||
|
|
||||||
|
|
||||||
async def fetch(url, *, json=False, response=False, text=False):
|
async def fetch(url, *, post={}, response=False, text=False, json=False):
|
||||||
if '.json' in url and ('e621' in url or 'e926' in url):
|
if '.json' in url and ('e621' in url or 'e926' in url):
|
||||||
url += f'&login=BotMyned&api_key={config["e621_api"]}'
|
url += f'&login=BotMyned&api_key={config["e621_api"]}'
|
||||||
async with asession.get(url, headers={
|
|
||||||
'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r:
|
if post:
|
||||||
if response:
|
async with asession.post(url, data=post, headers={
|
||||||
return r
|
'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r:
|
||||||
elif json:
|
if r.status != 200:
|
||||||
return await r.json()
|
return r.status
|
||||||
elif text:
|
elif response:
|
||||||
return await r.text()
|
return r
|
||||||
else:
|
elif text:
|
||||||
return await r.read()
|
return await r.text()
|
||||||
|
elif json:
|
||||||
|
return await r.json()
|
||||||
|
else:
|
||||||
|
return await r.read()
|
||||||
|
else:
|
||||||
|
async with asession.get(url, headers={
|
||||||
|
'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r:
|
||||||
|
if r.status != 200:
|
||||||
|
return r.status
|
||||||
|
elif response:
|
||||||
|
return r
|
||||||
|
elif text:
|
||||||
|
return await r.text()
|
||||||
|
elif json:
|
||||||
|
return await r.json()
|
||||||
|
else:
|
||||||
|
return await r.read()
|
||||||
|
|
||||||
|
|
||||||
def generate_embed(ctx, *, title=d.Embed.Empty, kind='rich', description=d.Embed.Empty, url=d.Embed.Empty, timestamp=d.Embed.Empty, colour=color, footer={}, image=d.Embed.Empty, thumbnail=d.Embed.Empty, author={}, fields=[]):
|
def generate_embed(ctx, *, title=d.Embed.Empty, kind='rich', description=d.Embed.Empty, url=d.Embed.Empty, timestamp=d.Embed.Empty, colour=color, footer={}, image=d.Embed.Empty, thumbnail=d.Embed.Empty, author={}, fields=[]):
|
||||||
|
|
Loading…
Reference in a new issue