Add command for detailed view of request

This commit is contained in:
Dustin Pianalto 2019-12-12 23:49:56 -09:00
parent 07a7b25964
commit 21f766b6d2

View File

@ -216,7 +216,7 @@ class Tickets(commands.Cog):
@commands.command() @commands.command()
async def view(self, ctx, id=None): async def view(self, ctx, id=None):
if not id: if not id:
await ctx.send('Please include at least one Request ID to close.') await ctx.send('Please include the id of the request you would like to view.')
return return
admin = False admin = False
@ -235,29 +235,25 @@ class Tickets(commands.Cog):
request = await request_resp.json() request = await request_resp.json()
requestor = ctx.guild.get_member(int(request['author'])) requestor = ctx.guild.get_member(int(request['author']))
if requestor == ctx.author or admin: if requestor == ctx.author or admin:
pag = Paginator(self.bot) pag = Paginator(self.bot, prefix='```md', suffix='```')
title = (f"<{'Request ID':^20} {'Requested By':^20}>\n" header = f''
f"<{request['id']:^20} {requestor.display_name if requestor else 'None':^20}>") if request_resp.status == 200:
orig_channel = ctx.guild.get_channel(int(request.get('channel'))) request = await request_resp.json()
comments_resp = await self.bot.aio_session.get( requestor = ctx.guild.get_member(int(request["author"]))
f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request["id"]}/comments/', header += (f'Original Request by {requestor.mention if requestor else "`User cannot be found`"}:\n'
headers=self.bot.auth_header) f'```{request["content"]}```')
comments_text = 'Comments: ' pag.set_header(header)
if comments_resp.status == 200:
comments_text += '\n' if request.get('comments'):
for comment in await comments_resp.json(): comments = request['comments']
author = ctx.guild.get_member(int(comment['author'])) for comment in comments:
comments_text += f'{author.display_name}: {comment["content"]}\n\n' author = ctx.guild.get_member(int(comment['author']))
else: pag.add(f'{author.display_name}: {comment["content"]}', keep_intact=True)
comments_text += 'None' if ctx.author != requestor and requestor:
pag.add(f"\n\n{title}\n" for page in pag.pages(page_headers=False):
f"{request['content']}\n\n" await requestor.send(page)
f"{comments_text}" book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
f"Requested at: " await book.create_book()
f"{request['requested_at'].split('.')[0].replace('T', ' ')} GMT\n"
f"In {orig_channel.name if orig_channel else 'N/A'}", keep_intact=True)
for page in pag.pages():
await ctx.send(page)
else: else:
await ctx.send('That is not your request to close.') await ctx.send('That is not your request to close.')