-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtexttools.py
84 lines (65 loc) · 3.34 KB
/
texttools.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
# Sh1t-UB (telegram userbot by sh1tn3t)
# Copyright (C) 2021-2022 Sh1tN3t
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import io
import tempfile
from string import hexdigits
from random import choice, randint
from pyrogram import Client, types
from .. import loader, utils
@loader.module(name="TextTools", author="sh1tn3t")
class TextToolsMod(loader.Module):
"""Инструменты для текста"""
async def switch_cmd(self, app: Client, message: types.Message, args: str):
"""Поменять раскладку текста. Использование: switch <аргументы или реплай>"""
reply = message.reply_to_message
text = (
args
if args
else reply.text
if reply and reply.text
else reply.caption
if reply and reply.caption
else None
)
if not text:
return await utils.answer(
message, "<b>[TextTools]</b> Нет аргументов или реплая на текст")
ru_keys = """ёйцукенгшщзхъфывапролджэячсмитьбю.Ё"№;%:?ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭ/ЯЧСМИТЬБЮ,"""
en_keys = """`qwertyuiop[]asdfghjkl;'zxcvbnm,./~@#$%^&QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?"""
change = str.maketrans(ru_keys + en_keys, en_keys + ru_keys)
result = str.translate(text, change)
return await utils.answer(message, result)
async def mtf_cmd(self, app: Client, message: types.Message, args: str):
"""Текст с реплая в файл. Использование: mtf <реплай на текст> [название]"""
reply = message.reply_to_message
if not (reply and reply.text):
return await utils.answer(
message, "<b>[TextTools]</b> Нет реплая на текст")
file_name = (
"".join(choice(hexdigits) for _ in range(randint(5, 10))) + ".txt"
) if not args else args
file = io.BytesIO(bytes(reply.text, "utf-8"))
file.name = file_name
file.seek(0)
await utils.answer(message, file, doc=True)
return await message.delete()
async def ftm_cmd(self, app: Client, message: types.Message):
"""Файл в текст. Использование: ftm <реплай на файл>"""
reply = message.reply_to_message
if not reply and reply.documemt:
return await utils.answer(
message, "<b>[TextTools]</b> Нет реплая на файл")
file = tempfile.NamedTemporaryFile("w")
await reply.download(file.name)
return await utils.answer(
message, open(file.name, "r").read())