-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_tele_group.py
More file actions
84 lines (68 loc) · 2.66 KB
/
join_tele_group.py
File metadata and controls
84 lines (68 loc) · 2.66 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
import datetime
import random
import time
from telethon import TelegramClient, events, functions, errors
import asyncio
from telethon.tl.functions.channels import JoinChannelRequest
from telethon.tl.functions.messages import ImportChatInviteRequest
import test
download_path = "15mb_vid/"
upload_path = "edited_video/"
api_id = 24259180
api_hash = "63cf9778009838a7d48f75866a5b6fc9"
# Ql & Public
download_chat_id = -1002006536487
upload_chat_id = -1001996807858
client = TelegramClient('khanh_chi', api_id, api_hash)
newest_msg_id_source = 0
# -------------------------------------------------------------
async def JoinGroup():
dict_link = test.GetNameGroup()
count = 0
count_success = 0
count_failure = 0
for link in dict_link:
# join private group
if link == 'private_link':
for idx in dict_link.get(link):
print(f"private: {idx}")
try:
await client(ImportChatInviteRequest(idx))
count_success += 1
print(f'success join private: {idx}, count_success : {count_success}')
except Exception as e:
count_failure += 1
print(f'failed join private: {idx}, count_failure : {count_failure}')
print(f'\nerr(private): {e}')
count += 1
print(f"count: {count}")
sleep_time = random.randint(1, 5)
time.sleep(sleep_time)
# join public group
else:
for idx in dict_link.get(link):
print(f"public: {idx}")
try:
chat = await client.get_entity(idx)
await client(JoinChannelRequest(chat))
count_success += 1
print(f'success join public: {idx}, count_success : {count_success}')
except Exception as e:
count_failure += 1
print(f'failed join public: {idx}, count_failure : {count_failure}')
print(f'\nerr(public): {e}')
count += 1
print(f"count: {count}")
sleep_time = random.randint(1, 5)
time.sleep(sleep_time)
# --------------------------------------------------------------------------------
@client.on(events.NewMessage)
async def my_event_handler(event):
# download and edit new video
if -1002000463892 == event.chat_id:
asyncio.gather(JoinGroup())
# await event.reply('hi!')
print("replied")
client.start()
client.run_until_disconnected()
# -----------------------------------------------------------------------------------