Corrected issue where post headers were being sent on get requests
This commit is contained in:
parent
d29bad3ea0
commit
51438fdde5
1 changed files with 25 additions and 20 deletions
|
@ -8,9 +8,11 @@ import re
|
||||||
import json
|
import json
|
||||||
import pendulum
|
import pendulum
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Strawpoll(bot))
|
bot.add_cog(Strawpoll(bot))
|
||||||
|
|
||||||
|
|
||||||
getter = re.compile(r'`(?!`)(.*?)`')
|
getter = re.compile(r'`(?!`)(.*?)`')
|
||||||
multi = re.compile(r'```(.*?)```', re.DOTALL)
|
multi = re.compile(r'```(.*?)```', re.DOTALL)
|
||||||
|
|
||||||
|
@ -25,10 +27,9 @@ class Strawpoll:
|
||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
self.session = aiohttp.ClientSession()
|
self.session = aiohttp.ClientSession()
|
||||||
|
|
||||||
|
@commands.group(aliases=['strawpoll', 'poll', 'polls'], pass_context=True, invoke_without_command=True)
|
||||||
@commands.group(aliases=['strawpoll','poll','polls'], pass_context=True, invoke_without_command=True)
|
|
||||||
@checks.customPermsOrRole(send_messages=True)
|
@checks.customPermsOrRole(send_messages=True)
|
||||||
async def strawpolls(self, ctx, poll_id: int=None):
|
async def strawpolls(self, ctx, poll_id: int = None):
|
||||||
"""This command can be used to show a strawpoll setup on this server"""
|
"""This command can be used to show a strawpoll setup on this server"""
|
||||||
all_polls = config.getContent('strawpolls') or {}
|
all_polls = config.getContent('strawpolls') or {}
|
||||||
server_polls = all_polls.get(ctx.message.server.id) or {}
|
server_polls = all_polls.get(ctx.message.server.id) or {}
|
||||||
|
@ -36,22 +37,25 @@ class Strawpoll:
|
||||||
await self.bot.say("There are currently no strawpolls running on this server!")
|
await self.bot.say("There are currently no strawpolls running on this server!")
|
||||||
return
|
return
|
||||||
if not poll_id:
|
if not poll_id:
|
||||||
fmt = "\n".join("{}: https://strawpoll.me/{}".format(data['title'], id) for id, data in server_polls.items())
|
fmt = "\n".join(
|
||||||
|
"{}: https://strawpoll.me/{}".format(data['title'], id) for id, data in server_polls.items())
|
||||||
await self.bot.say("```\n{}```".format(fmt))
|
await self.bot.say("```\n{}```".format(fmt))
|
||||||
elif str(poll_id) in server_polls.keys():
|
elif str(poll_id) in server_polls.keys():
|
||||||
poll = server_polls[str(poll_id)]
|
poll = server_polls[str(poll_id)]
|
||||||
|
|
||||||
async with self.session.get("{}/{}".format(self.url, str(poll_id)), headers=self.headers) as response:
|
async with self.session.get("{}/{}".format(self.url, str(poll_id))) as response:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
|
||||||
fmt_options = "\n\t".join("{}: {}".format(data['options'][i], data['votes'][i]) for i in range(data['options']))
|
fmt_options = "\n\t".join(
|
||||||
|
"{}: {}".format(data['options'][i], data['votes'][i]) for i in range(data['options']))
|
||||||
author = self.bot.get_member(poll['author'])
|
author = self.bot.get_member(poll['author'])
|
||||||
created_ago = (pendulum.parse(poll['date'])-pendulum.utcnow()).in_words()
|
created_ago = (pendulum.parse(poll['date']) - pendulum.utcnow()).in_words()
|
||||||
link = "https://strawpoll.me{}".format(str(poll_id))
|
link = "https://strawpoll.me{}".format(str(poll_id))
|
||||||
fmt = "Link: {}\nTitle: {}\nAuthor: {}\nCreated: {}\nOptions:\n\t{}".format(link, data['title'], author.display_name, created_ago, fmt_options)
|
fmt = "Link: {}\nTitle: {}\nAuthor: {}\nCreated: {}\nOptions:\n\t{}".format(link, data['title'],
|
||||||
|
author.display_name,
|
||||||
|
created_ago, fmt_options)
|
||||||
await self.bot.say("```\n{}```".format(fmt))
|
await self.bot.say("```\n{}```".format(fmt))
|
||||||
|
|
||||||
|
|
||||||
@strawpolls.command(name='create', aliases=['setup', 'add'], pass_context=True)
|
@strawpolls.command(name='create', aliases=['setup', 'add'], pass_context=True)
|
||||||
@checks.customPermsOrRole(kick_members=True)
|
@checks.customPermsOrRole(kick_members=True)
|
||||||
async def create_strawpoll(self, ctx, title, *, options):
|
async def create_strawpoll(self, ctx, title, *, options):
|
||||||
|
@ -68,7 +72,9 @@ class Strawpoll:
|
||||||
options = match_multi[0].splitlines()
|
options = match_multi[0].splitlines()
|
||||||
options = [option for option in options if option]
|
options = [option for option in options if option]
|
||||||
else:
|
else:
|
||||||
await self.bot.say("Please provide options for a new strawpoll! Use {}help if you do not know the format".format(ctx.prefix))
|
await self.bot.say(
|
||||||
|
"Please provide options for a new strawpoll! Use {}help if you do not know the format".format(
|
||||||
|
ctx.prefix))
|
||||||
return
|
return
|
||||||
payload = {'title': title,
|
payload = {'title': title,
|
||||||
'options': options}
|
'options': options}
|
||||||
|
@ -77,9 +83,8 @@ class Strawpoll:
|
||||||
|
|
||||||
all_polls = config.getContent('strawpolls') or {}
|
all_polls = config.getContent('strawpolls') or {}
|
||||||
server_polls = all_polls.get(ctx.message.server.id) or {}
|
server_polls = all_polls.get(ctx.message.server.id) or {}
|
||||||
server_polls[data['id']] = {'author': ctx.message.author.id,'date': str(pendulum.utcnow()), 'title': title}
|
server_polls[data['id']] = {'author': ctx.message.author.id, 'date': str(pendulum.utcnow()), 'title': title}
|
||||||
all_polls[ctx.message.server.id] = server_polls
|
all_polls[ctx.message.server.id] = server_polls
|
||||||
config.saveContent('strawpolls',all_polls)
|
config.saveContent('strawpolls', all_polls)
|
||||||
|
|
||||||
await self.bot.say("Link for your new strawpoll: https://strawpoll.me/{}".format(data['id']))
|
await self.bot.say("Link for your new strawpoll: https://strawpoll.me/{}".format(data['id']))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue