This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
autoprofile.py
235 lines (191 loc) · 9.24 KB
/
autoprofile.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
# Friendly Telegram (telegram userbot)
# Copyright (C) 2018-2019 The Authors
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import asyncio
import ast
import time
import logging
from io import BytesIO
from telethon.tl import functions
from .. import loader, utils
logger = logging.getLogger(__name__)
try:
from PIL import Image
except ImportError:
pil_installed = False
else:
pil_installed = True
def register(cb):
cb(AutoProfileMod())
@loader.tds
class AutoProfileMod(loader.Module):
"""Automatic stuff for your profile :P"""
strings = {"name": "Automatic Profile",
"missing_pil": "<b>You don't have Pillow installed</b>",
"missing_pfp": "<b>You don't have a profile picture to rotate</b>",
"invalid_args": "<b>Missing parameters, please read the docs</b>",
"invalid_degrees": "<b>Invalid number of degrees to rotate, please read the docs</b>",
"invalid_delete": "<b>Please specify whether to delete the old pictures or not</b>",
"enabled_pfp": "<b>Enabled profile picture rotation</b>",
"pfp_not_enabled": "<b>Profile picture rotation is not enabled</b>",
"pfp_disabled": "<b>Profile picture rotation disabled</b>",
"missing_time": "<b>Time was not specified in bio</b>",
"enabled_bio": "<b>Enabled bio clock</b>",
"bio_not_enabled": "<b>Bio clock is not enabled</b>",
"disabled_bio": "<b>Disabled bio clock</b>",
"enabled_name": "<b>Enabled name clock</b>",
"name_not_enabled": "<b>Name clock is not enabled</b>",
"disabled_name": "<b>Name clock disabled</b>",
"how_many_pfps": "<b>Please specify how many profile pictures should be removed</b>",
"invalid_pfp_count": "<b>Invalid number of profile pictures to remove</b>",
"removed_pfps": "<b>Removed {} profile pic(s)</b>"}
def __init__(self):
self.bio_enabled = False
self.name_enabled = False
self.pfp_enabled = False
self.raw_bio = None
self.raw_name = None
def config_complete(self):
self.name = self.strings["name"]
async def client_ready(self, client, db):
self.client = client
async def autopfpcmd(self, message):
"""Rotates your profile picture every 60 seconds with x degrees, usage:
.autopfp <degrees> <remove previous (last pfp)>
Degrees - 60, -10, etc
Remove last pfp - True/1/False/0, case sensitive"""
if not pil_installed:
return await utils.answer(message, self.strings["missing_pil"])
if not await self.client.get_profile_photos("me", limit=1):
return await utils.answer(message, self.strings["missing_pfp"])
msg = utils.get_args(message)
if len(msg) != 2:
return await utils.answer(message, self.strings["invalid_args"])
try:
degrees = int(msg[0])
except ValueError:
return await utils.answer(message, self.strings["invalid_degrees"])
try:
delete_previous = ast.literal_eval(msg[1])
except (ValueError, SyntaxError):
return await utils.answer(message, self.strings["invalid_delete"])
with BytesIO() as pfp:
await self.client.download_profile_photo("me", file=pfp)
raw_pfp = Image.open(pfp)
self.pfp_enabled = True
pfp_degree = 0
await self.allmodules.log("start_autopfp")
await utils.answer(message, self.strings["enabled_pfp"])
while self.pfp_enabled:
pfp_degree = (pfp_degree + degrees) % 360
rotated = raw_pfp.rotate(pfp_degree)
with BytesIO() as buf:
rotated.save(buf, format="JPEG")
buf.seek(0)
if delete_previous:
await self.client(functions.photos.
DeletePhotosRequest(await self.client.get_profile_photos("me", limit=1)))
await self.client(functions.photos.UploadProfilePhotoRequest(await self.client.upload_file(buf)))
buf.close()
await asyncio.sleep(60)
async def stopautopfpcmd(self, message):
"""Stop autobio cmd."""
if self.pfp_enabled is False:
return await utils.answer(message, self.strings["pfp_not_enabled"])
else:
self.pfp_enabled = False
await self.client(functions.photos.DeletePhotosRequest(
await self.client.get_profile_photos("me", limit=1)
))
await self.allmodules.log("stop_autopfp")
await utils.answer(message, self.strings["pfp_disabled"])
async def autobiocmd(self, message):
"""Automatically changes your account's bio with current time, usage:
.autobio '<message, time as {time}>'"""
msg = utils.get_args(message)
if len(msg) != 1:
return await utils.answer(message, self.strings["invalid_args"])
raw_bio = msg[0]
if "{time}" not in raw_bio:
return await utils.answer(message, self.strings["missing_time"])
self.bio_enabled = True
self.raw_bio = raw_bio
await self.allmodules.log("start_autobio")
await utils.answer(message, self.strings["enabled_bio"])
while self.bio_enabled is True:
current_time = time.strftime("%H:%M")
bio = raw_bio.format(time=current_time)
await self.client(functions.account.UpdateProfileRequest(
about=bio
))
await asyncio.sleep(60)
async def stopautobiocmd(self, message):
"""Stop autobio cmd."""
if self.bio_enabled is False:
return await utils.answer(message, self.strings["bio_not_enabled"])
else:
self.bio_enabled = False
await self.allmodules.log("stop_autobio")
await utils.answer(message, self.strings["disabled_bio"])
await self.client(functions.account.UpdateProfileRequest(about=self.raw_bio.format(time="")))
async def autonamecmd(self, message):
"""Automatically changes your Telegram name with current time, usage:
.autoname '<message, time as {time}>'"""
msg = utils.get_args(message)
if len(msg) != 1:
return await utils.answer(message, self.strings["invalid_args"])
raw_name = msg[0]
if "{time}" not in raw_name:
return await utils.answer(message, self.strings["missing_time"])
self.name_enabled = True
self.raw_name = raw_name
await self.allmodules.log("start_autoname")
await utils.answer(message, self.strings["enabled_name"])
while self.name_enabled is True:
current_time = time.strftime("%H:%M")
name = raw_name.format(time=current_time)
await self.client(functions.account.UpdateProfileRequest(
first_name=name
))
await asyncio.sleep(60)
async def stopautonamecmd(self, message):
""" Stop autoname cmd."""
if self.name_enabled is False:
return await utils.answer(message, self.strings["name_not_enabled"])
else:
self.name_enabled = False
await self.allmodules.log("stop_autoname")
await utils.answer(message, self.strings["disabled_name"])
await self.client(functions.account.UpdateProfileRequest(
first_name=self.raw_name.format(time="")
))
async def delpfpcmd(self, message):
""" Remove x profile pic(s) from your profile.
.delpfp <pfps count/unlimited - remove all>"""
args = utils.get_args(message)
if not args:
return await utils.answer(message, self.strings["how_many_pfps"])
if args[0].lower() == "unlimited":
pfps_count = None
else:
try:
pfps_count = int(args[0])
except ValueError:
return await utils.answer(message, self.strings["invalid_pfp_count"])
if pfps_count <= 0:
return await utils.answer(message, self.strings["invalid_pfp_count"])
await self.client(functions.photos.DeletePhotosRequest(await self.client.get_profile_photos("me",
limit=pfps_count)))
if pfps_count is None:
pfps_count = _("all")
await self.allmodules.log("delpfp")
await utils.answer(message, self.strings["removed_pfps"].format(str(pfps_count)))