mirror of
https://github.com/andwati/unsplash-bot.git
synced 2026-10-28 15:22:16 +00:00
added functionality for sending 4k pics and topic pics
This commit is contained in:
+39
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user