Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -48,30 +48,30 @@ async def save_messages(ctx, channel_id: int):
|
|
48 |
@bot.command()
|
49 |
async def save_forum(ctx, channel_id: int):
|
50 |
channel = bot.get_channel(channel_id)
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
threads = {} # Dictionary to store messages by thread ID
|
56 |
|
57 |
-
async for message in channel.history(limit=None):
|
58 |
-
thread_id = message.reference.channel_id if message.reference else message.id
|
59 |
-
if thread_id not in threads:
|
60 |
-
threads[thread_id] = []
|
61 |
-
threads[thread_id].append(message)
|
62 |
|
63 |
-
with open("gradio-questions.json", 'w', encoding='utf-8') as file:
|
64 |
-
for thread_id, messages in threads.items():
|
65 |
-
file.write(f"Thread ID: {thread_id}\n")
|
66 |
-
for message in messages:
|
67 |
-
file.write(f"{message.content}\n")
|
68 |
-
file.write("\n")
|
69 |
|
70 |
-
await ctx.send(f"Forum messages from {channel.name} saved to file")
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
|
76 |
|
77 |
""""""
|
|
|
48 |
@bot.command()
|
49 |
async def save_forum(ctx, channel_id: int):
|
50 |
channel = bot.get_channel(channel_id)
|
51 |
+
threads = channel.threads
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
messages_data = []
|
56 |
+
async for message in thread.history(limit=None): # limit=None retrieves all messages
|
57 |
+
message_data = {
|
58 |
+
"content": message.content,
|
59 |
+
"author": message.author.name,
|
60 |
+
"timestamp": message.created_at.isoformat()
|
61 |
+
}
|
62 |
+
messages_data.append(message_data)
|
63 |
+
|
64 |
|
|
|
65 |
|
|
|
|
|
|
|
|
|
|
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
|
|
68 |
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
|
76 |
|
77 |
""""""
|