Compare commits
5 Commits
8a814ded0f
...
4af14aab1a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4af14aab1a | ||
|
|
b974ecc687 | ||
|
|
4c12c0f536 | ||
|
|
71f824c21d | ||
|
|
ae6ef321f0 |
@ -11,251 +11,368 @@ class Tickets(commands.Cog):
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def request(self, ctx, *, message=None):
|
async def request(self, ctx, *, message=None):
|
||||||
if not ctx.guild:
|
if not ctx.guild:
|
||||||
await ctx.send('This command must be run from inside a guild.')
|
await ctx.send("This command must be run from inside a guild.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not message:
|
if not message:
|
||||||
await ctx.send('Please include a message containing your request')
|
await ctx.send("Please include a message containing your request")
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(message) > 1000:
|
if len(message) > 1000:
|
||||||
await ctx.send('Request is too long, please keep your request to less than 1000 characters.')
|
await ctx.send(
|
||||||
|
"Request is too long, please keep your request to less than 1000 characters."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'author': ctx.author.id,
|
"author": ctx.author.id,
|
||||||
'message': ctx.message.id,
|
"message": ctx.message.id,
|
||||||
'channel': ctx.channel.id,
|
"channel": ctx.channel.id,
|
||||||
'content': message
|
"content": message,
|
||||||
}
|
}
|
||||||
msg_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/messages/{ctx.message.id}/wait/', headers=self.bot.auth_header)
|
msg_resp = await self.bot.aio_session.get(
|
||||||
|
f"{self.bot.api_base}/messages/{ctx.message.id}/wait/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if msg_resp.status == 404:
|
if msg_resp.status == 404:
|
||||||
error = await msg_resp.json()
|
error = await msg_resp.json()
|
||||||
await ctx.send(error['details'])
|
await ctx.send(error["details"])
|
||||||
return
|
return
|
||||||
|
|
||||||
resp = await self.bot.aio_session.post(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/', headers=self.bot.auth_header, json=data)
|
resp = await self.bot.aio_session.post(
|
||||||
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
json=data,
|
||||||
|
)
|
||||||
|
|
||||||
if resp.status == 201:
|
if resp.status == 201:
|
||||||
admin_channel_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/channels/{ctx.guild.id}/admin/', headers=self.bot.auth_header)
|
admin_channel_resp = await self.bot.aio_session.get(
|
||||||
|
f"{self.bot.api_base}/channels/{ctx.guild.id}/admin/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
request = await resp.json()
|
request = await resp.json()
|
||||||
|
|
||||||
if admin_channel_resp.status == 200:
|
if admin_channel_resp.status == 200:
|
||||||
admin_chan_data = await admin_channel_resp.json()
|
admin_chan_data = await admin_channel_resp.json()
|
||||||
msg = f''
|
msg = f""
|
||||||
admin_roles_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/', headers=self.bot.auth_header)
|
admin_roles_resp = await self.bot.aio_session.get(
|
||||||
|
f"{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if admin_roles_resp.status == 200:
|
if admin_roles_resp.status == 200:
|
||||||
admin_roles_data = await admin_roles_resp.json()
|
admin_roles_data = await admin_roles_resp.json()
|
||||||
for role in admin_roles_data:
|
for role in admin_roles_data:
|
||||||
msg += f'{ctx.guild.get_role(int(role["id"])).mention} '
|
msg += f'{ctx.guild.get_role(int(role["id"])).mention} '
|
||||||
msg += f"New Request ID: {request['id']} " \
|
msg += (
|
||||||
f"{ctx.author.mention} has requested assistance: \n" \
|
f"New Request ID: {request['id']} "
|
||||||
f"```{request['content']}``` \n" \
|
f"{ctx.author.mention} has requested assistance: \n"
|
||||||
f"Requested at: {request['requested_at'].split('.')[0].replace('T', ' ')} GMT\n" \
|
f"```{request['content']}``` \n"
|
||||||
|
f"Requested at: {request['requested_at'].split('.')[0].replace('T', ' ')} GMT\n"
|
||||||
f"In {ctx.guild.get_channel(int(request['channel'])).name}"
|
f"In {ctx.guild.get_channel(int(request['channel'])).name}"
|
||||||
admin_chan = ctx.guild.get_channel(int(admin_chan_data['id']))
|
)
|
||||||
|
admin_chan = ctx.guild.get_channel(int(admin_chan_data["id"]))
|
||||||
await admin_chan.send(msg)
|
await admin_chan.send(msg)
|
||||||
await ctx.send(f'{ctx.author.mention} The admin have received your request.\n'
|
await ctx.send(
|
||||||
f'If you would like to update or close your request please reference Request ID `{request["id"]}`')
|
f"{ctx.author.mention} The admin have received your request.\n"
|
||||||
|
f'If you would like to update or close your request please reference Request ID `{request["id"]}`'
|
||||||
|
)
|
||||||
|
|
||||||
@commands.command(aliases=['comment'])
|
@commands.command(aliases=["comment"])
|
||||||
async def update(self, ctx, request_id=None, *, comment: str = None):
|
async def update(self, ctx, request_id=None, *, comment: str = None):
|
||||||
try:
|
try:
|
||||||
request_id = int(request_id)
|
request_id = int(request_id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
await ctx.send("Please include the ID of the request you would like to update as the first thing after the command.")
|
await ctx.send(
|
||||||
|
"Please include the ID of the request you would like to update as the first thing after the command."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not comment:
|
if not comment:
|
||||||
await ctx.send("There is nothing to update since you didn't include a message.")
|
await ctx.send(
|
||||||
|
"There is nothing to update since you didn't include a message."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
data = {
|
data = {"author": ctx.author.id, "content": comment}
|
||||||
'author': ctx.author.id,
|
|
||||||
'content': comment
|
|
||||||
}
|
|
||||||
|
|
||||||
comment_resp = await self.bot.aio_session.post(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request_id}/comments/', headers=self.bot.auth_header, json=data)
|
comment_resp = await self.bot.aio_session.post(
|
||||||
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request_id}/comments/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
json=data,
|
||||||
|
)
|
||||||
|
|
||||||
if comment_resp.status == 201:
|
if comment_resp.status == 201:
|
||||||
comment = await comment_resp.json()
|
comment = await comment_resp.json()
|
||||||
admin_channel_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/channels/{ctx.guild.id}/admin/',
|
admin_channel_resp = await self.bot.aio_session.get(
|
||||||
headers=self.bot.auth_header)
|
f"{self.bot.api_base}/channels/{ctx.guild.id}/admin/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
|
|
||||||
if admin_channel_resp.status == 200:
|
if admin_channel_resp.status == 200:
|
||||||
admin_channel_data = await admin_channel_resp.json()
|
admin_channel_data = await admin_channel_resp.json()
|
||||||
admin_channel = ctx.guild.get_channel(int(admin_channel_data['id']))
|
admin_channel = ctx.guild.get_channel(int(admin_channel_data["id"]))
|
||||||
if admin_channel:
|
if admin_channel:
|
||||||
request_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request_id}/', headers=self.bot.auth_header)
|
request_resp = await self.bot.aio_session.get(
|
||||||
pag = Paginator(self.bot, prefix='```md', suffix='```')
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request_id}/",
|
||||||
header = f'{ctx.author.mention} has commented on request {request_id}\n'
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
|
pag = Paginator(self.bot, prefix="```md", suffix="```")
|
||||||
|
header = (
|
||||||
|
f"{ctx.author.mention} has commented on request {request_id}\n"
|
||||||
|
)
|
||||||
if request_resp.status == 200:
|
if request_resp.status == 200:
|
||||||
request = await request_resp.json()
|
request = await request_resp.json()
|
||||||
requestor = ctx.guild.get_member(int(request["author"]))
|
requestor = await ctx.guild.fetch_member(int(request["author"]))
|
||||||
header += (f'Original Request by {requestor.mention if requestor else "`User cannot be found`"}:\n'
|
header += (
|
||||||
f'```{request["content"]}```')
|
f'Original Request by {requestor.mention if requestor else "`User cannot be found`"}:\n'
|
||||||
|
f'```{request["content"]}```'
|
||||||
|
)
|
||||||
pag.set_header(header)
|
pag.set_header(header)
|
||||||
|
|
||||||
if request.get('comments'):
|
if request.get("comments"):
|
||||||
comments = request['comments']
|
comments = request["comments"]
|
||||||
for comment in comments:
|
for comment in comments:
|
||||||
author = ctx.guild.get_member(int(comment['author']))
|
author = await ctx.guild.fetch_member(
|
||||||
pag.add(f'{author.display_name}: {comment["content"]}', keep_intact=True)
|
int(comment["author"])
|
||||||
|
)
|
||||||
|
pag.add(
|
||||||
|
f'{author.display_name}: {comment["content"]}',
|
||||||
|
keep_intact=True,
|
||||||
|
)
|
||||||
if ctx.author != requestor and requestor:
|
if ctx.author != requestor and requestor:
|
||||||
for page in pag.pages(page_headers=False):
|
for page in pag.pages(page_headers=False):
|
||||||
await requestor.send(page)
|
await requestor.send(page)
|
||||||
book = Book(pag, (None, admin_channel, self.bot, ctx.message))
|
book = Book(pag, (None, admin_channel, self.bot, ctx.message))
|
||||||
await book.create_book()
|
await book.create_book()
|
||||||
await ctx.send(f'{ctx.author.mention} Your comment has been added to the request.')
|
await ctx.send(
|
||||||
|
f"{ctx.author.mention} Your comment has been added to the request."
|
||||||
|
)
|
||||||
|
|
||||||
@commands.command(name='requests_list', aliases=['rl'])
|
@commands.command(name="requests_list", aliases=["rl"])
|
||||||
async def _requests_list(self, ctx, closed: str = ''):
|
async def _requests_list(self, ctx, closed: str = ""):
|
||||||
pag = Paginator(self.bot)
|
pag = Paginator(self.bot)
|
||||||
admin_roles_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/', headers=self.bot.auth_header)
|
admin_roles_resp = await self.bot.aio_session.get(
|
||||||
|
f"{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if admin_roles_resp.status == 200:
|
if admin_roles_resp.status == 200:
|
||||||
admin_roles_data = await admin_roles_resp.json()
|
admin_roles_data = await admin_roles_resp.json()
|
||||||
admin_roles = [ctx.guild.get_role(int(role['id'])) for role in admin_roles_data]
|
admin_roles = [
|
||||||
|
ctx.guild.get_role(int(role["id"])) for role in admin_roles_data
|
||||||
|
]
|
||||||
if any([role in ctx.author.roles for role in admin_roles]):
|
if any([role in ctx.author.roles for role in admin_roles]):
|
||||||
requests_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/', headers=self.bot.auth_header)
|
|
||||||
if requests_resp.status == 200:
|
|
||||||
requests_data = await requests_resp.json()
|
|
||||||
requests_list = requests_data['requests'] if isinstance(requests_data, dict) else requests_data
|
|
||||||
while isinstance(requests_data, dict) and requests_data.get('next'):
|
|
||||||
requests_resp = await self.bot.aio_session.get(
|
requests_resp = await self.bot.aio_session.get(
|
||||||
requests_data['next'], headers=self.bot.auth_header)
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if requests_resp.status == 200:
|
if requests_resp.status == 200:
|
||||||
requests_data = await requests_resp.json()
|
requests_data = await requests_resp.json()
|
||||||
requests_list.extend(requests_data['requests'] if isinstance(requests_data, dict) else requests_data)
|
requests_list = (
|
||||||
for request in requests_list:
|
requests_data["requests"]
|
||||||
member = discord.utils.get(ctx.guild.members, id=int(request['author']))
|
if isinstance(requests_data, dict)
|
||||||
title = (f"<{'Request ID':^20} {'Requested By':^20}>\n"
|
else requests_data
|
||||||
f"<{request['id']:^20} {member.display_name if member else 'None':^20}>")
|
)
|
||||||
orig_channel = ctx.guild.get_channel(int(request.get('channel')))
|
while isinstance(requests_data, dict) and requests_data.get("next"):
|
||||||
comments_count_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request["id"]}/comments/count/', headers=self.bot.auth_header)
|
|
||||||
pag.add(f"\n\n{title}\n"
|
|
||||||
f"{request['content']}\n\n"
|
|
||||||
f"Comments: {await comments_count_resp.text() if comments_count_resp.status == 200 else 0}\n"
|
|
||||||
f"Requested at: "
|
|
||||||
f"{request['requested_at'].split('.')[0].replace('T', ' ')} GMT\n"
|
|
||||||
f"In {orig_channel.name if orig_channel else 'N/A'}", keep_intact=True)
|
|
||||||
pag.add(f'\n\uFFF8\nThere are currently {len(requests_list)} requests open.')
|
|
||||||
else:
|
|
||||||
pag.add('There are no open requests for this guild.', keep_intact=True)
|
|
||||||
else:
|
|
||||||
requests_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/user/{ctx.author.id}/',
|
|
||||||
headers=self.bot.auth_header)
|
|
||||||
if requests_resp.status == 200:
|
|
||||||
requests_data = await requests_resp.json()
|
|
||||||
requests_list = requests_data['requests'] if isinstance(requests_data, dict) else requests_data
|
|
||||||
while isinstance(requests_data, dict) and requests_data.get('next'):
|
|
||||||
requests_resp = await self.bot.aio_session.get(
|
requests_resp = await self.bot.aio_session.get(
|
||||||
requests_data['next'], headers=self.bot.auth_header)
|
requests_data["next"], headers=self.bot.auth_header
|
||||||
|
)
|
||||||
if requests_resp.status == 200:
|
if requests_resp.status == 200:
|
||||||
requests_data = await requests_resp.json()
|
requests_data = await requests_resp.json()
|
||||||
requests_list.extend(
|
requests_list.extend(
|
||||||
requests_data['requests'] if isinstance(requests_data, dict) else requests_data)
|
requests_data["requests"]
|
||||||
|
if isinstance(requests_data, dict)
|
||||||
|
else requests_data
|
||||||
|
)
|
||||||
for request in requests_list:
|
for request in requests_list:
|
||||||
title = (f"<{'Request ID':^20}>\n"
|
member = await ctx.guild.fetch_member(int(request["author"]))
|
||||||
f"<{request['id']:^20}>")
|
title = (
|
||||||
orig_channel = ctx.guild.get_channel(int(request.get('channel')))
|
f"<{'Request ID':^20} {'Requested By':^20}>\n"
|
||||||
|
f"<{request['id']:^20} {member.display_name if member else 'None':^20}>"
|
||||||
|
)
|
||||||
|
orig_channel = ctx.guild.get_channel(
|
||||||
|
int(request.get("channel"))
|
||||||
|
)
|
||||||
comments_count_resp = await self.bot.aio_session.get(
|
comments_count_resp = await self.bot.aio_session.get(
|
||||||
f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request["id"]}/comments/count/',
|
f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request["id"]}/comments/count/',
|
||||||
headers=self.bot.auth_header)
|
headers=self.bot.auth_header,
|
||||||
pag.add(f"\n\n{title}\n"
|
)
|
||||||
|
pag.add(
|
||||||
|
f"\n\n{title}\n"
|
||||||
f"{request['content']}\n\n"
|
f"{request['content']}\n\n"
|
||||||
f"Comments: {await comments_count_resp.text() if comments_count_resp.status == 200 else 0}\n"
|
f"Comments: {await comments_count_resp.text() if comments_count_resp.status == 200 else 0}\n"
|
||||||
f"Requested at: "
|
f"Requested at: "
|
||||||
f"{request['requested_at'].split('.')[0].replace('T', ' ')} GMT\n"
|
f"{request['requested_at'].split('.')[0].replace('T', ' ')} GMT\n"
|
||||||
f"In {orig_channel.name if orig_channel else 'N/A'}", keep_intact=True)
|
f"In {orig_channel.name if orig_channel else 'N/A'}",
|
||||||
pag.add(f'\n\uFFF8\nYou currently have {len(requests_list)} requests open.')
|
keep_intact=True,
|
||||||
|
)
|
||||||
|
pag.add(
|
||||||
|
f"\n\uFFF8\nThere are currently {len(requests_list)} requests open."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
pag.add('You have no open requests for this guild.', keep_intact=True)
|
pag.add(
|
||||||
|
"There are no open requests for this guild.", keep_intact=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
requests_resp = await self.bot.aio_session.get(
|
||||||
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/user/{ctx.author.id}/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
|
if requests_resp.status == 200:
|
||||||
|
requests_data = await requests_resp.json()
|
||||||
|
requests_list = (
|
||||||
|
requests_data["requests"]
|
||||||
|
if isinstance(requests_data, dict)
|
||||||
|
else requests_data
|
||||||
|
)
|
||||||
|
while isinstance(requests_data, dict) and requests_data.get("next"):
|
||||||
|
requests_resp = await self.bot.aio_session.get(
|
||||||
|
requests_data["next"], headers=self.bot.auth_header
|
||||||
|
)
|
||||||
|
if requests_resp.status == 200:
|
||||||
|
requests_data = await requests_resp.json()
|
||||||
|
requests_list.extend(
|
||||||
|
requests_data["requests"]
|
||||||
|
if isinstance(requests_data, dict)
|
||||||
|
else requests_data
|
||||||
|
)
|
||||||
|
for request in requests_list:
|
||||||
|
title = f"<{'Request ID':^20}>\n" f"<{request['id']:^20}>"
|
||||||
|
orig_channel = ctx.guild.get_channel(
|
||||||
|
int(request.get("channel"))
|
||||||
|
)
|
||||||
|
comments_count_resp = await self.bot.aio_session.get(
|
||||||
|
f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{request["id"]}/comments/count/',
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
|
pag.add(
|
||||||
|
f"\n\n{title}\n"
|
||||||
|
f"{request['content']}\n\n"
|
||||||
|
f"Comments: {await comments_count_resp.text() if comments_count_resp.status == 200 else 0}\n"
|
||||||
|
f"Requested at: "
|
||||||
|
f"{request['requested_at'].split('.')[0].replace('T', ' ')} GMT\n"
|
||||||
|
f"In {orig_channel.name if orig_channel else 'N/A'}",
|
||||||
|
keep_intact=True,
|
||||||
|
)
|
||||||
|
pag.add(
|
||||||
|
f"\n\uFFF8\nYou currently have {len(requests_list)} requests open."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
pag.add(
|
||||||
|
"You have no open requests for this guild.", keep_intact=True
|
||||||
|
)
|
||||||
for page in pag.pages():
|
for page in pag.pages():
|
||||||
await ctx.send(page)
|
await ctx.send(page)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def close(self, ctx, *, ids=None):
|
async def close(self, ctx, *, ids=None):
|
||||||
if not ids:
|
if not ids:
|
||||||
await ctx.send('Please include at least one Request ID to close.')
|
await ctx.send("Please include at least one Request ID to close.")
|
||||||
return
|
return
|
||||||
|
|
||||||
admin = False
|
admin = False
|
||||||
admin_roles_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/',
|
admin_roles_resp = await self.bot.aio_session.get(
|
||||||
headers=self.bot.auth_header)
|
f"{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if admin_roles_resp.status == 200:
|
if admin_roles_resp.status == 200:
|
||||||
admin_roles_data = await admin_roles_resp.json()
|
admin_roles_data = await admin_roles_resp.json()
|
||||||
admin_roles = [ctx.guild.get_role(int(role['id'])) for role in admin_roles_data]
|
admin_roles = [
|
||||||
|
ctx.guild.get_role(int(role["id"])) for role in admin_roles_data
|
||||||
|
]
|
||||||
if any([role in ctx.author.roles for role in admin_roles]):
|
if any([role in ctx.author.roles for role in admin_roles]):
|
||||||
admin = True
|
admin = True
|
||||||
|
|
||||||
ids = [id.strip() for id in ids.replace(' ', '').split(',')]
|
ids = [id.strip() for id in ids.replace(" ", "").split(",")]
|
||||||
|
|
||||||
for id in ids:
|
for id in ids:
|
||||||
request_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{id}/', headers=self.bot.auth_header)
|
request_resp = await self.bot.aio_session.get(
|
||||||
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/{id}/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if request_resp.status == 200:
|
if request_resp.status == 200:
|
||||||
request = await request_resp.json()
|
request = await request_resp.json()
|
||||||
requestor = ctx.guild.get_member(int(request['author']))
|
requestor = await ctx.guild.fetch_member(int(request["author"]))
|
||||||
if requestor == ctx.author or admin:
|
if requestor == ctx.author or admin:
|
||||||
data = {
|
data = {"completed_by": ctx.author.id}
|
||||||
'completed_by': ctx.author.id
|
delete_resp = await self.bot.aio_session.delete(
|
||||||
}
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/{id}/",
|
||||||
delete_resp = await self.bot.aio_session.delete(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{id}/', headers=self.bot.auth_header, json=data)
|
headers=self.bot.auth_header,
|
||||||
|
json=data,
|
||||||
|
)
|
||||||
if delete_resp.status == 202:
|
if delete_resp.status == 202:
|
||||||
delete_data = await delete_resp.json()
|
delete_data = await delete_resp.json()
|
||||||
if delete_data['completed']:
|
if delete_data["completed"]:
|
||||||
await ctx.send(f'Request {id} closed.')
|
await ctx.send(f"Request {id} closed.")
|
||||||
await requestor.send(f'{ctx.author.display_name} has closed request {id} which was '
|
await requestor.send(
|
||||||
f'opened by you in the '
|
f"{ctx.author.display_name} has closed request {id} which was "
|
||||||
|
f"opened by you in the "
|
||||||
f'{ctx.guild.get_channel(int(request["channel"])).name} '
|
f'{ctx.guild.get_channel(int(request["channel"])).name} '
|
||||||
f'channel.'
|
f"channel."
|
||||||
f'```{request["content"]}```'
|
f'```{request["content"]}```'
|
||||||
f'If there are any issues please open a new request.')
|
f"If there are any issues please open a new request."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await ctx.send('That is not your request to close.')
|
await ctx.send("That is not your request to close.")
|
||||||
|
|
||||||
@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 the id of the request you would like to view.')
|
await ctx.send(
|
||||||
|
"Please include the id of the request you would like to view."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
admin = False
|
admin = False
|
||||||
admin_roles_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/',
|
admin_roles_resp = await self.bot.aio_session.get(
|
||||||
headers=self.bot.auth_header)
|
f"{self.bot.api_base}/guilds/{ctx.guild.id}/roles/admin/",
|
||||||
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if admin_roles_resp.status == 200:
|
if admin_roles_resp.status == 200:
|
||||||
admin_roles_data = await admin_roles_resp.json()
|
admin_roles_data = await admin_roles_resp.json()
|
||||||
admin_roles = [ctx.guild.get_role(int(role['id'])) for role in admin_roles_data]
|
admin_roles = [
|
||||||
|
ctx.guild.get_role(int(role["id"])) for role in admin_roles_data
|
||||||
|
]
|
||||||
if any([role in ctx.author.roles for role in admin_roles]):
|
if any([role in ctx.author.roles for role in admin_roles]):
|
||||||
admin = True
|
admin = True
|
||||||
|
|
||||||
|
request_resp = await self.bot.aio_session.get(
|
||||||
request_resp = await self.bot.aio_session.get(f'{self.bot.api_base}/messages/{ctx.guild.id}/requests/{id}/',
|
f"{self.bot.api_base}/messages/{ctx.guild.id}/requests/{id}/",
|
||||||
headers=self.bot.auth_header)
|
headers=self.bot.auth_header,
|
||||||
|
)
|
||||||
if request_resp.status == 200:
|
if request_resp.status == 200:
|
||||||
request = await request_resp.json()
|
request = await request_resp.json()
|
||||||
requestor = ctx.guild.get_member(int(request['author']))
|
requestor = await ctx.guild.fetch_member(int(request["author"]))
|
||||||
if requestor == ctx.author or admin:
|
if requestor == ctx.author or admin:
|
||||||
pag = Paginator(self.bot, prefix='```md', suffix='```')
|
pag = Paginator(self.bot, prefix="```md", suffix="```")
|
||||||
header = (f'Request {id} by {requestor.mention if requestor else "`User cannot be found`"}:\n'
|
header = (
|
||||||
f'```{request["content"]}```')
|
f'Request {id} by {requestor.mention if requestor else "`User cannot be found`"}:\n'
|
||||||
|
f'```{request["content"]}```'
|
||||||
|
)
|
||||||
pag.set_header(header)
|
pag.set_header(header)
|
||||||
|
|
||||||
if request.get('comments'):
|
if request.get("comments"):
|
||||||
pag.add('Comments: \n')
|
pag.add("Comments: \n")
|
||||||
comments = request['comments']
|
comments = request["comments"]
|
||||||
for comment in comments:
|
for comment in comments:
|
||||||
author = ctx.guild.get_member(int(comment['author']))
|
author = await ctx.guild.fetch_member(int(comment["author"]))
|
||||||
pag.add(f'{author.display_name}: {comment["content"]}', keep_intact=True)
|
pag.add(
|
||||||
|
f'{author.display_name}: {comment["content"]}',
|
||||||
|
keep_intact=True,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
pag.add('No Comments')
|
pag.add("No Comments")
|
||||||
|
|
||||||
if request.get('completed'):
|
if request.get("completed"):
|
||||||
closer = ctx.guild.get_member(int(request.get('completed_by')))
|
closer = await ctx.guild.fetch_member(
|
||||||
pag.add(f'Closed By: {closer.name}#{closer.discriminator}\n{request.get("completed_message")}')
|
int(request.get("completed_by"))
|
||||||
|
)
|
||||||
|
pag.add(
|
||||||
|
f'Closed By: {closer.name}#{closer.discriminator}\n{request.get("completed_message")}'
|
||||||
|
)
|
||||||
book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
|
book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
|
||||||
await book.create_book()
|
await book.create_book()
|
||||||
else:
|
else:
|
||||||
await ctx.send('That is not your request to close.')
|
await ctx.send("That is not your request to close.")
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user