-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
137 lines (108 loc) · 5.81 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import telebot
from telebot.types import KeyboardButton, ReplyKeyboardMarkup
bot = telebot.TeleBot('6101444089:AAF17UIY8KKz5XPDGEzwZT9Vopsj7jtGNoo')
# Define a dictionary to keep track of user states
user_states = {}
@bot.message_handler(commands=['start'])
def start(message):
# Create a custom keyboard with a "Category" button and a "Student" button
keyboard = ReplyKeyboardMarkup(resize_keyboard=True)
travel_brochure_button = KeyboardButton("travel brochure")
district_button = KeyboardButton("district")
keyboard.row(travel_brochure_button, district_button)
# Add "Back" and "Main Menu" buttons
back_button = KeyboardButton("Back")
main_menu_button = KeyboardButton("Main Menu")
#keyboard.row(back_button, main_menu_button)
bot.send_message(message.chat.id, 'Welcome to my bot!', reply_markup=keyboard)
# Set the user's initial state to the main menu
user_states[message.chat.id] = "main_menu"
@bot.message_handler(func=lambda message: message.text == "Back")
def back_button_clicked(message):
chat_id = message.chat.id
if chat_id in user_states:
current_state = user_states[chat_id]
# Handle "Back" button based on the user's current state
if current_state == "category_selected":
# User was in the "travel brochure" section, go back to the main menu
start(message)
# Add more cases for other states as needed
# Update the user's current state
user_states[chat_id] = current_state
@bot.message_handler(func=lambda message: message.text == "Main Menu")
def main_menu_button_clicked(message):
# Handle the "Main Menu" button click by sending the main menu again
start(message)
@bot.message_handler(func=lambda message: message.text == "travel brochure")
def travel_brochure_button_selected(message):
# Create a nested keyboard when the user selects the "travel brochure" button
nested_keyboard = ReplyKeyboardMarkup(resize_keyboard=True)
two_day_button = KeyboardButton("two day")
three_day_button = KeyboardButton("three day")
# Add "Back" and "Main Menu" buttons to the nested keyboard
back_button = KeyboardButton("Back")
main_menu_button = KeyboardButton("Main Menu")
# Create two separate rows for buttons
nested_keyboard.row(two_day_button)
nested_keyboard.row(three_day_button)
nested_keyboard.row(back_button, main_menu_button)
# Respond with a message when the user selects the "travel brochure" button and include the nested keyboard
bot.send_message(message.chat.id, 'Hello! Welcome to the "travel brochure" section.', reply_markup=nested_keyboard)
# Update the user's current state to reflect the current menu
user_states[message.chat.id] = "category_selected"
@bot.message_handler(func=lambda message: message.text == "district")
def district_button_selected(message):
# Create a nested keyboard when the user selects the "district" button
nested_keyboard = ReplyKeyboardMarkup(resize_keyboard=True)
Kasaragod_button = KeyboardButton("Kasaragod")
Kannur_button = KeyboardButton("Kannur")
Wayanad_button = KeyboardButton("Wayanad")
Kozhikode_button = KeyboardButton("Kozhikode")
Malappuram_button = KeyboardButton(" Malappuram")
Palakkad_button = KeyboardButton("Palakkad")
Thrissur_button = KeyboardButton(" Thrissur")
Ernakulam_button = KeyboardButton("Ernakulam")
Idukki_button = KeyboardButton("Idukki")
Kottayam_button = KeyboardButton("Kottayam")
Alappuzha_button = KeyboardButton("Alappuzha")
Pathanamthitta_button = KeyboardButton("Pathanamthitta")
Kollam_button = KeyboardButton("kollom")
Thiruvananthapuram_button = KeyboardButton("Thiruvananthapuram")
# Add "Back" and "Main Menu" buttons to the nested keyboard
back_button = KeyboardButton("Back")
main_menu_button = KeyboardButton("Main Menu")
nested_keyboard.row(Kasaragod_button)
nested_keyboard.row(Kannur_button)
nested_keyboard.row(Wayanad_button)
nested_keyboard.row(Kozhikode_button)
nested_keyboard.row(Malappuram_button)
nested_keyboard.row(Palakkad_button)
nested_keyboard.row(Thrissur_button)
nested_keyboard.row(Ernakulam_button)
nested_keyboard.row(Idukki_button)
nested_keyboard.row(Kottayam_button)
nested_keyboard.row(Alappuzha_button)
nested_keyboard.row(Pathanamthitta_button)
nested_keyboard.row(Kollam_button)
nested_keyboard.row(Thiruvananthapuram_button)
nested_keyboard.row(back_button)
nested_keyboard.row(main_menu_button)
# Respond with a message when the user selects the "district" button and include the nested keyboard
bot.send_message(message.chat.id, 'Welcome to the "district" section.', reply_markup=nested_keyboard)
# Update the user's current state to reflect the current menu
user_states[message.chat.id] = "district_selected"
@bot.message_handler(func=lambda message: message.text == "Back")
def district_back_button_clicked(message):
chat_id = message.chat.id
if chat_id in user_states:
current_state = user_states[chat_id]
# Handle "Back" button based on the user's current state
if current_state == "district_selected":
# User was in the "district" section, go back to the main menu
start(message) # Call the start function to return to the main menu
# Add more cases for other states as needed
# Update the user's current state
user_states[chat_id] = current_state
#we will add the rest of the district code copy and pasted into here -
if __name__ == "__main__":
bot.polling()