Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jordanwildon
GitHub Repository: jordanwildon/Telepathy
Path: blob/main/build/lib/telepathy/utils.py
201 views
1
from colorama import Fore, Style
2
from googletrans import Translator
3
from telepathy.const import __version__, user_agent
4
import requests
5
import textwrap
6
from bs4 import BeautifulSoup
7
import random
8
9
def createPlaceholdeCls():
10
class Object(object):
11
pass
12
a = Object()
13
return a
14
15
def print_banner():
16
print(
17
Fore.GREEN
18
+ """
19
______ __ __ __
20
/_ __/__ / /__ ____ ____ _/ /_/ /_ __ __
21
/ / / _ \/ / _ \/ __ \/ __ `/ __/ __ \/ / / /
22
/ / / __/ / __/ /_/ / /_/ / /_/ / / / /_/ /
23
/_/ \___/_/\___/ .___/\__,_/\__/_/ /_/\__, /
24
/_/ /____/
25
-- An OSINT toolkit for investigating Telegram chats.
26
-- Developed by @jordanwildon | Version """ + __version__ + """.
27
""" + Style.RESET_ALL
28
)
29
30
def parse_tg_date(dd):
31
year = str(format(dd.year, "02d"))
32
month = str(format(dd.month, "02d"))
33
day = str(format(dd.day, "02d"))
34
hour = str(format(dd.hour, "02d"))
35
minute = str(format(dd.minute, "02d"))
36
second = str(format(dd.second, "02d"))
37
date = year + "-" + month + "-" + day
38
mtime = hour + ":" + minute + ":" + second
39
timestamp = date + "T" + mtime + "+00:00"
40
return {"timestamp":timestamp, "date":date, "mtime":mtime}
41
42
43
def populate_user(user, group_or_chat):
44
if user.username:
45
username = user.username
46
else:
47
username = "N/A"
48
if user.first_name:
49
first_name = user.first_name
50
else:
51
first_name = ""
52
if user.last_name:
53
last_name = user.last_name
54
else:
55
last_name = ""
56
if user.phone:
57
phone = user.phone
58
else:
59
phone = "N/A"
60
if user.id:
61
user_id = user.id
62
else:
63
user_id = "N/A"
64
full_name = (first_name + " " + last_name).strip()
65
return [username, full_name, user_id, phone, group_or_chat]
66
67
68
def process_message(mess, user_lang):
69
70
if mess is not None:
71
mess_txt = '"' + mess + '"'
72
else:
73
mess_txt = "None"
74
75
if mess_txt != "None":
76
translator = Translator()
77
detection = translator.detect(mess_txt)
78
translation_confidence = detection.confidence
79
translation = translator.translate(mess_txt, dest=user_lang)
80
original_language = translation.src
81
translated_text = translation.text
82
else:
83
original_language = user_lang
84
translated_text = "N/A"
85
translation_confidence = "N/A"
86
87
return {
88
"original_language": original_language,
89
"translated_text": translated_text,
90
"translation_confidence": translation_confidence,
91
"message_text": mess_txt,
92
}
93
94
def process_description(desc, user_lang):
95
if desc is not None:
96
desc_txt = '"' + desc + '"'
97
else:
98
desc_txt = "None"
99
100
if desc_txt != "None":
101
translator = Translator()
102
detection = translator.detect(desc_txt)
103
translation_confidence = detection.confidence
104
translation = translator.translate(desc_txt, dest=user_lang)
105
original_language = translation.src
106
translated_text = translation.text
107
else:
108
original_language = user_lang
109
translated_text = "N/A"
110
translation_confidence = "N/A"
111
112
return {
113
"original_language": original_language,
114
"translated_text": translated_text,
115
"translation_confidence": translation_confidence,
116
"description_text": desc_txt,
117
}
118
119
def color_print_green(first_string,second_string):
120
print(
121
Fore.GREEN
122
+ first_string
123
+ Style.RESET_ALL
124
+ second_string
125
)
126
127
def parse_html_page(url):
128
s = requests.Session()
129
s.max_redirects = 10
130
s.headers["User-Agent"] = random.choice(user_agent)
131
URL = s.get(url)
132
URL.encoding = "utf-8"
133
html_content = URL.text
134
soup = BeautifulSoup(html_content, "html.parser")
135
name = ""
136
group_description = ""
137
total_participants = ""
138
try:
139
name = soup.find(
140
"div", {"class": ["tgme_page_title"]}
141
).text
142
except:
143
name = "Not found"
144
try:
145
group_description = soup.find(
146
"div", {"class": ["tgme_page_description"]}
147
).text
148
descript = Fore.GREEN + "Description: " + Style.RESET_ALL+ group_description
149
except:
150
group_description = "None"
151
descript = Fore.GREEN + "Description: " + Style.RESET_ALL+ group_description
152
153
try:
154
group_participants = soup.find(
155
"div", {"class": ["tgme_page_extra"]}
156
).text
157
sep = "members"
158
stripped = group_participants.split(sep, 1)[0]
159
total_participants = (
160
stripped.replace(" ", "")
161
.replace("members", "")
162
.replace("subscribers", "")
163
.replace("member", "")
164
)
165
except:
166
total_participants = "Not found"
167
168
return {"name":name,"group_description":group_description, "total_participants":total_participants}
169
170
171
def generate_textwrap(text_string, size=70):
172
trans_descript = Fore.GREEN + f"{text_string} " + Style.RESET_ALL
173
prefix = trans_descript
174
return textwrap.TextWrapper(
175
initial_indent=prefix,
176
width=size,
177
subsequent_indent=" ",
178
)
179
180
def print_shell(type, obj):
181
if type == "user":
182
color_print_green(" [+] ", "User details for " + obj.target)
183
color_print_green(" ├ Username: ", str(obj.username))
184
color_print_green(" ├ Name: ", str(obj.user_full_name))
185
color_print_green(" ├ Verification: ", str(obj.verified))
186
color_print_green(" ├ Photo ID: ", str(obj.user_photo))
187
color_print_green(" ├ Phone number: ", str(obj.phone))
188
color_print_green(
189
" ├ Access hash: ", str(obj.access_hash)
190
)
191
color_print_green(" ├ Language: ", str(obj.lang_code))
192
color_print_green(" ├ Bot: ", str(obj.bot))
193
color_print_green(" ├ Scam: ", str(obj.scam))
194
color_print_green(" ├ Last seen: ", str(obj.user_status))
195
color_print_green(" └ Restrictions: ", str(obj.user_restrictions))
196
197
if type == "location_report":
198
color_print_green(" [+] Users located", "")
199
color_print_green(" ├ Users within 500m: ", str(obj.d500))
200
color_print_green(" ├ Users within 1000m: ", str(obj.d1000))
201
color_print_green(" ├ Users within 2000m: ", str(obj.d2000))
202
color_print_green(" ├ Users within 3000m: ", str(obj.d3000))
203
color_print_green(" ├ Total users found: ", str(obj.total))
204
color_print_green(" └ Location list saved to: ", obj.save_file)
205
206
if type == "channel_recap" or type == "group_recap":
207
208
d_wrapper = generate_textwrap("Description:")
209
td_wrapper = generate_textwrap("Translated Description:")
210
211
color_print_green(" ┬ Chat details", "")
212
color_print_green(" ├ Title: ", str(obj.title))
213
color_print_green(" ├ ", d_wrapper.fill(obj.group_description))
214
if obj.translated_description != obj.group_description:
215
color_print_green(" ├ ", td_wrapper.fill(obj.translated_description))
216
color_print_green(
217
" ├ Total participants: ", str(obj.total_participants)
218
)
219
220
if type == "group_recap":
221
color_print_green(
222
" ├ Participants found: ",
223
str(obj.found_participants)
224
+ " ("
225
+ str(format(obj.found_percentage, ".2f"))
226
+ "%)",
227
)
228
229
color_print_green(" ├ Username: ", str(obj.group_username))
230
color_print_green(" ├ URL: ", str(obj.group_url))
231
color_print_green(" ├ Chat type: ", str(obj.chat_type))
232
color_print_green(" ├ Chat id: ", str(obj.id))
233
color_print_green(" ├ Access hash: ", str(obj.access_hash))
234
if type == "channel_recap":
235
scam_status = str(obj.scam)
236
color_print_green(" ├ Scam: ", str(scam_status))
237
color_print_green(" ├ First post date: ", str(obj.first_post))
238
if type == "group_recap":
239
color_print_green(
240
" ├ Memberlist saved to: ", obj.memberlist_filename
241
)
242
color_print_green(
243
" └ Restrictions: ", (str(obj.group_status))
244
)
245
246
if type == "group_stat":
247
color_print_green(" [+] Chat archive saved", "")
248
color_print_green(" ┬ Chat statistics", "")
249
color_print_green(
250
" ├ Number of messages found: ", str(obj.messages_found)
251
)
252
color_print_green(
253
" ├ Top poster 1: ", str(obj.poster_one)
254
)
255
color_print_green(
256
" ├ Top poster 2: ", str(obj.poster_two)
257
)
258
color_print_green(
259
" ├ Top poster 3: ", str(obj.poster_three)
260
)
261
color_print_green(
262
" ├ Top poster 4: ", str(obj.poster_four)
263
)
264
color_print_green(
265
" ├ Top poster 5: ", str(obj.poster_five)
266
)
267
color_print_green(
268
" ├ Total unique posters: ", str(obj.unique_active)
269
)
270
color_print_green(
271
" └ Archive saved to: ", str(obj.file_archive)
272
)
273
return
274
275
if type == "channel_stat":
276
color_print_green(" [+] Channel archive saved", "")
277
color_print_green(" ┬ Channel statistics", "")
278
color_print_green(
279
" ├ Number of messages found: ", str(obj.messages_found)
280
)
281
color_print_green(
282
" └ Archive saved to: ", str(obj.file_archive)
283
)
284
return
285
286
if type == "reply_stat":
287
middle_char = "├"
288
if obj.user_replier_list_len == 0:
289
middle_char = "└"
290
291
color_print_green(" [+] Replies analysis ", "")
292
color_print_green(" ┬ Chat statistics", "")
293
color_print_green(
294
f" {middle_char} Archive of replies saved to: ",
295
str(obj.reply_file_archive),
296
)
297
if obj.user_replier_list_len > 0:
298
color_print_green(
299
" └ Active members list who replied to messages, saved to: ",
300
str(obj.reply_memberlist_filename),
301
)
302
color_print_green(
303
" ┬ Top replier 1: ", str(obj.replier_one)
304
)
305
color_print_green(
306
" ├ Top replier 2: ", str(obj.replier_two)
307
)
308
color_print_green(
309
" ├ Top replier 3: ", str(obj.replier_three)
310
)
311
color_print_green(
312
" ├ Top replier 4: ", str(obj.replier_four)
313
)
314
color_print_green(
315
" ├ Top replier 5: ", str(obj.replier_five)
316
)
317
color_print_green(
318
" └ Total unique repliers: ", str(obj.replier_unique)
319
)
320
321
if type == "forwarder_stat":
322
color_print_green(" [+] Forward scrape complete", "")
323
color_print_green(" ┬ Statistics", "")
324
color_print_green(
325
" ├ Forwarded messages found: ", str(obj.forward_count)
326
)
327
color_print_green(
328
" ├ Forwards from active public chats: ",
329
str(obj.forwards_found),
330
)
331
if hasattr(object, "private_count"):
332
color_print_green(
333
" ├ Forwards from private (or now private) chats: ",
334
str(obj.private_count),
335
)
336
color_print_green(
337
" ├ Unique forward sources: ", str(obj.unique_forwards)
338
)
339
color_print_green(
340
" ├ Top forward source 1: ", str(obj.forward_one)
341
)
342
color_print_green(
343
" ├ Top forward source 2: ", str(obj.forward_two)
344
)
345
color_print_green(
346
" ├ Top forward source 3: ", str(obj.forward_three)
347
)
348
color_print_green(
349
" ├ Top forward source 4: ", str(obj.forward_four)
350
)
351
color_print_green(
352
" ├ Top forward source 5: ", str(obj.forward_five)
353
)
354
color_print_green(" └ Edgelist saved to: ", obj.edgelist_file)
355