-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
369 lines (280 loc) · 15.9 KB
/
main.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
# -*- coding:utf-8 -*-
import asyncio
import logging
import os
import random
from datetime import datetime
import aiocron
import pytz
import redis.asyncio as redis
from decouple import config
from telethon import TelegramClient, events
from telethon import functions
from telethon.errors.rpcerrorlist import ContactIdInvalidError
from telethon.tl.functions.photos import UploadProfilePhotoRequest
from telethon.tl.functions.users import GetFullUserRequest
from telethon.tl.types import PeerChannel
from services import delete_profile_photo, delete_sender_message
from utils import image_set_clock
telegram_id = 777000
try:
r = redis.StrictRedis(host="localhost", port=6379, db=1, password="", decode_responses=True)
except Exception as e:
print("[-] i can`t connect to redis!\n[-] error: " + str(e))
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s ',
level=logging.INFO)
logger = logging.getLogger(__name__)
master = config('master', cast=int)
admin_list = config('admin_list', cast=lambda v: [int(s.strip()) for s in v.split(',') if v]) + [master]
api_id = config('api_id')
api_hash = config('api_hash')
client = TelegramClient(
'mahdi',
api_id,
api_hash
)
client.start()
save_path = "assets/images/avatar.jpg"
@aiocron.crontab('*/1 * * * *')
async def worker():
online_mode = await r.get("online")
clock_in_profile = await r.get("clock_in_profile")
change_name = await r.get("change_name")
ir = pytz.timezone("Asia/Tehran")
time = datetime.now(ir).strftime("%H:%M")
if online_mode == "1":
await client(functions.account.UpdateStatusRequest(offline=False))
if clock_in_profile == "1":
result = image_set_clock(time)
await delete_profile_photo(client)
image = await client.upload_file(result)
await client(UploadProfilePhotoRequest(file=image))
if change_name == "1":
list_name = await r.lrange("list_name", 0, -1) or await client.get_me()
name = random.choice(list_name) if isinstance(list_name, list) else list_name.first_name
await client(functions.account.UpdateProfileRequest(first_name=name))
@client.on(events.NewMessage(pattern="-Hello"))
async def main(event):
await event.reply('Hey!')
@client.on(events.NewMessage(from_users=admin_list, pattern="-set online"))
async def set_online(event):
await r.set("online", "1")
await client.send_message(event.chat_id, "-Keep online mode turned on")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset online"))
async def unset_online(event):
await r.set("online", "0")
await client.send_message(event.chat_id, "-Keep online mode turned off")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set clock in profile"))
async def clock_in_profile_on(event):
clock_in_profile = await r.get("clock_in_profile")
if clock_in_profile == "1":
await client.send_message(event.chat_id, "-Clock in profile is already on")
else:
result = await client.download_profile_photo("me", file=save_path)
if result is None:
await client.send_message(event.chat_id, "-You don`t have profile photo!")
else:
await r.set("clock_in_profile", "1")
await client.send_message(event.chat_id, "-Clock in profile turned on")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset clock in profile"))
async def clock_in_profile_off(event):
await delete_profile_photo(client) if await r.get("clock_in_profile") == "1" else ...
if os.path.exists(save_path):
image = await client.upload_file(save_path)
await client(UploadProfilePhotoRequest(file=image))
await r.set("clock_in_profile", "0")
await client.send_message(event.chat_id, "-Clock in profile turned off")
@client.on(events.NewMessage(from_users=admin_list, pattern="-remove profile"))
async def remove_profile(event):
await delete_profile_photo(client, 1)
await client.send_message(event.chat_id, "-Profile photo removed")
@client.on(events.NewMessage(from_users=admin_list, pattern="-clear profile"))
async def clear_profile(event):
await delete_profile_photo(client)
await client.send_message(event.chat_id, "-Profile photo cleared")
@client.on(events.NewMessage(from_users=admin_list, pattern="-fuck"))
async def fuck(event):
await delete_sender_message(client, event)
fuck_text_sended = " .\n \n /¯ )\n /¯ / \n / / \n /´¯/' '/´¯ )\n /'/ / / / / \ \n ('( ( ( ( |/ )\n \ ./ \n \ _.•´\n \ (\n \ \ "
fuck_text_edited = " .\n \n \n \n \n /´¯/' '/´¯ )\n /'/ / / / / \ \n ('( ( ( ( |/ )\n \ ./ \n \ _.•´\n \ (\n \ \ "
message = await client.send_message(event.chat_id, fuck_text_sended, reply_to=event.reply_to_msg_id)
for i in range(1, 5):
await asyncio.sleep(0.5)
await client.edit_message(event.chat_id, message, fuck_text_edited)
await asyncio.sleep(0.5)
await client.edit_message(event.chat_id, message, fuck_text_sended)
@client.on(events.NewMessage(from_users=admin_list, pattern="-ping"))
async def ping(event):
x = 7
black_ball = "⚫️"
white_ball = "⚪️"
message = await client.send_message(event.chat_id, black_ball * x)
for i in range(x + 2):
await client.edit_message(event.chat_id, message, f"{black_ball * (x - i + 1) + (white_ball * (i + 1))}")
await client.edit_message(event.chat_id, message, "-Im online")
@client.on(events.NewMessage(func=lambda e: e.is_private and e.chat_id not in admin_list))
async def lock_pv(event):
status = await r.get("lock_pv")
if status == "1":
sender = await event.get_sender()
if not sender.contact:
await client.delete_messages(event.chat_id, event.message.id)
@client.on(events.NewMessage(from_users=admin_list, pattern="-set lock pv"))
async def set_lock_pv(event):
await r.set("lock_pv", "1")
await client.send_message(event.chat_id, "-Lock pv turned on")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset lock pv"))
async def unset_lock_pv(event):
await r.set("lock_pv", "0")
await client.send_message(event.chat_id, "-Lock pv turned off")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set auto seen"))
async def set_auto_seen(event):
await r.set("auto_seen", "1")
await client.send_message(event.chat_id, "-Auto seen turned on")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset auto seen"))
async def unset_auto_seen(event):
await r.set("auto_seen", "0")
await client.send_message(event.chat_id, "-Auto seen turned off")
@client.on(events.NewMessage(func=lambda e: e.is_private))
async def auto_seen(event):
status = await r.get("auto_seen")
if status == "1":
try:
await client.send_read_acknowledge(event.chat_id, max_id=event.id)
except ValueError as va:
sender = await event.get_input_sender()
await client.send_read_acknowledge(sender, max_id=event.id)
@client.on(events.NewMessage(from_users=admin_list, pattern="-set block"))
async def set_block(event):
if event.reply_to_msg_id is None:
await client.send_message(event.chat_id, "-Reply to a message!")
else:
try:
replied = await event.get_reply_message()
sender = replied.sender_id
await client(functions.contacts.BlockRequest(id=sender))
full = await client(GetFullUserRequest(sender))
await client.send_message(event.chat_id, f"-User {full.user.first_name} {full.user.last_name} blocked")
except ContactIdInvalidError:
await client.send_message(event.chat_id, "-The provided contact ID is invalid")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset block"))
async def unset_block(event):
if event.reply_to_msg_id is None:
await client.send_message(event.chat_id, "-Reply to a message!")
else:
try:
replied = await event.get_reply_message()
sender = replied.sender_id
await client(functions.contacts.UnblockRequest(id=sender))
full = await client(GetFullUserRequest(sender))
await client.send_message(event.chat_id, f"-User {full.user.first_name} {full.user.last_name} unblocked")
except ContactIdInvalidError:
await client.send_message(event.chat_id, "-The provided contact ID is invalid")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set name (.*)"))
async def set_name(event):
name = event.pattern_match.group(1)
await client(functions.account.UpdateProfileRequest(first_name=name))
await client.send_message(event.chat_id, f"-Name changed to {name}")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set bio (.*)"))
async def set_bio(event):
bio = event.pattern_match.group(1)
await client(functions.account.UpdateProfileRequest(about=bio))
await client.send_message(event.chat_id, f"-Bio changed to {bio}")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set list name (.*)"))
async def set_list_name(event):
name = event.pattern_match.group(1)
await r.rpush("list_name", name)
await client.send_message(event.chat_id, f"-{name} added to list name")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset list name (.*)"))
async def unset_list_name(event):
name = event.pattern_match.group(1)
await r.lrem("list_name", 0, name)
await client.send_message(event.chat_id, f"-{name} removed from list name")
@client.on(events.NewMessage(from_users=admin_list, pattern="-clear list name"))
async def clear_list_name(event):
await r.delete("list_name")
await client.send_message(event.chat_id, "-List name cleared")
@client.on(events.NewMessage(from_users=admin_list, pattern="-show list name"))
async def show_list_name(event):
name_list = '\n'.join(await r.lrange("list_name", 0, -1))
await client.send_message(event.chat_id, f"-List name:\n{name_list}")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set change name"))
async def set_change_name(event):
status = await r.set("change_name", "1")
await client.send_message(event.chat_id, "-Change name turned on")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset change name"))
async def unset_change_name(event):
status = await r.set("change_name", "0")
await client.send_message(event.chat_id, "-Change name turned off")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set self destructing downloader"))
async def self_destructing_downloader(event):
status = await r.set("self_destructing_downloader", "1")
await client.send_message(event.chat_id, "-Self destructing downloader turned on")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset self destructing downloader"))
async def unset_self_destructing_downloader(event):
status = await r.set("self_destructing_downloader", "0")
await client.send_message(event.chat_id, "-Self destructing downloader turned off")
@client.on(events.NewMessage(func=lambda e: e.is_private and (e.photo or e.video) and e.media_unread))
async def self_destructing_downloader(event):
status = await r.get("self_destructing_downloader")
if status == "1":
result = await event.download_media()
await client.send_file("me", result, caption=f"-{event.sender.first_name} {event.sender.last_name} sent a file")
@client.on(events.NewMessage(from_users=admin_list, pattern="-set special", func=lambda e: not e.is_private))
async def set_special(event):
await r.lpush("special", event.chat_id)
await client.send_message(event.chat_id, "-Chat added to special")
@client.on(events.NewMessage(from_users=admin_list, pattern="-unset special", func=lambda e: not e.is_private))
async def unset_special(event):
await r.lrem("special", 0, event.chat_id)
await client.send_message(event.chat_id, "-Chat removed from special")
@client.on(events.NewMessage(from_users=admin_list, pattern="-clear special"))
async def clear_special(event):
await r.delete("special")
await client.send_message(event.chat_id, "-Special cleared")
@client.on(events.NewMessage(from_users=admin_list, pattern="-show list special"))
async def show_list_special(event):
text = "-Special list:"
for i in await r.lrange("special", 0, -1):
my_chat = await client.get_entity(PeerChannel(int(i)))
text += f"\n{my_chat.title}"
await client.send_message(event.chat_id, text)
@client.on(events.ChatAction(func=lambda e: e.user_joined))
async def user_join(event):
list_group = await r.lrange("special", 0, -1)
if str(event.chat_id) in list_group:
message = await event.reply("💚💚💚💚💚")
await client.edit_message(event.chat_id, message, "❤️❤️❤️❤️❤️")
await client.edit_message(event.chat_id, message, "🧡🧡🧡🧡🧡")
await client.edit_message(event.chat_id, message, "💛💛💛💛💛")
await client.edit_message(event.chat_id, message, "💚💚💚💚💚")
await client.edit_message(event.chat_id, message, "💙💙💙💙💙")
await client.edit_message(event.chat_id, message, "💜💜💜💜💜")
await client.edit_message(event.chat_id, message, "🖤🖤🖤🖤🖤")
await client.edit_message(event.chat_id, message, "🤍🤍🤍🤍🤍")
await client.edit_message(event.chat_id, message, "🤎🤎🤎🤎🤎")
await client.edit_message(event.chat_id, message, "❣️❣️❣️❣️❣️")
await client.edit_message(event.chat_id, message, "💕💕💕💕💕")
await client.edit_message(event.chat_id, message, "💞💞💞💞💞")
await client.edit_message(event.chat_id, message, "💓💓💓💓💓")
await client.edit_message(event.chat_id, message, "💗💗💗💗💗")
await client.edit_message(event.chat_id, message, "💖💖💖💖💖")
await client.edit_message(event.chat_id, message, "💘💘💘💘💘")
await client.edit_message(event.chat_id, message, "💝💝💝💝💝")
my_chat = await client.get_entity(PeerChannel(event.chat_id))
await client.edit_message(event.chat_id, message, f"-Welcome to {my_chat.title}")
@client.on(events.ChatAction(func=lambda e: e.user_left))
async def user_left(event):
list_group = await r.lrange("special", 0, -1)
if str(event.chat_id) in list_group:
fuck_text_sended = " .\n \n /¯ )\n /¯ / \n / / \n /´¯/' '/´¯ )\n /'/ / / / / \ \n ('( ( ( ( |/ )\n \ ./ \n \ _.•´\n \ (\n \ \ "
fuck_text_edited = " .\n \n \n \n \n /´¯/' '/´¯ )\n /'/ / / / / \ \n ('( ( ( ( |/ )\n \ ./ \n \ _.•´\n \ (\n \ \ "
message = await event.reply(fuck_text_sended)
for i in range(1, 5):
await asyncio.sleep(0.5)
await client.edit_message(event.chat_id, message, fuck_text_edited)
await asyncio.sleep(0.5)
await client.edit_message(event.chat_id, message, fuck_text_sended)
worker.start()
asyncio.get_event_loop().run_forever()
client.run_until_disconnected()