-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathavatar.py
174 lines (157 loc) · 6.65 KB
/
avatar.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
# -*- coding: utf-8 -*-
# Module author: @ftgmodulesbyfl1yd, @dekftgmodules
import os
from telethon import functions
from telethon.errors.rpcerrorlist import UsernameOccupiedError
from telethon.tl.functions.account import UpdateProfileRequest, UpdateUsernameRequest
from .. import loader, utils
class GetPPMod(loader.Module):
strings = {"name": "Profile"}
async def client_ready(self, client, db):
self.client = client
self.db = db
async def avacmd(self, message):
id = utils.get_args_raw(message)
user = await message.get_reply_message()
chat = message.input_chat
if user:
photos = await self.client.get_profile_photos(user.sender)
u = True
else:
photos = await self.client.get_profile_photos(chat)
u = False
if id.strip() == "":
if len(photos) > 0:
await self.client.send_file(message.chat_id, photos)
for i in photos:
os.remove(i)
else:
try:
if u:
photo = await self.client.download_profile_photo(user.sender)
else:
photo = await self.client.download_profile_photo(
message.input_chat
)
await self.client.send_file(message.chat_id, photo)
os.remove(photo)
except Exception:
await message.edit("<code>This user has no photos</code>")
return
else:
try:
id = int(id)
if id <= 0:
await message.edit("<code>ID number you entered is invalid</code>")
return
except Exception:
await message.edit("<code>ID number you entered is invalid</code>")
return
if int(id) <= (len(photos)):
send_photos = await self.client.download_media(photos[id - 1])
await self.client.send_file(message.chat_id, send_photos)
os.remove(send_photos)
else:
await message.edit("<code>No photo found with that id</code>")
return
await message.delete()
async def setavacmd(self, message):
reply = await check_mediaa(message)
if not reply:
try:
reply = await message.get_reply_message()
if not reply:
return await message.edit("No reply to a media.")
await message.edit("Downloading...")
if reply.video:
await message.client.download_media(reply.media, "ava.mp4")
await message.edit("Converting...")
os.system("ffmpeg -i ava.mp4 -c copy -an gifavaa.mp4 -y")
os.system("ffmpeg -i gifavaa.mp4 -vf scale=360:360 gifava.mp4 -y")
else:
await message.client.download_media(reply.media, "tgs.tgs")
await message.edit("Converting...")
os.system(
"lottie_convert.py tgs.tgs tgs.gif; mv tgs.gif gifava.mp4"
)
await message.edit("Uploading avatar...")
await message.client(
functions.photos.UploadProfilePhotoRequest(
video=await message.client.upload_file("gifava.mp4"),
video_start_ts=0.0,
)
)
await message.edit("Uploaded.")
os.system("rm -rf ava.mp4 gifava.mp4 gifavaa.mp4 tgs*")
except Exception:
await message.edit("An unexpected error occurred")
return os.system("rm -rf ava.mp4 gifava.mp4 gifavaa.mp4 tgs*")
else:
reply = await message.get_reply_message()
media = reply.photo or reply.sticker if reply else None
if not media:
return await message.edit("No reply on photo/sticker")
await message.edit("Downloading...")
photo = await message.client.download_media(message=reply.photo)
up = await message.client.upload_file(photo)
await message.edit("Uploading avatar...")
await message.client(functions.photos.UploadProfilePhotoRequest(up))
await message.delete()
os.remove(photo)
async def delavacmd(self, message):
ava = await message.client.get_profile_photos("me", limit=1)
if len(ava) > 0:
await message.edit("Deleting avatar...")
await message.client(functions.photos.DeletePhotosRequest(ava))
await message.edit("Current avatar was deleted.")
else:
await message.edit("No avatar found")
async def delavascmd(self, message):
ava = await message.client.get_profile_photos("me")
if len(ava) > 0:
await message.edit("Deleting avatars...")
await message.client(
functions.photos.DeletePhotosRequest(
await message.client.get_profile_photos("me")
)
)
await message.edit("All avatars was deleted")
else:
await message.edit("No avatar found")
async def setnamecmd(self, message):
args = utils.get_args_raw(message).split("/")
if len(args) == 1:
firstname = args[0]
lastname = " "
elif len(args) == 2:
firstname = args[0]
lastname = args[1]
await message.client(
UpdateProfileRequest(first_name=firstname, last_name=lastname)
)
await message.edit("Name changed successfully!")
async def setbiocmd(self, message):
args = utils.get_args_raw(message)
if not args:
return await message.edit("No arguments.")
await message.client(UpdateProfileRequest(about=args))
await message.edit("Bio changed successfully!")
async def setusercmd(self, message):
args = utils.get_args_raw(message)
if not args:
return await message.edit("No args.")
try:
await message.client(UpdateUsernameRequest(args))
await message.edit("Username changed successfully!")
except UsernameOccupiedError:
await message.edit("This username is already occupied!")
async def check_mediaa(message):
reply = await message.get_reply_message()
if not reply:
return False
if not reply.file:
return False
mime = reply.file.mime_type.split("/")[0].lower()
if mime != "image":
return False
return reply