Skip to content

Commit 6df9a66

Browse files
authored
Merge pull request #1 from vertyco/main
Merge from fork
2 parents 08aab20 + 0fe4d51 commit 6df9a66

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

tickets/common/utils.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections import defaultdict
55
from contextlib import suppress
66
from datetime import datetime
7-
from io import BytesIO
7+
from io import BytesIO, StringIO
88
from pathlib import Path
99
from typing import List, Optional, Union
1010

@@ -14,7 +14,7 @@
1414
from redbot.core import Config, commands
1515
from redbot.core.bot import Red
1616
from redbot.core.i18n import Translator
17-
from redbot.core.utils.chat_formatting import humanize_list, pagify, text_to_file
17+
from redbot.core.utils.chat_formatting import pagify, text_to_file
1818
from redbot.core.utils.mod import is_admin_or_superior
1919

2020
LOADING = "https://i.imgur.com/l3p6EMX.gif"
@@ -138,9 +138,9 @@ async def close_ticket(
138138
color=discord.Color.green(),
139139
)
140140
embed.set_thumbnail(url=pfp)
141-
log_chan = guild.get_channel(panel["log_channel"]) if panel["log_channel"] else None
141+
log_chan: discord.TextChannel = guild.get_channel(panel["log_channel"]) if panel["log_channel"] else None
142142

143-
text = ""
143+
buffer = StringIO()
144144
files: List[dict] = []
145145
filename = (
146146
f"{member.name}-{member.id}.html" if conf.get("detailed_transcript") else f"{member.name}-{member.id}.txt"
@@ -153,14 +153,14 @@ async def close_ticket(
153153

154154
use_exporter = conf.get("detailed_transcript", False)
155155
is_thread = isinstance(channel, discord.Thread)
156-
exporter_success = False
156+
# exporter_success = False
157157

158158
if conf["transcript"]:
159159
temp_message = await channel.send(embed=em)
160160

161161
if use_exporter:
162162
try:
163-
text = await chat_exporter.export(
163+
res = await chat_exporter.export(
164164
channel=channel,
165165
limit=None,
166166
tz_info="UTC",
@@ -170,14 +170,15 @@ async def close_ticket(
170170
fancy_times=True,
171171
support_dev=False,
172172
)
173-
exporter_success = True
173+
buffer.write(res)
174+
# exporter_success = True
174175
except AttributeError:
175176
pass
176177

177178
answers = ticket.get("answers")
178179
if answers and not use_exporter:
179180
for q, a in answers.items():
180-
text += _("Question: {}\nResponse: {}\n").format(q, a)
181+
buffer.write(_("Question: {}\nResponse: {}\n").format(q, a))
181182

182183
history = await fetch_channel_history(channel)
183184
filenames = defaultdict(int)
@@ -187,9 +188,9 @@ async def close_ticket(
187188
if not msg:
188189
continue
189190

190-
att = []
191+
att: list[discord.Attachment] = []
191192
for i in msg.attachments:
192-
att.append(i.filename)
193+
att.append(i)
193194
if i.size < guild.filesize_limit and (not is_thread or conf["thread_close"]):
194195
filenames[i.filename] += 1
195196
if filenames[i.filename] > 1:
@@ -201,9 +202,13 @@ async def close_ticket(
201202

202203
if not use_exporter:
203204
if msg.content:
204-
text += f"{msg.author.name}: {msg.content}\n"
205+
buffer.write(
206+
f"{msg.created_at.strftime('%m-%d-%Y %I:%M:%S %p')} - {msg.author.name}: {msg.content}\n"
207+
)
205208
if att:
206-
text += _("Files uploaded: ") + humanize_list(att) + "\n"
209+
buffer.write(_("Files Uploaded:\n"))
210+
for i in att:
211+
buffer.write(f"[{i.filename}]({i.url})\n")
207212

208213
with suppress(discord.HTTPException):
209214
await temp_message.delete()
@@ -243,6 +248,8 @@ def zip_files():
243248

244249
view_label = _("View Transcript")
245250

251+
text = buffer.getvalue()
252+
246253
if log_chan and ticket["logmsg"]:
247254
text_file = text_to_file(text, filename) if text else None
248255
zip_file = discord.File(BytesIO(zip_bytes), filename="attachments.zip") if zip_bytes else None
@@ -295,11 +302,11 @@ def zip_files():
295302
else:
296303
raise
297304

298-
if log_msg and exporter_success:
299-
url = f"https://mahto.id/chat-exporter?url={log_msg.attachments[0].url}"
300-
view = discord.ui.View()
301-
view.add_item(discord.ui.Button(label=view_label, style=discord.ButtonStyle.link, url=url))
302-
await log_msg.edit(view=view)
305+
# if log_msg and exporter_success:
306+
# url = f"https://mahto.id/chat-exporter?url={log_msg.attachments[0].url}"
307+
# view = discord.ui.View()
308+
# view.add_item(discord.ui.Button(label=view_label, style=discord.ButtonStyle.link, url=url))
309+
# await log_msg.edit(view=view)
303310

304311
# Delete old log msg
305312
log_msg_id = ticket["logmsg"]

tickets/tickets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Tickets(TicketCommands, Functions, commands.Cog, metaclass=CompositeMetaCl
3434
"""
3535

3636
__author__ = "[vertyco](https://github.com/vertyco/vrt-cogs)"
37-
__version__ = "2.9.13"
37+
__version__ = "2.9.14"
3838

3939
def format_help_for_context(self, ctx):
4040
helpcmd = super().format_help_for_context(ctx)

0 commit comments

Comments
 (0)