Repository navigation
Expand file tree
/
Copy pathmain_funcs.py
More file actions
205 lines (152 loc) · 7.87 KB
/
Copy pathmain_funcs.py
File metadata and controls
205 lines (152 loc) · 7.87 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
199
200
201
202
203
204
205
import re
from telegram import Update
from telegram.ext import ConversationHandler
from db_model_data import Emails, Telephons, select_from_tables, add_telephons, add_emails
telephons_string = None
emails_string = None
def start(update: Update, _) -> None:
user = update.effective_user
update.message.reply_text(f'Приветствую {user.first_name}, aka {user.username}, USER ID: {user.id}')
def my_help(update: Update, _) -> None:
help_str = ('/start - поприветствует\n'
'/help - список доступных команд\n'
'/exit - выход, если застрял\n'
'/find_tel_numbers - поиск телефона в тексте\n'
'/find_emails - поиск электронного адреса в тексте\n'
'/verify_password - валидация пароля\n'
'/get_release - посмотреть релиз\n'
'/get_uname - архитектуру\n'
'/get_uptime - время работы\n'
'/get_df - место\n'
'/get_free - утилизация оперативки\n'
'/get_mpstat - производительность\n'
'/get_w - пользователи в системе\n'
'/get_auths - последние 10 юзеров\n'
'/get_critical - ошибки ядра\n'
'/get_ps - процессы\n'
'/get_ss - порты\n'
'/packages_services - установленные пакеты и службы ОС\n'
'/get_repl_logs - логи реплики\n'
'/get_emails - получить имейлы из базы\n'
'/get_phone_numbers - получить номера')
update.message.reply_text(help_str)
def echo(update: Update, _) -> None:
update.message.reply_text(update.message.text)
def find_tel_numbers_command(update: Update, _) -> str:
update.message.reply_text('Давай, где искать: ')
return 'find_tel_numbers'
def find_tel_numbers(update: Update, _) -> int | str:
user_input = update.message.text
find_pat = re.compile(r'[\+7|8][\d(\s-]*[\d)\s]*') # [\+7|8][\d(\s-]*[\d)\s]*
find_result = find_pat.findall(user_input)
if find_result:
str_numbers = ''
for my_index in range(len(find_result)):
str_numbers += f'{my_index + 1}.\t{find_result[my_index]}\n'
update.message.reply_text(f'<pre language="python">{str_numbers}</pre>', parse_mode='HTML')
global telephons_string # запретная магия, за такое наказывают
telephons_string = str_numbers
update.message.reply_text('Хотелось бы Вам любезнейший, сохранить результаты в базку?')
# return ConversationHandler.END # <class 'int'> -1
return 'telephone_step'
else:
update.message.reply_text('Нет номеров!')
return ConversationHandler.END
def write_tel_numbers(update: Update, _) -> int:
if telephons_string:
list_of_tels = telephons_string.splitlines(keepends=True)
for num in list_of_tels:
_, tel = num.split('\t')
clean_num = tel.replace('\n', '')
try:
add_telephons(my_num=clean_num)
except Exception as exp:
update.message.reply_text(exp)
update.message.reply_text('Хорошо, сохраняю!')
return ConversationHandler.END
else:
update.message.reply_text('Нет номеров!')
return ConversationHandler.END
def get_from_the_database_telephons(update: Update, _) -> int: # TODO добавить elif для строк более 4096
query_tels = Telephons.id, Telephons.number
telephons = select_from_tables(many_data=query_tels)
if telephons:
str_tels = ''
for ind, tel in telephons:
str_tels += f'{ind}. {tel}\n'
update.message.reply_text(f'<pre language="python">{str_tels}</pre>', parse_mode='HTML')
return ConversationHandler.END
else:
update.message.reply_text('В базе пусто!')
return ConversationHandler.END
def find_emails_command(update: Update, _) -> str:
update.message.reply_text('Ладно уж, по ищу ка я твои имэйлы: ')
return 'find_emails'
def find_emails(update: Update, _) -> int | str:
user_input = update.message.text
find_pat = re.compile(r'[\w\.-]+@[\w-]+\.[a-zа-я]{2,9}')
find_result = find_pat.findall(user_input)
if find_result:
str_numbers = ''
for my_index, email in enumerate(find_result, start=1):
str_numbers += f'{my_index}.\t{email}\n'
update.message.reply_text(f'<pre language="python">{str_numbers}</pre>', parse_mode='HTML')
global emails_string
emails_string = str_numbers
update.message.reply_text('Хотелось бы Вам любезнейший, сохранить результаты в базку?')
return 'email_step'
else:
update.message.reply_text('Нет ни каких имэйлов!')
return ConversationHandler.END
def write_emails(update: Update, _) -> int:
if emails_string:
list_of_emails = emails_string.splitlines(keepends=True)
for ema in list_of_emails:
_, email = ema.split('\t')
clean_email = email.replace('\n', '')
try:
add_emails(my_ema=clean_email)
except Exception as exp:
update.message.reply_text(exp)
update.message.reply_text('Хорошо, сохраняю!')
return ConversationHandler.END
else:
update.message.reply_text('Нет имейлов!')
return ConversationHandler.END
def get_from_the_database_emails(update: Update, _) -> int: # TODO добавить elif для строк более 4096
query_emails = Emails.id, Emails.email
mails = select_from_tables(many_data=query_emails)
if mails:
str_emails = ''
for ind, email in mails:
str_emails += f'{ind}. {email}\n'
update.message.reply_text(f'<pre language="python">{str_emails}</pre>', parse_mode='HTML')
return ConversationHandler.END
else:
update.message.reply_text('В базе пусто!')
return ConversationHandler.END
def check_pas_command(update: Update, _) -> str:
update.message.reply_text('Мне нужен твой байк, простите, пароль: ')
return 'check_pas'
def check_pas(update: Update, _) -> int:
user_input = update.message.text
if not re.search(r'^.{8,}$', user_input):
update.message.reply_text('Ваш пароль мог быть и подлиннее, обидно как то даже.')
return ConversationHandler.END
elif not re.search(r'(?=.*[A-Z])', user_input):
update.message.reply_text('Не нашёл букв по крупнее, мелочь одна.')
return ConversationHandler.END
elif not re.search(r'(?=.*[a-z])', user_input):
update.message.reply_text('Не капси, добавь пару мелких букв.')
return ConversationHandler.END
elif not re.search(r'(?=.*[0-9])', user_input):
update.message.reply_text('А где же числа?')
return ConversationHandler.END
elif not re.search(r'(?=.*[!@#$%^&*()])', user_input):
update.message.reply_text('Отсыпь спецсимволов не жадничай.')
return ConversationHandler.END
else:
update.message.reply_text('Впечатляет, всё как надо, обнимаю твои мысли, всё на созвоне.')
return ConversationHandler.END
def my_exit(update: Update, _) -> int:
return ConversationHandler.END