-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRandomPasswordGenerator.py
More file actions
198 lines (184 loc) · 8.44 KB
/
RandomPasswordGenerator.py
File metadata and controls
198 lines (184 loc) · 8.44 KB
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
__version__ = (2, 0, 0)
#
# @@@@@@ @@@@@@ @@@@@@@ @@@@@@@ @@@@@@ @@@@@@@@@@ @@@@@@ @@@@@@@ @@@ @@@ @@@ @@@@@@@@ @@@@@@
# @@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@@@@ @@@@@@@@ @@@@@@@@ @@@ @@@ @@@ @@@@@@@@ @@@@@@@
# @@! @@@ !@@ @@! @@! @@@ @@! @@@ @@! @@! @@! @@! @@@ @@! @@@ @@! @@@ @@! @@! !@@
# !@! @!@ !@! !@! !@! @!@ !@! @!@ !@! !@! !@! !@! @!@ !@! @!@ !@! @!@ !@! !@! !@!
# @!@!@!@! !!@@!! @!! @!@!!@! @!@ !@! @!! !!@ @!@ @!@ !@! @!@ !@! @!@ !@! @!! @!!!:! !!@@!!
# !!!@!!!! !!@!!! !!! !!@!@! !@! !!! !@! ! !@! !@! !!! !@! !!! !@! !!! !!! !!!!!: !!@!!!
# !!: !!! !:! !!: !!: :!! !!: !!! !!: !!: !!: !!! !!: !!! !!: !!! !!: !!: !:!
# :!: !:! !:! :!: :!: !:! :!: !:! :!: :!: :!: !:! :!: !:! :!: !:! :!: :!: !:!
# :: ::: :::: :: :: :: ::: ::::: :: ::: :: ::::: :: :::: :: ::::: :: :: :::: :: :::: :::: ::
# : : : :: : : : : : : : : : : : : : : :: : : : : : : :: : : : :: :: :: : :
#
# © Copyright 2024
#
# https://t.me/Den4ikSuperOstryyPer4ik
# and
# https://t.me/ToXicUse
#
# 🔒 Licensed under the GNU AGPLv3
# https://www.gnu.org/licenses/agpl-3.0.html
#
# meta developer: @AstroModules
# meta banner: https://raw.githubusercontent.com/Den4ikSuperOstryyPer4ik/Astro-modules/main/Banners/PasswordGenerator.jpg
import logging
import random
from telethon.tl.types import Message
from .. import loader, utils
from ..inline.types import InlineCall
logger = logging.getLogger(__name__)
@loader.tds
class PasswordGeneratorMod(loader.Module):
'''Random password/pincode generator'''
strings = {
"name": "RandomPasswordGenerator",
"_cfg_doc_pass_length": "set password length (in number of characters)",
"_cfg_doc_pin_code_length": "set pincode length (in number of characters)",
"_cfg_doc_simbols_in_pass": (
"Will there be additional characters in the generated password"
" (+-*!&$#?=@<>)?"
),
"what_to_generate": "🆗What should be generated?",
"new_random_pass": "🔣 new random password 🆕",
"new_random_pincode": "🔢 new random PIN-code 🆕",
"pass": "<b>🆕 Your new password in {} characters:\n<code>{}</code></b>",
"pincode": "<b>🆕 Your new pincode in {} characters:\n<code>{}</code></b>",
"menu": "💻 Menu",
"close": "🚫 Close",
}
strings_ru = {
"_cls_doc": (
"Генератор рандомного пароля/пин-кода\nНастроить генератор можно через"
" конфиг"
),
"_cfg_doc_pass_length": "выставьте длину пароля(в кол-ве символов)",
"_cfg_doc_pin_code_length": "выставьте длину Пин-Кода(в кол-ве символов)",
"_cfg_doc_simbols_in_pass": (
"Какие символы должны быть в сгенерированном пароле?"
),
"what_to_generate": "🆗 Что надо сгенерировать?",
"new_random_pass": "🔣 Новый рандомный пароль 🆕",
"new_random_pincode": "🔢 Новый рандомный PIN-код 🆕",
"pass": "<b>🆕 Ваш новый пароль в {} символов:\n<code>{}</code></b>",
"pincode": "<b>🆕 Ваш новый пин-код в {} символов:</b>\n<code>{}</code>",
"menu": "💻 Меню",
"close": "🚫 Закрыть",
}
@loader.command(ru_doc="—>конфиг этого модуля")
async def generatorcfgcmd(self, message: Message):
"""—>config for this module"""
name = self.strings("name")
await self.allmodules.commands["config"](
await utils.answer(message, f"{self.get_prefix()}config {name}")
)
def __init__(self):
self._ratelimit = []
self.config = loader.ModuleConfig(
loader.ConfigValue(
"password_length",
10,
doc=lambda: self.strings("_cfg_doc_pass_length"),
validator=loader.validators.Integer(minimum=6),
),
loader.ConfigValue(
"pincode_length",
4,
doc=lambda: self.strings("_cfg_doc_pin_code_length"),
validator=loader.validators.Integer(minimum=4),
),
loader.ConfigValue(
"symbols",
"+-*!&$?=@<>abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
doc=lambda: self.strings("_cfg_doc_simbols_in_pass"),
),
)
@loader.command(ru_doc="—>сгенерировать случайный пароль/пин-код")
async def igeneratorcmd(self, message: Message):
"""—>generate random password/pin"""
await self.inline.form(
self.strings("what_to_generate"),
reply_markup=[
[
{
"text": self.strings("new_random_pass"),
"callback": self.new_random_pass,
}
],
[
{
"text": self.strings("new_random_pincode"),
"callback": self.new_random_pincode,
}
],
[{"text": self.strings("close"), "action": "close"}],
],
message=message,
)
async def igenerator(self, call: InlineCall):
await call.edit(
self.strings("what_to_generate"),
reply_markup=[
[
{
"text": self.strings("new_random_pass"),
"callback": self.new_random_pass,
}
],
[
{
"text": self.strings("new_random_pincode"),
"callback": self.new_random_pincode,
}
],
[{"text": self.strings("close"), "action": "close"}],
],
)
async def new_random_pass(self, call: InlineCall):
symbols = self.config["symbols"]
password_length = self.config["password_length"]
length = int(password_length)
password = ""
for _ in range(length):
password += random.choice(symbols)
await call.edit(
self.strings["pass"].format(password_length, password),
reply_markup=[
[
{
"text": self.strings("menu"),
"callback": self.igenerator
}
],
[
{
"text": self.strings("close"),
"action": "close"
}
],
],
)
async def new_random_pincode(self, call: InlineCall):
pincode_length = self.config["pincode_length"]
chars = "1234567890"
length = int(self.config["pincode_length"])
pincode = ""
for _ in range(length):
pincode += random.choice(chars)
await call.edit(
self.strings["pincode"].format(pincode_length, pincode),
reply_markup=[
[
{
"text": self.strings("menu"),
"callback": self.igenerator
}
],
[
{
"text": self.strings("close"),
"action": "close"
}
],
],
)