-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavachanger.py
96 lines (65 loc) · 3.56 KB
/
avachanger.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
# █▀▀ ▄▀█ █▀▄▀█ █▀█ █▀▄ █▀
# █▀░ █▀█ █░▀░█ █▄█ █▄▀ ▄█
# https://t.me/famods
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# ---------------------------------------------------------------------------------
# Name: AvaChanger
# Description: Смена аватарки по времени
# meta developer: @FAmods
# meta banner: https://github.com/FajoX1/FAmods/blob/main/assets/banners/avachanger.png?raw=true
# ---------------------------------------------------------------------------------
import os
import asyncio
import tempfile
import logging
from telethon.tl.functions.photos import UploadProfilePhotoRequest
from .. import loader, utils
logger = logging.getLogger(__name__)
@loader.tds
class AvaChanger(loader.Module):
"""Смена аватарки по времени"""
strings = {
"name": "AvaChanger",
"no_args": "<emoji document_id=5440381017384822513>❌</emoji> <b>Нужно <code>{}avatarl [сколько раз] [сколько ждать перед сменой каждой аватарки]</code></b>",
"no_reply": "<emoji document_id=5440381017384822513>❌</emoji> <b>Нужно ответить на сообщение с фоткой</b>",
"changing_avatars": "<emoji document_id=5328274090262275771>🔄</emoji> <b>Меняю аватарки...</b>\n<i>⏳ Это займёт {} секунд</i>",
"was_off": "<emoji document_id=5440381017384822513>❌</emoji> <b>Смена аватарки была выключена!</b>",
"off": "<b><emoji document_id=5212932275376759608>✅</emoji> Выключил смену аватарки</b>",
"completed": "<b><emoji document_id=5212932275376759608>✅</emoji> Готово. Сменил аватарку {} раз за {} секунд/</b>",
}
async def client_ready(self, client, db):
self.db = db
self._client = client
@loader.command()
async def avatarl(self, message):
"""Смена аватарки по времени"""
args = utils.get_args_raw(message)
try:
counts, time_c = args.split(" ")
counts = int(counts)
time_c = int(time_c)
except:
return await utils.answer(message, self.strings['no_args'].format(self.get_prefix()))
r = await message.get_reply_message()
if not r:
return await utils.answer(message, self.strings['no_reply'])
m = await utils.answer(message, self.strings['changing_avatars'].format((time_c * counts)))
self.m = m
with tempfile.TemporaryDirectory() as temp_dir:
file_path = os.path.join(temp_dir, os.path.basename("avatar.jpg"))
await message.client.download_media(r.media.photo, file_path)
for i in range(counts):
if not self.m:
return
await self.client(UploadProfilePhotoRequest(file=await self.client.upload_file(file_path)))
await asyncio.sleep(time_c)
self.m = None
await utils.answer(message, self.strings['completed'].format(counts, (time_c * counts)))
@loader.command()
async def avatarl_stop(self, message):
"""Выключить смену аватарки по времени"""
m = self.m
self.m = None
await utils.answer(m, self.strings['was_off'])
await utils.answer(message, self.strings['off'])