-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZelBot.py
71 lines (61 loc) · 2.71 KB
/
ZelBot.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
# -*- coding: utf-8 -*-
import config
import telebot
import func
import qwests
bot = telebot.TeleBot(config.token)
db = func.open_file('db.csv')
# Старт квеста
@bot.message_handler(commands = ['start'])
def handle_start(message):
user_markup = telebot.types.ReplyKeyboardMarkup(True)
user_markup.row('/start', '/qwest', '/loc')
user_markup.row('/help', '/again')
Uid = message.chat.id
ent = func.ent_user(Uid, db)
func.save_file(db)
if ent == False:
bot.send_message(message.chat.id, qwests.welcome1, reply_markup=user_markup)
else:
bot.send_message(message.chat.id, qwests.welcome2, reply_markup=user_markup)
# Запрос текущего квеста
@bot.message_handler(commands = ['qwest'])
def current_qwest(message):
user_markup = telebot.types.ReplyKeyboardMarkup(True)
user_markup.row('/start', '/qwest', '/loc')
user_markup.row('/help', '/again')
Uid = message.chat.id
CQ = func.my_qwest(Uid, db)
if CQ == 1:
bot.send_message(message.chat.id, qwests.qwest1, reply_markup=user_markup)
if CQ == 2:
bot.send_message(message.chat.id, qwests.qwest2, reply_markup=user_markup)
if CQ == 3:
bot.send_message(message.chat.id, qwests.qwest3, reply_markup=user_markup)
# Отправка геолокации
@bot.message_handler(commands = ['loc'])
def geoloc(message):
keyboard = telebot.types.ReplyKeyboardMarkup(one_time_keyboard=True)
button_geo = telebot.types.KeyboardButton(text="Отправить местоположение", request_location=True)
keyboard.add(button_geo)
bot.send_message(message.chat.id, "Отправь мне свое местоположение!", reply_markup=keyboard)
# Обработка местоположения
@bot.message_handler(content_types = ['location'])
def get_geoloc(message):
user_markup = telebot.types.ReplyKeyboardMarkup(True)
user_markup.row('/start', '/qwest', '/loc')
user_markup.row('/help', '/again')
loc = message.location
print(loc)
Uid = message.chat.id
my_loc = func.norm_loc(loc)
CQ = func.my_qwest(Uid, db)
rez = func.in_right_place(Uid, db, my_loc, CQ)
if rez == True:
func.next_qwest(Uid, db)
bot.send_message(message.chat.id, 'Поздравляем! Чтобы посмотреть следующий квест, нажмите /qwest', reply_markup=user_markup)
else:
bot.send_message(message.chat.id, 'Вы не угадали, подумайте еще! Чтобы заново посмотреть задание, нажмите /qwest', reply_markup=user_markup)
user_markup = telebot.types.ReplyKeyboardMarkup(True)
if __name__ == '__main__':
bot.polling(none_stop=True)