Created
January 3, 2020 00:44
-
-
Save joshdabosh/87878313b4f860a502b31890df4f9bf4 to your computer and use it in GitHub Desktop.
Downloads any images sent over Discord. Technically a violation of Discord ToS. Use carefully.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import discord | |
import asyncio | |
import json | |
import os | |
import re | |
import requests | |
info = {"email":"REDACT", | |
"password":"REDACT"} | |
client = discord.Client() | |
@client.async_event | |
async def on_ready(): | |
os.system("clear") | |
print("Logged in as {}, with ID {}".format(client.user.name, client.user.id)) | |
@client.async_event | |
async def on_message(message): | |
if (not message.channel.is_private) and ((message.embeds) or (message.attachments)): | |
name = str(message.server.name)+'/'+str(message.channel.name) | |
if message.embeds: | |
for pic in message.embeds: | |
thing = str(pic['url']).split('/') | |
await download(str(pic["url"]), str(name), str(thing[-1].split('.')[0]), str(thing[-1].split('.')[-1])) | |
elif message.attachments: | |
for pic in message.attachments: | |
thing = str(pic['url']).split('/') | |
await download(str(pic["url"]), str(name), str(thing[-1].split('.')[0]), str(thing[-1].split('.')[-1])) | |
else: | |
return | |
elif (message.channel.is_private) and (message.embeds or message.attachments): | |
name = 'pms\\'+str(message.channel.user) | |
if message.embeds: | |
for pic in message.embeds: | |
thing = str(pic['url']).split('/') | |
await download(str(pic['url']), str(name), str(thing[-1].split('.')[-2]), str(thing[-1].split('.')[-1])) | |
elif message.attachments: | |
for pic in message.attachments: | |
thing = str(pic['url']).split('/') | |
await download(str(pic['url']), str(name), str(thing[-1].split('.')[-2]), str(thing[-1].split('.')[-1])) | |
else: | |
return | |
async def download(url, path, f_name, f_type): | |
path = path.replace(" ", "-") | |
if f_type.lower() in ["exe","js","bat"]: | |
return | |
if not os.path.exists("./downloaded/"+path): | |
os.makedirs("./downloaded/"+path) | |
headers = { | |
'User-agent': 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0' | |
} | |
r = requests.get(url, headers=headers, stream=True) | |
with open("./downloaded/{}/{}.{}".format(path, str(f_name), str(f_type)), "wb") as f: | |
for chunk in r.iter_content(chunk_size=1024): | |
if chunk: | |
f.write(chunk) | |
client.run(info["email"], info["password"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment