diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/bot.py b/src/bot.py index 39ac982..bb19c9b 100644 --- a/src/bot.py +++ b/src/bot.py @@ -5,6 +5,13 @@ import telebot bot = telebot.TeleBot(environ["TELEGRAM_TOKEN"]) +# configure the webhook for the bot +bot.set_webhook( + "https://{}.herokuapp.com/{}".format( + environ["PROJECT_NAME"], environ["TELEGRAM_TOKEN"] + ) +) + @bot.message_handler(commands=["start"]) def send_welcome(message): @@ -14,9 +21,36 @@ def send_welcome(message): bot.reply_to(message, "hi there") -# configure the webhook for the bot -bot.set_webhook( - "https://{}.herokuapp.com/{}".format( - environ["PROJECT_NAME"], environ["TELEGRAM_TOKEN"] +@bot.message_handler(commands=["random"]) +def send_random_pic(message): + """ + send a random picture + """ + response = requests.get("https://source.unsplash.com/random") + bot.send_photo(message.chat.id, response.content) + + +@bot.message_handler(commands=["4k"]) +def send_random_4k_pic(message): + """ + send random 4k unsplash picture + """ + response = requests.get("https://source.unsplash.com/random/4096x2160") + bot.send_photo(message.chat.id, response.content) + bot.send_document(message.chat.id, response.content, caption="rename_to_jpeg") + + +@bot.message_handler(commands=["topic"]) +def handle_text(message): + chat_id = message.chat.id + message_topics = bot.send_message( + chat_id, "Type the topic(s) separated with commas" ) -) + bot.register_next_step_handler(message_topics, step_set_topics) + + +def step_set_topics(message): + chat_id = message.chat.id + topics = message.text + response = requests.get("https://source.unsplash.com/random?{0}".format(topics)) + bot.send_photo(message.chat.id, response.content)