-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprofile.py
281 lines (257 loc) Β· 9.09 KB
/
profile.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
import os
import urllib
from telethon.errors.rpcerrorlist import UsernameOccupiedError
from telethon.tl import functions
from telethon.tl.functions.account import UpdateUsernameRequest
from telethon.tl.functions.channels import GetAdminedPublicChannelsRequest
from telethon.tl.functions.photos import DeletePhotosRequest, GetUserPhotosRequest
from telethon.tl.types import Channel, Chat, InputPhoto, User
from . import *
# ====================== CONSTANT ===============================
INVALID_MEDIA = "β οΈ Targeted Media **Invalid !!**"
PP_CHANGED = "**π Profile picture changed successfully.**"
PP_TOO_SMOL = "πΌοΈ Image size is small. Use a bigger picture."
PP_ERROR = "π₯΄ Failure occured while processing image."
BIO_SUCCESS = "π Bio Message Edited Successfully."
NAME_OK = "~~Kimi No Nawa~~ **Your Name Changed to** {}.."
USERNAME_SUCCESS = "π Successfully Changed Your Username."
USERNAME_TAKEN = "π¬ This Username is already taken. Try another one."
OFFLINE_TAG = "[ β’ OFFLINE β’ ]"
ONLINE_TAG = "[ β’ ONLINE β’ ]"
PROFILE_IMAGE = "https://telegra.ph/file/9f0638dbfa028162a8682.jpg"
# ===============================================================
@bot.on(d3vil_cmd(pattern="offline$", outgoing=True))
async def _(event):
if event.fwd_from:
return
user_it = "me"
user = await event.client.get_entity(user_it)
if user.first_name.startswith(OFFLINE_TAG):
await eod(event, "**Already in Offline Mode.**")
return
await eor(event, "**Changing Profile to Offline...**")
if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
urllib.request.urlretrieve(
"https://telegra.ph/file/a8944f9944ceb3077f1c8.jpg", "donottouch.jpg"
)
photo = "donottouch.jpg"
if photo:
file = await event.client.upload_file(photo)
try:
await bot(functions.photos.UploadProfilePhotoRequest(file))
except Exception as e:
await eod(event, str(e))
else:
await eod(event, "**Changed profile to OffLine.**")
try:
os.system("rm -fr donottouch.jpg")
except Exception as e:
logger.warn(str(e))
last_name = ""
first_name = OFFLINE_TAG
try:
await bot(
functions.account.UpdateProfileRequest(
last_name=last_name, first_name=first_name
)
)
result = "**`{} {}`\nI am Offline now.**".format(first_name, last_name)
await eod(event, result)
except Exception as e:
await eod(event, str(e))
@bot.on(d3vil_cmd(pattern="online$", outgoing=True))
async def _(event):
if event.fwd_from:
return
user_it = "me"
user = await event.client.get_entity(user_it)
if user.first_name.startswith(OFFLINE_TAG):
await eor(event, "**Changing Profile to Online...**")
else:
await eod(event, "**Already Online.**")
return
if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
urllib.request.urlretrieve(PROFILE_IMAGE, "donottouch.jpg")
photo = "donottouch.jpg"
if photo:
file = await event.client.upload_file(photo)
try:
await bot(functions.photos.UploadProfilePhotoRequest(file))
except Exception as e:
await eod(event, str(e))
else:
await eod(event, "**Changed profile to Online.**")
try:
os.system("rm -fr donottouch.jpg")
except Exception as e:
logger.warn(str(e))
first_name = ONLINE_TAG
last_name = ""
try:
await bot(
functions.account.UpdateProfileRequest(
last_name=last_name, first_name=first_name
)
)
result = "**`{} {}`\nI am Online !**".format(first_name, last_name)
await eod(event, result)
except Exception as e:
await eod(event, str(e))
@bot.on(d3vil_cmd(pattern="pbio (.*)"))
async def _(event):
if event.fwd_from:
return
bio = event.pattern_match.group(1)
try:
await bot(
functions.account.UpdateProfileRequest(about=bio)
)
await eod(event, BIO_SUCCESS)
except Exception as e:
await event.edit(str(e))
@bot.on(d3vil_cmd(pattern="pname (.*)"))
async def _(event):
if event.fwd_from:
return
names = event.pattern_match.group(1)
first_name = names
last_name = ""
if "-" in names:
first_name, last_name = names.split("-", 1)
try:
await bot(
functions.account.UpdateProfileRequest(
first_name=first_name, last_name=last_name
)
)
await eod(event, NAME_OK.format(names))
except Exception as e:
await event.edit(str(e))
@bot.on(d3vil_cmd(pattern="ppic"))
async def _(event):
if event.fwd_from:
return
reply_message = await event.get_reply_message()
await event.edit("Downloading Profile Picture to my local ...")
if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
photo = None
try:
photo = await bot.download_media(
reply_message, Config.TMP_DOWNLOAD_DIRECTORY
)
except Exception as e:
await event.edit(str(e))
else:
if photo:
await event.edit("now, Uploading to @Telegram ...")
file = await bot.upload_file(photo)
try:
await bot(
functions.photos.UploadProfilePhotoRequest(
file
)
)
except Exception as e:
await event.edit(str(e))
else:
await eod(event, PP_CHANGED)
try:
os.remove(photo)
except Exception as e:
logger.warn(str(e))
@bot.on(d3vil_cmd(outgoing=True, pattern="username (.*)"))
async def update_username(username):
newusername = username.pattern_match.group(1)
try:
await username.client(UpdateUsernameRequest(newusername))
await eod(username, USERNAME_SUCCESS)
except UsernameOccupiedError:
await eod(username, USERNAME_TAKEN)
@bot.on(d3vil_cmd(outgoing=True, pattern="count$"))
async def count(event):
u = 0
g = 0
c = 0
bc = 0
b = 0
result = ""
await event.edit("`Processing..`")
dialogs = await bot.get_dialogs(limit=None, ignore_migrated=True)
for d in dialogs:
currrent_entity = d.entity
if isinstance(currrent_entity, User):
if currrent_entity.bot:
b += 1
else:
u += 1
elif isinstance(currrent_entity, Chat):
g += 1
elif isinstance(currrent_entity, Channel):
if currrent_entity.broadcast:
bc += 1
else:
c += 1
else:
print(d)
result += f"**ππ»ββοΈ Users :** `{u}`\n\n"
result += f"**ποΈ Groups :** `{g}`\n\n"
result += f"**π Super Groups :** `{c}`\n\n"
result += f"**πΊ Channels :** `{bc}`\n\n"
result += f"**πΎ Bots :** `{b}`"
await event.edit(result)
@bot.on(d3vil_cmd(outgoing=True, pattern=r"delpfp"))
async def remove_profilepic(delpfp):
group = delpfp.text[8:]
if group == "all":
lim = 0
elif group.isdigit():
lim = int(group)
else:
lim = 1
pfplist = await delpfp.client(
GetUserPhotosRequest(user_id=delpfp.sender_id, offset=0, max_id=0, limit=lim)
)
input_photos = []
for sep in pfplist.photos:
input_photos.append(
InputPhoto(
id=sep.id,
access_hash=sep.access_hash,
file_reference=sep.file_reference,
)
)
await delpfp.client(DeletePhotosRequest(id=input_photos))
await eod(delpfp, f"ποΈ **Successfully deleted** `{len(input_photos)}` **profile picture(s).**")
@bot.on(d3vil_cmd(pattern="myusernames$"))
async def _(event):
if event.fwd_from:
return
result = await bot(GetAdminedPublicChannelsRequest())
output_str = ""
for channel_obj in result.chats:
output_str += f"- {channel_obj.title} @{channel_obj.username} \n"
await event.edit(output_str)
CmdHelp("profile").add_command(
"count", None, "Counts your groups, chats, bots etc..."
).add_command(
"myusernames", None, "Shows usernames reserved by you. That is public groups or channels created by you"
).add_command(
"delpfp", "<count> or all", "Deletes your Telegram profile picture(s)."
).add_command(
"pbio", "<text>", "Changes your Telegram bio", ".pbio Hello there, This iz my bio"
).add_command(
"ppic", "<reply to image>", "Changes your Telegram profie picture with the one you replied to"
).add_command(
"pname", "<firstname> or <firstname | lastname>", "Changes Your Telegram account name"
).add_command(
"username", "<new username>", "Changes your Telegram Account Username"
).add_command(
"online", None, "Remove Offline Tag from your name and change profile pic to vars PROFILE_IMAGE."
).add_command(
"offline", None, "Add an offline tag in your name and change profile pic to black."
).add_command(
"kickme", None, "Gets out of the grp..."
).add()