-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
78 lines (60 loc) · 3.51 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import telebot
from flask import Flask, request
from data import get_stats, get_image_link, get_ways, get_positions
options = {'Statistics': 'Statistics by today', 'Ways': 'Ways by today', 'Positions': 'Positions by today',
'URL': 'Open site', 'Languages': 'Languages comparison'}
TOKEN = os.getenv('TOKEN')
bot = telebot.TeleBot(TOKEN)
server = Flask(__name__)
keyboard1 = telebot.types.ReplyKeyboardMarkup()
keyboard1.row(options['Statistics'], options['Languages'], options['URL'])
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBlF6psFYlbJCeQj7Ter-NBzwhfGLmAAIBAQACVp29CiK-nw64wuY0GQQ')
bot.send_message(message.chat.id, 'Please choose an option', reply_markup=keyboard1)
@bot.message_handler(content_types=['sticker'])
def get_sticker_id(sticker):
bot.send_message(sticker.chat.id, f'Sticker Id - {sticker.sticker.file_id}')
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text.lower() == options['Statistics'].lower():
bot.send_message(message.chat.id, 'Processing...')
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBk16psBCMPBU_NmudwEd_jzye7P52AAICAQACVp29Ck7ibIHLQOT_GQQ')
bot.send_message(message.chat.id, get_stats(), parse_mode="Markdown")
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBh16prxNbEgme1n_uECeShXDlUhekAAIFAQACVp29Crfk_bYORV93GQQ')
elif message.text.lower() == options['Ways'].lower():
bot.send_message(message.chat.id, 'Processing...')
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBk16psBCMPBU_NmudwEd_jzye7P52AAICAQACVp29Ck7ibIHLQOT_GQQ')
bot.send_message(message.chat.id, get_ways(), parse_mode="Markdown")
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBh16prxNbEgme1n_uECeShXDlUhekAAIFAQACVp29Crfk_bYORV93GQQ')
elif message.text.lower() == options['Positions'].lower():
bot.send_message(message.chat.id, 'Processing...')
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBk16psBCMPBU_NmudwEd_jzye7P52AAICAQACVp29Ck7ibIHLQOT_GQQ')
bot.send_message(message.chat.id, get_positions(), parse_mode="Markdown")
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBh16prxNbEgme1n_uECeShXDlUhekAAIFAQACVp29Crfk_bYORV93GQQ')
elif message.text.lower() == options['Languages'].lower():
bot.send_message(message.chat.id, 'Processing...')
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBk16psBCMPBU_NmudwEd_jzye7P52AAICAQACVp29Ck7ibIHLQOT_GQQ')
bot.send_photo(message.chat.id, get_image_link())
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBh16prxNbEgme1n_uECeShXDlUhekAAIFAQACVp29Crfk_bYORV93GQQ')
elif message.text.lower() == options['URL'].lower():
bot.send_message(message.chat.id, 'Site URL - https://qa-skills.herokuapp.com')
else:
bot.send_message(message.chat.id, 'Sorry, I did not understand this command')
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAIBkl6pr4kVOGisB5LUX54w8USsN6hWAAL5AANWnb0KlWVuqyorGzYZBA')
# Local
# bot.remove_webhook()
# bot.polling(none_stop=True)
# Heroku
@server.route('/' + TOKEN, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return '!', 200
@server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url="https://qa-skills-bot.herokuapp.com/" + TOKEN)
return "!", 200
if __name__ == '__main__':
server.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))