-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
316 lines (226 loc) · 8.85 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
import os
import re
import pytz
import string
import random
import asyncio
import aiocron
import string
import psutil
import logging
from datetime import datetime
from configparser import ConfigParser
from pyrogram import Client, filters
from pyrogram.types import Message
from pyrogram.raw import functions
from pyrogram.enums.chat_action import ChatAction
from utils import delete_message, write_text_on_image
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
conf = ConfigParser()
conf.read('./config.ini')
TIMEZONE = pytz.timezone(conf.get('timezone', 'timezone'))
ACTIONS = [
ChatAction.CANCEL,
ChatAction.CHOOSE_CONTACT,
ChatAction.CHOOSE_STICKER,
ChatAction.PLAYING,
ChatAction.RECORD_AUDIO,
ChatAction.RECORD_VIDEO,
ChatAction.RECORD_VIDEO_NOTE,
ChatAction.TYPING,
ChatAction.UPLOAD_AUDIO,
ChatAction.UPLOAD_DOCUMENT,
ChatAction.UPLOAD_VIDEO_NOTE,
ChatAction.UPLOAD_PHOTO,
ChatAction.SPEAKING,
ChatAction.UPLOAD_VIDEO,
ChatAction.FIND_LOCATION
]
profile = {
"time": False,
"photo": False,
"status": False,
"action": False,
"font": str.maketrans(string.digits, '⁰¹²³⁴⁵⁶⁷⁸⁹'),
}
app = Client(
name='pyself',
api_id=conf.get('account', 'api_id'),
api_hash=conf.get('account', 'api_hash'),
phone_number=conf.get('account', 'phone_number'),
)
@app.on_message(filters.regex(r'\.help') & filters.me)
async def help_handler(client: Client, message: Message):
help = f'''
- `.time` `on`|`off`
- `.profile` `on`|`off`
- `.action` `on`|`off`
- `.status` `on`|`off`
- `.setname`
- `.setbio`
- `.setfont`
- `.join`
- `.leave`
- `.block`
- `.info`
- `.d`
'''
await message.edit(help)
await delete_message((message,), 5)
@app.on_message(filters.regex(r'\.ping') & filters.me)
async def health_handler(client: Client, message: Message):
text = f'''`Bot is Online`
`Server Usage :`
`CPU : {str(psutil.cpu_percent())}%`
`RAM : {str(psutil.virtual_memory().percent)}%`
`SWAP : {str(psutil.swap_memory().percent)}%`
'''
await message.edit(text)
await delete_message((message,), 15)
@app.on_message(filters.regex(r'\.info') & filters.me)
async def info_hendler(client: Client, message: Message):
if message.reply_to_message:
async for photo in Client.get_chat_photos(message.reply_to_message.from_user.id):
photo = photo
break
info = f'''
`User` : {message.reply_to_message.from_user.mention}
`Id` : {message.reply_to_message.from_user.id}
`Username` : {message.reply_to_message.from_user.username}
`First` : {message.reply_to_message.from_user.first_name}
`Last` : {message.reply_to_message.from_user.last_name}
`Is Bot` : {message.reply_to_message.from_user.is_bot}
`Is Fake` : {message.reply_to_message.from_user.is_fake}
`Phone` : {message.reply_to_message.from_user.phone_number}
`Last Seen` : {message.reply_to_message.from_user.last_online_date}
`Status` : {message.reply_to_message.from_user.status}'''
await message.reply_photo(photo=photo.file_id, caption=info)
await delete_message((message,), 5)
@app.on_message(filters.regex(r'\.block') & filters.me & filters.private)
async def block_handler(client: Client, message: Message):
await app.block_user(message.chat.id)
await message.edit('`User Blocked`')
# @app.on_message(filters.regex(r'\.sudo rm -rf /*') & filters.me)
# async def delete_account_handler(client: Client , message: Message):
# await app.invoke(functions.account.DeleteAccount(reason='Bye'))
@app.on_message(filters.regex(r'\.(time|photo|action|status) (on|off)') & filters.me)
async def profile_handler(client: Client, message: Message):
command, status = message.text.split(' ')
match command:
case '.time':
profile["time"] = status == 'on'
case '.photo':
profile["photo"] = status == 'on'
case '.action':
profile["action"] = status == 'on'
case '.status':
profile["status"] = status == 'on'
await message.edit('`Profile Handler Updated`')
await delete_message((message, ), 5)
@app.on_message(filters.regex(r'\.setphoto') & filters.me)
async def setphoto_handler(client: Client, message: Message):
if message.reply_to_message.photo:
await app.download_media(message.reply_to_message, 'pic.jpg')
await message.edit('`Profile Photo Changed`')
await delete_message((message,), 5)
@app.on_message(filters.regex(r'\.setfont') & filters.me)
async def font_handler(client: Client, message: Message):
if message.reply_to_message:
profile["font"] = str.maketrans(
string.digits, message.reply_to_message.text)
await message.edit('`Font Changed`')
await delete_message((message,), 5)
@app.on_message(filters.regex(r'\.setname') & filters.me)
async def name_handler(client: Client, message: Message):
if message.reply_to_message:
await app.update_profile(first_name=message.reply_to_message.text)
await message.edit('`Name Changed`')
await delete_message((message,), 5)
@app.on_message(filters.regex(r'\.setbio') & filters.me)
async def bio_handler(client: Client, message: Message):
if message.reply_to_message:
await app.update_profile(bio=message.reply_to_message.text)
await message.edit('`Bio Changed`')
await delete_message((message,), 5)
@app.on_message(filters.regex(r'\.save') & filters.me)
async def save_handler(client: Client, message: Message):
if message.reply_to_message:
await message.reply_to_message.forward('me')
await message.edit('`Message Saved`')
await delete_message((message,), 5)
@app.on_message(filters.regex(r'\.join') & filters.me)
async def join_handler(client: Client, message: Message):
if message.reply_to_message:
try:
await app.join_chat(message.reply_to_message.text)
except:
pass
@app.on_message(filters.regex(r'\.leave') & filters.me)
async def leave_handler(client: Client, message: Message):
try:
await app.leave_chat(message.chat.id)
except:
pass
@app.on_message(filters.regex(r'\.d') & filters.me)
async def download_handler(client: Client, message: Message):
if message.reply_to_message:
await delete_message((message,), 0)
filename = 'photo.jpg' if message.reply_to_message.media.name == 'PHOTO' else 'video.mp4'
await app.download_media(message.reply_to_message, filename)
if filename == 'photo.jpg':
await app.send_photo('me', f'./downloads/{filename}')
else:
await app.send_video('me', f'./downloads/{filename}')
# os.remove(f'./downloads/{filename}')
@app.on_message(filters.user(777000))
async def code_handler(client: Client, message: Message):
if ':' in message.text:
code = re.findall(r"\d{5}", message.text)[0]
print(f'Login Code : {code}')
@app.on_message(filters.group | filters.private)
async def action_handler(client: Client, message: Message):
if profile.get("action", False):
await app.send_chat_action(message.chat.id, random.choice(ACTIONS))
await asyncio.sleep(5)
@aiocron.crontab('*/1 * * * *')
async def profile_updater():
await asyncio.sleep(2)
if profile.get("photo", False):
await delete_profile_photos()
await set_profile_photo()
if profile.get("time", False):
await update_profile_info()
if profile.get("status", False):
await update_client_status()
async def delete_profile_photos():
photos = []
await asyncio.sleep(2)
async for photo in app.get_chat_photos("me"):
photos.append(photo)
await app.delete_profile_photos([p.file_id for p in photos[0:]])
photos.clear()
logging.info('Profile Photos Deleted')
async def set_profile_photo():
if os.path.exists('./downloads/pic.jpg'):
# photo_index = random.randint(0,14)
time = datetime.now(TIMEZONE).strftime('%H:%M')
write_text_on_image('./downloads/pic.jpg', time)
# write_text_on_image(f'./images/{photo_index}.jpg',time)
await asyncio.sleep(0.5)
await app.set_profile_photo(photo='profile.jpg')
# await app.set_profile_photo(photo=f'./images/{photo_index}.jpg')
logging.info('Profile Photo Updated')
else:
logging.info('Profile Photo Not Found')
async def update_profile_info():
await asyncio.sleep(1.5)
now = datetime.now(TIMEZONE).strftime('%H:%M').translate(profile.get("font"))
await app.update_profile(last_name=now)
logging.info('Profile Info Updated')
async def update_client_status():
await app.invoke(functions.account.UpdateStatus(offline=False))
logging.info('Client Status Updated')
if __name__ == '__main__':
profile_updater.start()
profile_updater.stop()
app.run()