4f126c7def72d814bfc99981444106f524abbb5d
1 # Discord private message full removal script - public domain
4 # 1. Place this script next to the extracted package/ directory
5 # 2. Create auth.txt with your discord auth token in it
6 # 3. On the terminal enter:
7 # python3 delete-private.py
9 import os
, json
, csv
, atexit
, time
, requests
16 # =============================================================================
18 with
open( "auth.txt" ) as a
:
19 auth
= a
.readlines()[0].strip()
21 print( "Error: no auth.txt found" )
25 # =============================================================================
26 print( "Step 1/3: Resume state... ", end
="" )
29 with
open( "delete_total.txt", "w" ) as cur
:
30 cur
.write( str(delete_total
) )
32 atexit
.register(exit_handler
)
35 with
open( "delete_total.txt", "r" ) as cur
:
36 delete_total
= int(cur
.read())
39 print( "starting new" )
42 # =============================================================================
43 print( "Step 2/3: Collect messages... ", end
="" )
45 for d
in os
.listdir( "package/messages" ):
46 channel_path
= "package/messages/" + d
+ "/"
48 if os
.path
.isdir( channel_path
):
49 with
open( channel_path
+ "channel.json" ) as index
:
50 data
= json
.load( index
)
52 # Filter for non-public channel types, these are the only type of
53 # channels we are garunteed to have access to.
55 with
open( channel_path
+ "messages.csv" ) as messages
:
56 reader
= csv
.reader( messages
, delimiter
=',', quotechar
='"' )
60 all_messages
.append((data
["id"],row
[0]))
66 # =============================================================================
67 time_hours
= ((len(all_messages
)-delete_total
)*4)/60/60
69 print( "Step 3/3: Delete, ETA: {:.2f} hours".format(time_hours
) )
70 print( "===============================" )
72 while delete_total
< len( all_messages
):
73 percentage
= (delete_total
/ len(all_messages
)) * 100.0
75 print("{:.2f}% | Process message {} of {}: ".format(
76 percentage
, delete_total
, len(all_messages
)), end
=""
79 api_url
= "https://discord.com/api/v6/channels/{}/messages/{}".format(
80 all_messages
[ delete_total
][0], all_messages
[ delete_total
][1]
83 x
= requests
.delete( api_url
, headers
= { "Authorization": auth
} )
85 if x
.status_code
!= 204:
86 print( "ERROR: " + str(x
.status_code
) )
87 with
open( "failed_urls.txt", "a" ) as errs
:
88 errs
.write( "{},{}\n".format(x
.status_code
, api_url
) )
90 print( "204, deleted" )