added functionality for sending 4k pics and topic pics

This commit is contained in:
2022-05-08 00:52:28 +03:00
parent 3ca0f2c82f
commit 7d516104b5
2 changed files with 39 additions and 5 deletions
View File
+39 -5
View File
@@ -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)