forked from Keys-007/Instagram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insta_cmds.py
624 lines (572 loc) · 23.2 KB
/
insta_cmds.py
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
#MIT License
#Copyright (c) 2021 subinps
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from pyrogram import Client, filters
from config import Config
from instaloader import Profile
from pyrogram.errors.exceptions.bad_request_400 import MessageTooLong
import os
from utils import *
USER=Config.USER
OWNER=Config.OWNER
HOME_TEXT_OWNER=Config.HOME_TEXT_OWNER
HELP=Config.HELP
HOME_TEXT=Config.HOME_TEXT
session=f"./{USER}"
STATUS=Config.STATUS
insta = Config.L
buttons=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("👨🏼💻Developer", url='https://t.me/subinps'),
InlineKeyboardButton("🤖Other Bots", url="https://t.me/subin_works/122")
],
[
InlineKeyboardButton("🔗Source Code", url="https://github.com/subinps/Instagram-Bot"),
InlineKeyboardButton("🧩Deploy Own Bot", url="https://heroku.com/deploy?template=https://github.com/subinps/Instagram-Bot")
],
[
InlineKeyboardButton("👨🏼🦯How To Use?", callback_data="help#subin"),
InlineKeyboardButton("⚙️Update Channel", url="https://t.me/subin_works")
]
]
)
@Client.on_message(filters.command("posts") & filters.private)
async def post(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
await bot.send_message(
message.from_user.id,
f"What type of post do you want to download?.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("Photos", callback_data=f"photos#{username}"),
InlineKeyboardButton("Videos", callback_data=f"video#{username}")
]
]
)
)
@Client.on_message(filters.command("igtv") & filters.private)
async def igtv(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
m=await message.reply_text(f"Fetching IGTV from <code>@{username}</code>")
profile = Profile.from_username(insta.context, username)
igtvcount = profile.igtvcount
await m.edit(
text = f"Do you Want to download all IGTV posts?\nThere are {igtvcount} posts.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("Yes", callback_data=f"yesigtv#{username}"),
InlineKeyboardButton("No", callback_data=f"no#{username}")
]
]
)
)
@Client.on_message(filters.command("followers") & filters.private)
async def followers(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
profile = Profile.from_username(insta.context, username)
name=profile.full_name
m=await message.reply_text(f"Fetching Followers list of <code>@{username}</code>")
chat_id=message.from_user.id
f = profile.get_followers()
followers=f"**Followers List for {name}**\n\n"
for p in f:
followers += f"\n[{p.username}](www.instagram.com/{p.username})"
try:
await m.delete()
await bot.send_message(chat_id=chat_id, text=followers)
except MessageTooLong:
followers=f"**Followers List for {name}**\n\n"
f = profile.get_followers()
for p in f:
followers += f"\nName: {p.username} : Link to Profile: www.instagram.com/{p.username}"
text_file = open(f"{username}'s followers.txt", "w")
text_file.write(followers)
text_file.close()
await bot.send_document(chat_id=chat_id, document=f"./{username}'s followers.txt", caption=f"{name}'s followers\n\nA Project By [XTZ_Bots](https://t.me/subin_works)")
os.remove(f"./{username}'s followers.txt")
@Client.on_message(filters.command("followees") & filters.private)
async def followees(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
profile = Profile.from_username(insta.context, username)
name=profile.full_name
m=await message.reply_text(f"Fetching Followees list of <code>@{username}</code>")
chat_id=message.from_user.id
f = profile.get_followees()
followees=f"**Followees List for {name}**\n\n"
for p in f:
followees += f"\n[{p.username}](www.instagram.com/{p.username})"
try:
await m.delete()
await bot.send_message(chat_id=chat_id, text=followees)
except MessageTooLong:
followees=f"**Followees List for {name}**\n\n"
f = profile.get_followees()
for p in f:
followees += f"\nName: {p.username} : Link to Profile: www.instagram.com/{p.username}"
text_file = open(f"{username}'s followees.txt", "w")
text_file.write(followees)
text_file.close()
await bot.send_document(chat_id=chat_id, document=f"./{username}'s followees.txt", caption=f"{name}'s followees\n\nA Project By [XTZ_Bots](https://t.me/subin_works)")
os.remove(f"./{username}'s followees.txt")
@Client.on_message(filters.command("fans") & filters.private)
async def fans(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
profile = Profile.from_username(insta.context, username)
name=profile.full_name
m=await message.reply_text(f"Fetching list of followees of <code>@{username}</code> who follows <code>@{username}</code>.")
chat_id=message.from_user.id
f = profile.get_followers()
fl = profile.get_followees()
flist=[]
fmlist=[]
for fn in f:
u=fn.username
flist.append(u)
for fm in fl:
n=fm.username
fmlist.append(n)
fans = [value for value in fmlist if value in flist]
print(len(fans))
followers=f"**Fans List for {name}**\n\n"
for p in fans:
followers += f"\n[{p}](www.instagram.com/{p})"
try:
await m.delete()
await bot.send_message(chat_id=chat_id, text=followers)
except MessageTooLong:
followers=f"**Fans List for {name}**\n\n"
for p in fans:
followers += f"\nName: {p} : Link to Profile: www.instagram.com/{p}"
text_file = open(f"{username}'s fans.txt", "w")
text_file.write(followers)
text_file.close()
await bot.send_document(chat_id=chat_id, document=f"./{username}'s fans.txt", caption=f"{name}'s fans\n\nA Project By [XTZ_Bots](https://t.me/subin_works)")
os.remove(f"./{username}'s fans.txt")
@Client.on_message(filters.command("notfollowing") & filters.private)
async def nfans(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
profile = Profile.from_username(insta.context, username)
name=profile.full_name
m=await message.reply_text(f"Fetching list of followees of <code>@{username}</code> who is <b>not</b> following <code>@{username}</code>.")
chat_id=message.from_user.id
f = profile.get_followers()
fl = profile.get_followees()
flist=[]
fmlist=[]
for fn in f:
u=fn.username
flist.append(u)
for fm in fl:
n=fm.username
fmlist.append(n)
fans = list(set(fmlist) - set(flist))
print(len(fans))
followers=f"**Followees of <code>@{username}</code> who is <b>not</b> following <code>@{username}</code>**\n\n"
for p in fans:
followers += f"\n[{p}](www.instagram.com/{p})"
try:
await m.delete()
await bot.send_message(chat_id=chat_id, text=followers)
except MessageTooLong:
followers=f"Followees of <code>@{username}</code> who is <b>not</b> following <code>@{username}</code>\n\n"
for p in fans:
followers += f"\nName: {p} : Link to Profile: www.instagram.com/{p}"
text_file = open(f"{username}'s Non_followers.txt", "w")
text_file.write(followers)
text_file.close()
await bot.send_document(chat_id=chat_id, document=f"./{username}'s Non_followers.txt", caption=f"{name}'s Non_followers\n\nA Project By [XTZ_Bots](https://t.me/subin_works)")
os.remove(f"./{username}'s Non_followers.txt")
@Client.on_message(filters.command("feed") & filters.private)
async def feed(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
count=None
if " " in text:
cmd, count = text.split(' ')
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
m=await message.reply_text(f"Fetching Posts in Your Feed.")
chat_id=message.from_user.id
dir=f"{chat_id}/{username}"
await m.edit("Starting Downloading..\nThis may take longer time Depending upon number of posts.")
if count:
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-posts",
"--no-captions",
"--no-video-thumbnails",
"--login", USER,
"--sessionfile", session,
"--dirname-pattern", dir,
":feed",
"--count", count
]
else:
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-posts",
"--no-captions",
"--no-video-thumbnails",
"--login", USER,
"--sessionfile", session,
"--dirname-pattern", dir,
":feed"
]
await download_insta(command, m, dir)
await upload(m, bot, chat_id, dir)
@Client.on_message(filters.command("saved") & filters.private)
async def saved(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
count=None
if " " in text:
cmd, count = text.split(' ')
m=await message.reply_text(f"Fetching your Saved Posts.")
chat_id=message.from_user.id
dir=f"{chat_id}/{username}"
await m.edit("Starting Downloading..\nThis may take longer time Depending upon number of posts.")
if count:
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-posts",
"--no-captions",
"--no-video-thumbnails",
"--login", USER,
"-f", session,
"--dirname-pattern", dir,
":saved",
"--count", count
]
else:
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-posts",
"--no-captions",
"--no-video-thumbnails",
"--login", USER,
"-f", session,
"--dirname-pattern", dir,
":saved"
]
await download_insta(command, m, dir)
await upload(m, bot, chat_id, dir)
@Client.on_message(filters.command("tagged") & filters.private)
async def tagged(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
m=await message.reply_text(f"Fetching the posts in which <code>@{username}</code> is tagged.")
chat_id=message.from_user.id
dir=f"{chat_id}/{username}"
await m.edit("Starting Downloading..\nThis may take longer time Depending upon number of posts.")
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-posts",
"--tagged",
"--no-captions",
"--no-video-thumbnails",
"--login", USER,
"-f", session,
"--dirname-pattern", dir,
"--", username
]
await download_insta(command, m, dir)
await upload(m, bot, chat_id, dir)
@Client.on_message(filters.command("story") & filters.private)
async def story(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
text=message.text
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
m=await message.reply_text(f"Fetching stories of <code>@{username}</code>")
chat_id=message.from_user.id
dir=f"{chat_id}/{username}"
await m.edit("Starting Downloading..\nThis may take longer time Depending upon number of posts.")
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-posts",
"--stories",
"--no-captions",
"--no-video-thumbnails",
"--login", USER,
"-f", session,
"--dirname-pattern", dir,
"--", username
]
await download_insta(command, m, dir)
await upload(m, bot, chat_id, dir)
@Client.on_message(filters.command("stories") & filters.private)
async def stories(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
m=await message.reply_text(f"Fetching stories of all your followees")
chat_id=message.from_user.id
dir=f"{chat_id}/{username}"
await m.edit("Starting Downloading..\nThis may take longer time Depending upon number of posts.")
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-captions",
"--no-posts",
"--no-video-thumbnails",
"--login", USER,
"-f", session,
"--dirname-pattern", dir,
":stories"
]
await download_insta(command, m, dir)
await upload(m, bot, chat_id, dir)
@Client.on_message(filters.command("highlights") & filters.private)
async def highlights(bot, message):
if str(message.from_user.id) != OWNER:
await message.reply_text(
HOME_TEXT.format(message.from_user.first_name, message.from_user.id, USER, USER, USER, OWNER),
reply_markup=buttons,
disable_web_page_preview=True
)
return
username=USER
if 1 not in STATUS:
await message.reply_text("You Must Login First /login ")
return
text=message.text
if " " in text:
cmd, username = text.split(' ')
profile = Profile.from_username(insta.context, username)
is_followed = yes_or_no(profile.followed_by_viewer)
type = acc_type(profile.is_private)
if type == "🔒Private🔒" and is_followed == "No":
await message.reply_text("Sorry!\nI can't fetch details from that account.\nSince its a Private account and you are not following <code>@{username}</code>.")
return
m=await message.reply_text(f"Fetching highlights from profile <code>@{username}</code>")
chat_id=message.from_user.id
dir=f"{chat_id}/{username}"
await m.edit("Starting Downloading..\nThis may take longer time Depending upon number of posts.")
command = [
"instaloader",
"--no-metadata-json",
"--no-compress-json",
"--no-profile-pic",
"--no-posts",
"--highlights",
"--no-captions",
"--no-video-thumbnails",
"--login", USER,
"-f", session,
"--dirname-pattern", dir,
"--", username
]
await download_insta(command, m, dir)
await upload(m, bot, chat_id, dir)