-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
94 lines (69 loc) · 2.83 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import telebot
import os
from src.wh_img import custom_title, random_title, title_from_keyword, print_tutorial
from telebot import types
from dotenv import load_dotenv
if os.path.isfile("src/.env"):
load_dotenv("src/.env")
TOKEN = os.getenv("API_TOKEN")
else:
TOKEN = os.getenv("API_TOKEN")
bot = telebot.TeleBot(TOKEN)
markup = types.ReplyKeyboardMarkup()
markup.row_width = 1
keyword_mkup = types.KeyboardButton("Keyword")
custom_title_mkup = types.KeyboardButton("Custom title")
random_title_mkup = types.KeyboardButton("Random title")
restart_mkup = types.KeyboardButton("/start")
help_mkup = types.KeyboardButton("Help")
markup.add(keyword_mkup, custom_title_mkup, random_title_mkup, restart_mkup, help_mkup)
@bot.message_handler(commands=["start", "help"])
def send_welcome(message):
bot.reply_to(
message,
"Hi! I can make random tutorials. How? Tap on the buttons below to:\n\n1) Give me a keyword and let me choose the title of the tutorial\n2) Send me the title of the tutorial\n3) Let me pick a random title.",
reply_markup=markup,
)
@bot.message_handler(func=lambda message: True, content_types=["text"])
def get_choice(message):
if message.text == "Help":
send_welcome(message)
return
if message.text == "Keyword" or "Custom title" or "Random title":
choice = message.text
if choice == "Custom title":
message = bot.send_message(message.chat.id, "Type your title:")
bot.register_next_step_handler(message, get_user_title)
if choice == "Keyword":
message = bot.send_message(message.chat.id, "Type your keyword:")
bot.register_next_step_handler(message, get_user_keyword)
if choice == "Random title":
bot.send_chat_action(message.chat.id, "upload_photo")
image = print_tutorial(random_title())
bot.send_photo(message.chat.id, image)
return
else:
bot.send_message(message.chat.id, "Bro you have to tap on the buttons below!")
def get_user_title(message):
input = message.text
custom_title_ok = custom_title(input)
bot.reply_to(message, "Gotcha! I'm working on it")
image = print_tutorial(custom_title_ok)
bot.send_chat_action(message.chat.id, "upload_photo")
bot.send_photo(message.chat.id, image)
return
def get_user_keyword(message):
input = message.text
title_tutorial = title_from_keyword(input)
bot.reply_to(message, "Gotcha! I'm working on it")
if title_tutorial == -1:
bot.send_message(message.chat.id, "No matching keyword, please retry!")
else:
image = print_tutorial(title_tutorial)
bot.send_chat_action(message.chat.id, "upload_photo")
bot.send_photo(message.chat.id, image)
return
def main():
bot.infinity_polling()
if __name__ == "__main__":
main()