some fixes

This commit is contained in:
KatykhinAA
2024-06-03 19:45:04 +03:00
parent c70219b481
commit 00bb2fa74e
4 changed files with 868 additions and 854 deletions

50
main.py
View File

@@ -66,24 +66,25 @@ def telegram_bot():
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
item1 = types.KeyboardButton("📢Предложить свой пост")
item2 = types.KeyboardButton("📩Связаться с админами")
item3 = types.KeyboardButton("❌Удалить пост")
# TODO: Выпилил, удалить
#item3 = types.KeyboardButton("❌Удалить пост")
if BotDB.user_exists(user_id):
is_need_sticker = BotDB.get_info_about_stickers(user_id=message.from_user.id)
if is_need_sticker == 0:
item5 = types.KeyboardButton("🤪Хочу стикеры")
BotDB.update_info_about_stickers(user_id=message.from_user.id)
markup.add(item1, item2, item3, item5)
markup.add(item1, item2, item5)
else:
markup.add(item1, item2, item3)
markup.add(item1, item2)
else:
BotDB.add_new_user_in_db(user_id, first_name, full_name, username, is_bot, language_code, date_added, date_changed)
is_need_sticker = BotDB.get_info_about_stickers(user_id=message.from_user.id)
if is_need_sticker == 0:
item5 = types.KeyboardButton("🤪Хочу стикеры")
BotDB.update_info_about_stickers(user_id=message.from_user.id)
markup.add(item1, item2, item3, item5)
markup.add(item1, item2, item5)
else:
markup.add(item1, item2, item3)
markup.add(item1, item2)
hello_message = BotDB.get_message_from_db('start_message', first_name)
bot.send_message(message.chat.id, hello_message, parse_mode='html', reply_markup=markup, disable_web_page_preview=not PREVIEW_LINK)
except:
@@ -96,9 +97,10 @@ def telegram_bot():
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
item1 = types.KeyboardButton("📢Предложить свой пост")
item2 = types.KeyboardButton("📩Связаться с админами")
item3 = types.KeyboardButton("❌Удалить пост")
# TODO: Скрыл, удалить обработчик
#item3 = types.KeyboardButton("❌Удалить пост")
item5 = types.KeyboardButton("👋🏼Сказать пока!")
markup.add(item1, item2, item3, item5)
markup.add(item1, item2, item5)
bot.send_message(message.chat.id,
"Выбери нужную кнопку внизу экрана".format(
message.from_user, bot.get_me()),
@@ -180,9 +182,10 @@ def telegram_bot():
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
item1 = types.KeyboardButton("📢Предложить свой пост")
item2 = types.KeyboardButton("📩Связаться с админами")
item3 = types.KeyboardButton("❌Удалить пост")
# TODO: Скрыл кнопку, убрать обработчик позднее
#item3 = types.KeyboardButton("❌Удалить пост")
item5 = types.KeyboardButton("👋🏼Сказать пока!")
markup.add(item1, item2, item3, item5)
markup.add(item1, item2, item5)
try:
if LOGS:
bot.forward_message(chat_id=GROUP_FOR_LOGS,
@@ -239,6 +242,23 @@ def telegram_bot():
)
elif message.content_type == 'photo' and message.media_group_id == None:
post_text_for_photo = message.caption.lower()
if post_text_for_photo.find('неанон') != -1 or post_text_for_photo.find('не анон') != -1:
bot.send_photo(
# TODO: GROUP_FOR_POST
chat_id=GROUP_FOR_POST,
caption=f'Пост из ТГ:\n{post_text_for_photo}\n\nАвтор поста: {message.from_user.first_name} @{message.from_user.username}',
photo=message.photo[-1].file_id,
reply_markup=markup
)
elif post_text_for_photo.find('анон') != -1 or post_text_for_photo.find('анон') != -1:
bot.send_photo(
# TODO: GROUP_FOR_POST
chat_id=GROUP_FOR_POST,
caption=f'Пост из ТГ:\n{post_text_for_photo}\n\nПост опубликован анонимно',
photo=message.photo[-1].file_id,
reply_markup=markup
)
else:
bot.send_photo(
# TODO: GROUP_FOR_POST
chat_id=GROUP_FOR_POST,
@@ -310,16 +330,10 @@ def telegram_bot():
if __name__ == '__main__':
telegram_bot()
while True:
try:
bot.polling(none_stop=True)
bot.enable_save_next_step_handlers(delay=2)
bot.load_next_step_handlers()
except ConnectionError as e:
if LOGS:
bot.send_message(IMPORTANT_LOGS, "Ошибка соединения, потерял связь")
except Exception as r:
if LOGS:
bot.send_message(IMPORTANT_LOGS, "Произошло что-то непредвиденное, хелп")
finally:
if LOGS:
bot.send_message(IMPORTANT_LOGS, 'Я упал, помогите')
except (ConnectionError, Exception):
print("Произошла ошибка, перезапуск бота")