From a83bd54da862012b9fc8d0f37c9075ebb6cdfa7f Mon Sep 17 00:00:00 2001 From: Rykov7 Date: Tue, 3 Jan 2023 00:42:33 +0300 Subject: [PATCH] improve adding quotes, improve reading quotes --- README.md | 7 +++---- Stan.txt | 8 +++++++- app/bot.py | 10 +++++++--- app/config.py | 2 +- app/stan.py | 3 +-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4c7baeb..b14b8a8 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,16 @@ Multipurpose Telegram Bot for Python group ### What does this project do? * Send links on command (chat rules, FAQs, libraries etc.) * Ban users and delete messages - * Filter links * Remind dates - * Daily statistics publication (how many banned, deleted, sent messages) + * Report Daily statistics (how many banned, deleted, sent messages) * Search for the Zen of Python quotes (inline query) * Help users with googling their queries * Make faces when doubtful bloggers are mentioned - * Etc. (functionality is growing up) + * Etc. ### Why is this project useful? You can use this project as a pre-coded customizable bot. -Original (and currently working) bot Telegram username: @LutzPyBot +Original (and currently working example) bot Telegram username: @LutzPyBot ### How to deploy it? 1. Clone repository on your linux server into `lutzpybot` user's home directory. diff --git a/Stan.txt b/Stan.txt index f64a555..890cf7c 100644 --- a/Stan.txt +++ b/Stan.txt @@ -350,4 +350,10 @@ facepalm.jpg заметьте, поясняют профессиональные программисты действительно, ведь не будет же кто-то врать в интернете за деньги? все, уговорил, пиши на киви -я буду скучать по некоторым из вас \ No newline at end of file +я буду скучать по некоторым из вас +да штош это, блин, такое +не спится человеку, курлит с утра +не бережешь ты себя, золотой ты человек +🦔 +наш человек че там +хренасси год начинается, в чате питон обсуждают \ No newline at end of file diff --git a/app/bot.py b/app/bot.py index 40c51ce..1a12d78 100644 --- a/app/bot.py +++ b/app/bot.py @@ -266,9 +266,13 @@ def list_jobs(message): @bot.message_handler(func=is_white, commands=['add']) def add_stan_quote(message): if message.reply_to_message and message.reply_to_message.text: - with open('Stan.txt', 'a', encoding='utf8') as stan_quotes: - stan_quotes.write('\n' + message.reply_to_message.text) - bot.send_message(message.chat.id, f'Добавил: {message.reply_to_message.text}') + with open('Stan.txt', 'a+', encoding='utf8') as stan_quotes: + if message.reply_to_message.text not in (i.rstrip() for i in stan_quotes): + stan_quotes.write('\n' + message.reply_to_message.text) + bot.send_message(message.chat.id, f'✅ Добавил\n └ {message.reply_to_message.text}') + else: + bot.send_message(message.chat.id, + f'⛔️ Не добавил, есть токое\n └ {message.reply_to_message.text}') @bot.message_handler(func=is_admin, commands=['stats']) diff --git a/app/config.py b/app/config.py index e9b1f68..db9c92d 100644 --- a/app/config.py +++ b/app/config.py @@ -37,7 +37,7 @@ LIB = '📚 Библиоте SPAM = ['me.sv/', 'tg.sv/', 'goo.by/', 'go.sv/', 'intim.video/', 'uclck.ru/'] NON_GRATA = ['дудар', 'хауди', 'dudar'] -BAN_WORDS = ['GREEN ROOM'] +BAN_WORDS = ['GREEN'] ZEN = ['Beautiful is better than ugly.', 'Explicit is better than implicit.', 'Simple is better than complex.', 'Complex is better than complicated.', 'Flat is better than nested.', 'Sparse is better than dense.', diff --git a/app/stan.py b/app/stan.py index e477b42..d061767 100644 --- a/app/stan.py +++ b/app/stan.py @@ -1,10 +1,9 @@ """ Stan quote generator. """ import random -quotes = [i.rstrip() for i in open('Stan.txt', 'r', encoding='utf8')] - def speak(chance_of): number = random.randint(0, chance_of) if number == 0: + quotes = (i.rstrip() for i in open('Stan.txt', 'r', encoding='utf8')) return random.choice(quotes)