-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (25 loc) · 1.04 KB
/
main.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
from telegram import ReplyKeyboardMarkup
from telegram.ext import Updater, CommandHandler
from dotenv import load_dotenv
import os
import requests
load_dotenv()
bot_token = os.getenv('BOT_TOKEN')
updater = Updater(token=bot_token, use_context=True)
dispatcher = updater.dispatcher
reply_keyboard = [['/random']]
markup = ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True)
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id,
text="Type /random to get a new quote everytime!", reply_markup=markup)
def get_random_quote(update, context):
resp = requests.get('http://quotes.stormconsultancy.co.uk/random.json')
data = resp.json()
context.bot.send_message(
chat_id=update.effective_chat.id, text=data['quote'])
if __name__ == '__main__':
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
quote_handler = CommandHandler('random', get_random_quote)
dispatcher.add_handler(quote_handler)
updater.start_polling()