Guest User

main.py

a guest
Aug 15th, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3.  
  4. import telebot
  5. import config
  6. import db
  7. import bot_code
  8.  
  9.  
  10. # Инициализация API и СУБД
  11. bot = telebot.TeleBot(config.TOKEN, skip_pending=True)
  12. bot_code.bot = bot
  13. db.init_db(config.FORCE_DB)
  14.  
  15.  
  16. # Обработка Inline клавиш
  17. @bot.callback_query_handler(func=lambda call: True)
  18. def callback_inline(call):
  19. bot_code.callback_inline(call)
  20.  
  21.  
  22. # TODO: изменить текст
  23. @bot.message_handler(commands=['start'])
  24. def command_start(message):
  25. bot_code.start_command_handler(message)
  26.  
  27.  
  28. # TODO: изменить текст
  29. @bot.shipping_query_handler(func=lambda query: True)
  30. def payment_error_server(shipping_query):
  31. bot_code.payment_error_server(shipping_query)
  32.  
  33.  
  34. # TODO: изменить текст
  35. @bot.pre_checkout_query_handler(func=lambda query: True)
  36. def payment_error_bot(pre_checkout_query):
  37. bot_code.payment_error_bot(pre_checkout_query)
  38.  
  39.  
  40. @bot.message_handler(content_types=['successful_payment'])
  41. def payment_success(message):
  42. print(message.successful_payment)
  43. print()
  44. print(message)
  45. bot_code.payment_success(message)
  46.  
  47.  
  48. """
  49. @bot.channel_post_handler(content_types=['text'])
  50. def channel_post_handler(message):
  51. bot_code.channel_post_handler(bot, message)
  52. """
  53.  
  54.  
  55. # TODO: доработать
  56. @bot.message_handler(content_types=['text'])
  57. def text_handler(message):
  58. if message.text.lower() in config.WORDS['account_text']:
  59. bot_code.subscribe_handler(message, account=True)
  60.  
  61. elif message.text.lower() in config.WORDS['subscribe_text']:
  62. bot_code.subscribe_handler(message, account=False)
  63.  
  64. elif message.text.lower() in config.WORDS['add_channel']:
  65. bot_code.add_channel_handler(message)
  66.  
  67. elif message.text.lower() in config.WORDS['create_post_riddle']:
  68. bot_code.create_post_handler(message)
  69.  
  70. elif message.text.lower() in config.WORDS['create_post_surwey']:
  71. bot_code.create_post_handler(message, surwey=True, buttons=False)
  72.  
  73. elif message.text.lower() == 'пересоздать бд' and message.from_user.id in config.OWNER:
  74. db.init_db(force=True)
  75. bot.send_message(message.chat.id,
  76. 'База данных очищена! 🎉',
  77. reply_markup=config.standart_markup(),
  78. parse_mode='HTML'
  79. )
  80.  
  81. elif message.text.lower().startswith(config.WORDS['gift']) and message.from_user.id in config.OWNER:
  82. bot_code.send_gift(message)
  83.  
  84. elif message.text.lower().startswith(config.WORDS['mailing']) and message.from_user.id in config.OWNER:
  85. if message.photo:
  86. bot_code.mailing(message.chat.id,
  87. message.text,
  88. message.photo[-1].file_id
  89. )
  90.  
  91. elif message.video:
  92. bot_code.mailing(message.chat.id,
  93. message.text,
  94. message.video[-1].file_id
  95. )
  96.  
  97. elif message.document:
  98. bot_code.mailing(message.chat.id,
  99. message.text,
  100. message.document[-1].file_id
  101. )
  102.  
  103. else:
  104. bot.send_message(message.chat.id,
  105. config.WORDS['sorry'], reply_markup=config.standart_markup(), parse_mode='HTML'
  106. )
  107.  
  108.  
  109. if __name__ == '__main__':
  110. #bot_code.channel_timer()
  111. bot.polling()
  112. #bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment