44from collections import defaultdict
55from contextlib import suppress
66from datetime import datetime
7- from io import BytesIO
7+ from io import BytesIO , StringIO
88from pathlib import Path
99from typing import List , Optional , Union
1010
1414from redbot .core import Config , commands
1515from redbot .core .bot import Red
1616from 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
1818from redbot .core .utils .mod import is_admin_or_superior
1919
2020LOADING = "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: {}\n Response: {}\n " ).format (q , a )
181+ buffer . write ( _ ("Question: {}\n Response: {}\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,11 @@ 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 ( f"{ msg .created_at . strftime ( '%Y-%m-%d %H:%M:%S' ) } - { msg . author .name } : { msg .content } \n " )
205206 if att :
206- text += _ ("Files uploaded: " ) + humanize_list (att ) + "\n "
207+ buffer .write (_ ("Files Uploaded:\n " ))
208+ for i in att :
209+ buffer .write (f"[{ i .filename } ]({ i .url } )\n " )
207210
208211 with suppress (discord .HTTPException ):
209212 await temp_message .delete ()
@@ -243,6 +246,8 @@ def zip_files():
243246
244247 view_label = _ ("View Transcript" )
245248
249+ text = buffer .getvalue ()
250+
246251 if log_chan and ticket ["logmsg" ]:
247252 text_file = text_to_file (text , filename ) if text else None
248253 zip_file = discord .File (BytesIO (zip_bytes ), filename = "attachments.zip" ) if zip_bytes else None
@@ -295,11 +300,11 @@ def zip_files():
295300 else :
296301 raise
297302
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 )
303+ # if log_msg and exporter_success:
304+ # url = f"https://mahto.id/chat-exporter?url={log_msg.attachments[0].url}"
305+ # view = discord.ui.View()
306+ # view.add_item(discord.ui.Button(label=view_label, style=discord.ButtonStyle.link, url=url))
307+ # await log_msg.edit(view=view)
303308
304309 # Delete old log msg
305310 log_msg_id = ticket ["logmsg" ]
0 commit comments