format Black

This commit is contained in:
Rykov7
2023-02-22 18:53:12 +03:00
parent 23a93b5dbd
commit d0cf0762c8
13 changed files with 356 additions and 205 deletions
+46 -23
View File
@@ -9,14 +9,18 @@ from .filters import is_white, is_nongrata
def speak(chance_of):
number = random.randint(0, chance_of)
if number == 0:
return random.choice([i.rstrip() for i in open('Stan.txt', 'r', encoding='utf8') if i])
return random.choice(
[i.rstrip() for i in open("Stan.txt", "r", encoding="utf8") if i]
)
def send_quote(after_sec, message, quote):
""" Pretend Reading, pretend Typing, send. """
"""Pretend Reading, pretend Typing, send."""
if message.text:
sleep(len(message.text) * 0.13 / 4) # Reading time is quarter of the same text writing time
bot.send_chat_action(message.chat.id, action='typing')
sleep(
len(message.text) * 0.13 / 4
) # Reading time is quarter of the same text writing time
bot.send_chat_action(message.chat.id, action="typing")
sleep(after_sec) # Typing time
bot.send_message(message.chat.id, quote)
@@ -24,37 +28,56 @@ def send_quote(after_sec, message, quote):
def act(message):
quote = speak(50)
if quote:
threading.Thread(target=send_quote, args=(len(quote) * 0.13, message, quote)).start()
threading.Thread(
target=send_quote, args=(len(quote) * 0.13, message, quote)
).start()
@bot.message_handler(func=is_white, commands=['add'])
@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:
if message.reply_to_message.text not in (i.rstrip() for i in open('Stan.txt', 'r', encoding='utf8')):
stan_quotes.write(message.reply_to_message.text.replace('\n', ' ') + '\n')
bot.send_message(message.chat.id,
'✅ <b>Добавил</b>\n └ <i>' + message.reply_to_message.text.replace("\n",
" ") + '</i>')
with open("Stan.txt", "a", encoding="utf8") as stan_quotes:
if message.reply_to_message.text not in (
i.rstrip() for i in open("Stan.txt", "r", encoding="utf8")
):
stan_quotes.write(
message.reply_to_message.text.replace("\n", " ") + "\n"
)
bot.send_message(
message.chat.id,
"✅ <b>Добавил</b>\n └ <i>"
+ message.reply_to_message.text.replace("\n", " ")
+ "</i>",
)
else:
bot.send_message(message.chat.id,
f'⛔️ <b>Не добавил</b>, есть токое\n └ <i>{message.reply_to_message.text}</i>')
bot.send_message(
message.chat.id,
f"⛔️ <b>Не добавил</b>, есть токое\n └ <i>{message.reply_to_message.text}</i>",
)
@bot.message_handler(func=is_white, commands=['remove'])
@bot.message_handler(func=is_white, commands=["remove"])
def remove_stan_quote(message):
if message.reply_to_message and message.reply_to_message.text:
if message.reply_to_message.text in (i.rstrip() for i in open('Stan.txt', 'r', encoding='utf8')):
quotes = list(open('Stan.txt', 'r', encoding='utf8'))
with open('Stan.txt', 'w', encoding='utf8') as stan_quotes:
quotes.remove(message.reply_to_message.text + '\n')
if message.reply_to_message.text in (
i.rstrip() for i in open("Stan.txt", "r", encoding="utf8")
):
quotes = list(open("Stan.txt", "r", encoding="utf8"))
with open("Stan.txt", "w", encoding="utf8") as stan_quotes:
quotes.remove(message.reply_to_message.text + "\n")
stan_quotes.writelines(quotes)
bot.send_message(message.chat.id, f'✅ <b>Удалил</b>\n └ <i>{message.reply_to_message.text}</i>')
bot.send_message(
message.chat.id,
f"✅ <b>Удалил</b>\n └ <i>{message.reply_to_message.text}</i>",
)
else:
bot.send_message(message.chat.id, f'⛔️ <b>Нет такого</b>\n └ <i>{message.reply_to_message.text}</i>')
bot.send_message(
message.chat.id,
f"⛔️ <b>Нет такого</b>\n └ <i>{message.reply_to_message.text}</i>",
)
@bot.message_handler(func=is_nongrata)
def tease_nongrata(message: types.Message):
""" Reply to non grata mentions. """
bot.reply_to(message, f'у нас тут таких не любят')
"""Reply to non grata mentions."""
bot.reply_to(message, f"у нас тут таких не любят")