def test_messages_collection(self): bad_words = set() with open(self.messages_collection, 'r', encoding='utf-8') as f: for line in f: bad_words.update(word.lower() for word in Antimat.bad_words(line)) with open(r'..\tmp\antimat\messages_collection_bad.txt', 'w', encoding='utf-8') as f: f.writelines(f'{word}\n' for word in sorted(bad_words))
def test_words(self): bad_words = set() with open(self.words, 'r', encoding='utf-8') as f: for line in f: # self.assertEqual(0, Antimat.bad_words_count(line), line) bad_words.update(word.lower() for word in Antimat.bad_words(line)) with open(r'..\tmp\antimat\words\words_bad.txt', 'w', encoding='utf-8') as f: f.writelines(f'{word}\n' for word in sorted(bad_words))
def test_wp(): bad_words = set() with open(r'..\tmp\antimat\text_for_mat.txt', 'r', encoding='utf-8') as f: for line in f: bad_words.update(word.lower() for word in Antimat.bad_words(line)) with open(r'..\tmp\antimat\text_for_mat_bad.txt', 'w', encoding='utf-8') as f: f.writelines(f'{word}\n' for word in sorted(bad_words))
def cmd_mats(cls, bot: telegram.Bot, update: telegram.Update) -> None: uid = update.message.from_user.id # только админ бота может использовать команду if uid != CONFIG.get('debug_uid', None): return # получаем параметры команды (текст после "/mats ") text = update.message.text.partition(' ')[2].strip() if not text: return # получаем мат mat_words = list(word.lower() for word in Antimat.bad_words(text)) if len(mat_words) == 0: return # отправляем мат matshowtime.send(bot, mat_words)