Repository navigation
Expand file tree
/
Copy pathdiscordJson.py
More file actions
143 lines (119 loc) · 4.69 KB
/
Copy pathdiscordJson.py
File metadata and controls
143 lines (119 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import gzip
import re
import os
import json
import shutil
import errno
from pathlib import Path
import scripts.artifacts.artGlobals
from packaging import version
from scripts.artifact_report import ArtifactHtmlReport
from scripts.ilapfuncs import logfunc, logdevinfo, timeline, tsv, is_platform_windows
def get_discordJson(files_found, report_folder, seeker, wrap_text):
data_list = []
for file_found in files_found:
file_found = str(file_found)
#logfunc(file_found)
pathed = file_found
try:
if os.path.isfile(file_found):
with open(file_found) as f_in:
for jsondata in f_in:
#jsondata = jsondata[1:-1]
jsonfinal = json.loads(jsondata)
#print (jsonfinal)
x = 0
emdeddedauthor = ''
authorurl = ''
authoriconurl = ''
embededurl = ''
embededurl = ''
embededdescript = ''
footertext = ''
footericonurl = ''
listlength = len(jsonfinal)
if isinstance(jsonfinal, list):
while x < listlength:
if 'author' in jsonfinal[x]:
username = (jsonfinal[x]['author']['username'])
userid = (jsonfinal[x]['author']['id'])
if 'bot' in jsonfinal[x]['author']:
botuser = (jsonfinal[x]['author']['bot'])
else:
botuser = ''
if 'timestamp' in jsonfinal[x]:
timestamp = (jsonfinal[x]['timestamp'])
if 'edited_timestamp' in jsonfinal[x]:
editedtimestamp = (jsonfinal[x]['edited_timestamp'])
if 'content' in jsonfinal[x]:
content = jsonfinal[x]['content']
if 'channel_id' in jsonfinal[x]:
channelid = jsonfinal[x]['channel_id']
if 'attachments' in jsonfinal[x]:
attachments = jsonfinal[x]['attachments']
if len(attachments) > 0:
string = (attachments[0]['url'])
attachments = string
else:
attachments = ''
if 'embeds' in jsonfinal[x]:
if len(jsonfinal[x]['embeds']) > 0:
y = 0
lenembeds = (len(jsonfinal[x]['embeds']))
while y < lenembeds:
#print(jsonfinal[x]['embeds'])
if 'url' in jsonfinal[x]['embeds'][y]:
embededurl = (jsonfinal[x]['embeds'][y]['url'])
else:
embededurl = ''
if 'description' in jsonfinal[x]['embeds'][y]:
embededdescript = (jsonfinal[x]['embeds'][y]['description'])
else:
embededdescript = ''
if 'author' in jsonfinal[x]['embeds'][y]:
emdeddedauthor = (jsonfinal[x]['embeds'][y]['author']['name'])
if 'url' in jsonfinal[x]['embeds'][y]['author']:
authorurl = (jsonfinal[x]['embeds'][y]['author']['url'])
else:
authorurl = ''
if 'icon_url' in jsonfinal[x]['embeds'][y]['author']:
authoriconurl =(jsonfinal[x]['embeds'][y]['author']['icon_url'])
else:
authoriconurl = ''
else:
emdeddedauthor = ''
if 'footer' in jsonfinal[x]['embeds']:
footertext = (jsonfinal[x]['embeds'][y]['footer']['text'])
footericonurl = (jsonfinal[x]['embeds'][y]['footer']['icon_url'])
else:
footertext = ''
footericonurl = ''
y = y + 1
pathedhead, pathedtail = os.path.split(pathed)
data_list.append((timestamp, editedtimestamp, username, botuser, content, attachments, userid, channelid, emdeddedauthor, authorurl, authoriconurl, embededurl, embededdescript, footertext, footericonurl, pathedtail))
x = x + 1
else:
pass
#logfunc('JSON data is no expected list')
except ValueError as e:
pass
#logfunc('JSON error: %s' % e)
#logfunc('')
if len(data_list) > 0:
logfunc(f'Files found:{len(files_found)}')
report = ArtifactHtmlReport('Discord Messages')
report.start_artifact_report(report_folder, 'Discord Messages')
report.add_script()
data_headers = ('Timestamp','Edited Timestamp','Username','Bot?','Content','Attachments','User ID','Channel ID','Embedded Author','Author URL','Author Icon URL','Embedded URL','Embedded Script','Footer Text', 'Footer Icon URL', 'Source File')
report.write_artifact_data_table(data_headers, data_list, pathedhead)
report.end_artifact_report()
tsvname = 'Discord Messages'
tsv(report_folder, data_headers, data_list, tsvname)
tlactivity = 'Discord Messages'
timeline(report_folder, tlactivity, data_list, data_headers)
__artifacts__ = {
"discordjson": (
"Discord",
('*/com.hammerandchisel.discord/fsCachedData/*'),
get_discordJson)
}