Spaces:
Runtime error
Runtime error
plong95 commited on
Commit ·
e4f3b0e
1
Parent(s): 883e2a8
Initial commit
Browse files- README.md +39 -10
- exporter.py +70 -0
- links.md +1 -0
- messages.md +1 -0
- requirements.txt +5 -0
README.md
CHANGED
|
@@ -1,12 +1,41 @@
|
|
| 1 |
-
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
title: Discord-utility
|
| 2 |
+
emoji: 💬
|
| 3 |
+
colorFrom: "#7289da"
|
| 4 |
+
colorTo: "#7289da"
|
|
|
|
| 5 |
sdk: gradio
|
| 6 |
+
python_version: 3.8.9
|
| 7 |
+
sdk_version: 1.5.1
|
| 8 |
+
app_file: exporter.py
|
| 9 |
+
fullWidth: false
|
| 10 |
+
tags:
|
| 11 |
+
- Discord
|
| 12 |
+
- Export
|
| 13 |
+
- UI
|
| 14 |
+
pinned: true
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
## Discord-Utility Is A Discord Message Exporter
|
| 18 |
+
This Python script allows you to export every message a specific Discord user ever sent in DMs and every message they ever sent in a Discord server.
|
| 19 |
+
## Instructions to Run on your local PC
|
| 20 |
+
1. Install the required dependencies. You can do this by running the following command:
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
pip install -r requirements.txt
|
| 25 |
+
|
| 26 |
+
```
|
| 27 |
+
<ol start="2">Save the script in a file with the name `discord-exporter.py`.</li>Run the script by executing the following command:</li></ol>
|
| 28 |
+
```
|
| 29 |
+
python discord-exporter.py
|
| 30 |
+
|
| 31 |
+
```
|
| 32 |
+
<ol start="4">The Gradio interface will appear. Enter the Discord user ID, Discord bot token, and the output directory in the respective text boxes and click "Submit".</li>The script will then log in to the Discord client and start exporting messages. The exported messages will be saved in the output directory in two files: `messages.md` and `links.md`.</li>The script will log out of the Discord client and terminate.</li></ol>## Running in Debug Mode
|
| 33 |
+
If you want to run the script in debug mode, you can set the `DEBUG` variable to `True` at the top of the script like this:
|
| 34 |
+
|
| 35 |
+
```
|
| 36 |
+
DEBUG = True
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
When the script is run in debug mode, it will print additional information to the console, such as the messages being exported and the HTTP requests being made.
|
| 41 |
|
|
|
exporter.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import discord
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Set up Discord client
|
| 6 |
+
client = discord.Client()
|
| 7 |
+
|
| 8 |
+
# Set up UI
|
| 9 |
+
def get_input():
|
| 10 |
+
user_id = gr.inputs.Textbox(label="Discord user ID")
|
| 11 |
+
token = gr.inputs.Textbox(label="Discord bot token")
|
| 12 |
+
output_dir = gr.inputs.Textbox(label="Output directory")
|
| 13 |
+
return [user_id, token, output_dir]
|
| 14 |
+
|
| 15 |
+
def export_messages(user_id, token, output_dir):
|
| 16 |
+
# Log in to Discord client
|
| 17 |
+
@client.event
|
| 18 |
+
async def on_ready():
|
| 19 |
+
print(f"Logged in as {client.user}")
|
| 20 |
+
|
| 21 |
+
# Get user
|
| 22 |
+
user = await client.fetch_user(user_id)
|
| 23 |
+
|
| 24 |
+
# Export DMs
|
| 25 |
+
dms = await user.create_dm()
|
| 26 |
+
dm_messages = await dms.history(limit=None).flatten()
|
| 27 |
+
with open(os.path.join(output_dir, "messages.md"), "w", encoding="utf-8") as f:
|
| 28 |
+
for message in dm_messages:
|
| 29 |
+
f.write(f"[{message.created_at}] {message.author.name}: {message.content}\n")
|
| 30 |
+
|
| 31 |
+
# Export server messages with links
|
| 32 |
+
server_messages = []
|
| 33 |
+
for guild in client.guilds:
|
| 34 |
+
for channel in guild.text_channels:
|
| 35 |
+
async for message in channel.history(limit=None):
|
| 36 |
+
if message.author.id == user_id:
|
| 37 |
+
server_messages.append(message)
|
| 38 |
+
|
| 39 |
+
with open(os.path.join(output_dir, "links.md"), "w", encoding="utf-8") as f:
|
| 40 |
+
for message in server_messages:
|
| 41 |
+
if len(message.embeds) > 0:
|
| 42 |
+
for embed in message.embeds:
|
| 43 |
+
if "url" in embed:
|
| 44 |
+
f.write(f"[{message.created_at}] {message.author.name}: {message.content}\n")
|
| 45 |
+
f.write(f"- {embed.url}\n")
|
| 46 |
+
elif len(message.attachments) > 0:
|
| 47 |
+
for attachment in message.attachments:
|
| 48 |
+
if "url" in attachment:
|
| 49 |
+
f.write(f"[{message.created_at}] {message.author.name}: {message.content}\n")
|
| 50 |
+
f.write(f"- {attachment.url}\n")
|
| 51 |
+
else:
|
| 52 |
+
if "http" in message.content:
|
| 53 |
+
f.write(f"[{message.created_at}] {message.author.name}: {message.content}\n")
|
| 54 |
+
|
| 55 |
+
print("Export complete.")
|
| 56 |
+
|
| 57 |
+
# Log in to client
|
| 58 |
+
client.run(token)
|
| 59 |
+
|
| 60 |
+
iface = gr.Interface(
|
| 61 |
+
fn=export_messages,
|
| 62 |
+
inputs=get_input(),
|
| 63 |
+
outputs="text",
|
| 64 |
+
title="Discord Message Exporter",
|
| 65 |
+
description="Export every message a specific Discord user ever sent in DMs and every message they ever sent in a Discord server.",
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
iface.launch()
|
| 70 |
+
|
links.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
messages.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
discord==1.7.3
|
| 2 |
+
gradio==2.3.6
|
| 3 |
+
python-dotenv==0.19.0
|
| 4 |
+
requests==2.27.1
|
| 5 |
+
|