Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabby garf patch 1 #3

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<h1 align="center">📝 Discord Scraper 📝</h1>
<h3 align="center">Scrapes messages in chanel</h3>
<h4 align="center">⭐ Don't forget to leave a star! ⭐</h4>

<h5 align="center">🔩 V2 Coming soon! 🔩</h4>
<h3 align="center">Scrapes messages in channel or private message.</h3>

<h3 align="center" color="red">DUE TO DISCORDPY BEING BITCHES AND REMOVING ABILITY TO SELF BOT, THIS SCRAPER DOESNT WORK ANYMORE</h3>

## Installation:
1. Run `install.bat` or run in cmd `pip install -r _req.txt`
2. Config your token, prefix and command in `config.json`
## Usage:
1. Config settings and token in `config.json`
2. Open install.bat
3. Open start.bat
4. In channel write `!scrape <number of messages>`
5. Scraped messages will be saved in `scraped/name-of-channel`

## Settings:
![Settings Showcase](https://camo.githubusercontent.com/91fb91dbef076670a6791ffdea7bcf3591e36643/68747470733a2f2f7768657265732d6d792d74612e636f2f74504a58576c2e706e67)
1. Open start.bat
2. In channel/DM write `!scrape <number of messages>/all` or the command in your prompt
3. Scraped messages will be saved in `scrape/Guild Name/name-of-channel`
## Differences between original and fork
1. Shows progress in command prompt. (Scraped x out of y message(s))
2. Shows status in window title (waiting command, amount scraped on channel, done)
3. Customizable prefix and command! `default: !scrape`

## Showcase:
![Showcase](https://i.imgur.com/jQEmM9K.png)
![Showcase](https://ella-nelson.wheres-my-ta.co/5UmLAQpwz.png)

`WARN: Using a selfbot is against TOS, It's not my fault if you get a ban when someone reports you`
File renamed without changes.
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"token": "token-here"
"token": "token-here",
"prefix": "!",
"command": "scrape"
}
5 changes: 5 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
cls
title installing requirements
pip install -r _req.txt
pause
76 changes: 57 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,49 @@
import json
import os
import discord

from datetime import datetime

from discord.ext import (
commands,
tasks
)

with open("config.json") as f:
config = json.load(f)

token = config["token"]
cmd = config["command"]
command_prefix=config["prefix"]



client = discord.Client()
client = commands.Bot(
command_prefix="!",
command_prefix=config["prefix"],
self_bot=True
)
client.remove_command('help')

with open('config.json') as f:
config = json.load(f)

token = config.get("token")

os.system('cls')

print(f"{Fore.WHITE}[ {Fore.CYAN}§ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Discord Chat Scraper made by {Fore.WHITE}LnX{Fore.LIGHTBLACK_EX} | Licensed under {Fore.WHITE}MIT {Fore.LIGHTBLACK_EX}License")
print(f"{Fore.WHITE}[ {Fore.CYAN}§ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}You can follow me on Github: {Fore.WHITE}https://github.com/lnxcz")
print(f"{Fore.WHITE}[ {Fore.CYAN}§ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Discord Chat Scraper made by {Fore.CYAN}LnX{Fore.LIGHTBLACK_EX}, fork by {Fore.YELLOW}TabbyGarf{Fore.LIGHTBLACK_EX}")
print(f"{Fore.WHITE}[ {Fore.CYAN}§ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Licensed under {Fore.WHITE}MIT {Fore.LIGHTBLACK_EX}License")
print(f"{Fore.WHITE}[ {Fore.CYAN}§ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}You can follow LnX on Github: {Fore.WHITE}https://github.com/lnxcz")
print(f"{Fore.WHITE}[ {Fore.CYAN}§ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}You can follow me there too: {Fore.WHITE}https://github.com/TabbyGarf")

print(f"\n{Fore.WHITE}[ {Fore.GREEN}+ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Bot is ready!")
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Write {Fore.WHITE}!scrape <number of messages>{Fore.LIGHTBLACK_EX} to log messages\n")
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Write {Fore.YELLOW}{command_prefix}{Fore.CYAN}{cmd}{Fore.WHITE} <number of messages>{Fore.LIGHTBLACK_EX} to log messages\n")
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Write {Fore.YELLOW}{command_prefix}{Fore.CYAN}{cmd}{Fore.WHITE} all{Fore.LIGHTBLACK_EX} to log every message\n")
os.system("title awaiting command")

def Init():
if config.get('token') == "token-here":
if config["token"] == "token-here":
os.system('cls')
print(f"\n\n{Fore.WHITE}[ {Fore.RED}E {Fore.WHITE}] {Fore.LIGHTBLACK_EX}You didnt put your token in the config.json file\n\n"+Fore.RESET)
exit()
else:
token = config.get('token')
token = config["token"]
try:
client.run(token, bot=False, reconnect=True)
os.system(f'Discord message scraper')
Expand All @@ -45,26 +53,56 @@ def Init():
exit()


@client.command()
async def scrape(ctx, amount: int):
f = open(f"scraped/{ctx.message.channel}.txt","w+", encoding="UTF-8")
total = amount
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Scraping {Fore.WHITE}{amount}{Fore.LIGHTBLACK_EX} messages to {Fore.WHITE}scraped/{ctx.message.channel}.txt{Fore.LIGHTBLACK_EX}!")
async for message in ctx.message.channel.history(limit=amount):
@client.command(name=cmd)
async def scrape(ctx, amount: str):
time = datetime.now()
ft = time.strftime("%Y%m%d-%H%M%S")
if (ctx.message.guild != None):
filename = "scraped/{}/{}-{}.txt".format(ctx.message.guild.name,ctx.message.channel,ft)
else:
filename = "scraped/Direct Messages/{}-{}.txt".format(ctx.message.channel,ft)
os.makedirs(os.path.dirname(filename), exist_ok=True)
f = open(filename, "w+", encoding = "UTF-8")
count = 1

if amount == "all":
all = True
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Counting the amount of messages, this might take a while...")
os.system("title counting messages...")
amount = len([m async for m in ctx.message.channel.history(limit=None)])

else:
all = False
amount = int(amount)
total = int(amount)

if all == True:
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Scraping {Fore.WHITE}all{Fore.LIGHTBLACK_EX} messages to {Fore.WHITE}{filename}{Fore.LIGHTBLACK_EX}!")
else:
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Scraping {Fore.WHITE}{amount}{Fore.LIGHTBLACK_EX} messages to {Fore.WHITE}{filename}{Fore.LIGHTBLACK_EX}!")
async for message in ctx.message.channel.history(limit=amount, oldest_first=False):
attachments = [attachment.url for attachment in message.attachments if message.attachments]
try:
if attachments:
realatt = attachments[0]
f.write(f"({message.created_at}) {message.author}: {message.content} ({realatt})\n")
print(f"{Fore.WHITE}[ {Fore.GREEN}+ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Scraped message")
print(f"{Fore.WHITE}[ {Fore.GREEN}+ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Scraped {count} out of {total} message(s)")
else:
f.write(f"({message.created_at}) {message.author}: {message.content}\n")
print(f"{Fore.WHITE}[ {Fore.GREEN}+ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Scraped message")
print(f"{Fore.WHITE}[ {Fore.GREEN}+ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Scraped {count} out of {total} message(s)")
except Exception as e:
print(f"{Fore.WHITE}[ {Fore.RED}- {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Cannot scrape message from {Fore.WHITE}{message.author}")
print(f"{Fore.WHITE}[ {Fore.RED}E {Fore.WHITE}] {Fore.LIGHTBLACK_EX} {Fore.WHITE}{e}")
total = total - 1
os.system("title [{}/{}] scraping {}".format(count,total,ctx.message.channel))
count = count + 1
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Succesfully scraped {Fore.WHITE}{total} {Fore.LIGHTBLACK_EX}messages!\n\n{Fore.WHITE}")
os.system("title [DONE] - awaiting command".format(total))
print(f"\n{Fore.WHITE}[ {Fore.GREEN}+ {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Bot is ready!")
print(f"{Fore.WHITE}[ {Fore.YELLOW}? {Fore.WHITE}] {Fore.LIGHTBLACK_EX}Write {Fore.YELLOW}{command_prefix}{Fore.CYAN}{cmd}{Fore.WHITE} <number of messages>{Fore.LIGHTBLACK_EX} to log messages\n")





@client.event
Expand Down