Привет, у меня почему то не работает команда /play, хотя она задана и должна работать после ответа да
Вот код
Вот код
Python:
import sqlite3
import telebot
import texts
from configBot import TOKEN
from sqlite3 import Error
from time import ctime
token = TOKEN
bot = telebot.TeleBot(token)
# БД для данных пользователей
def post_sql_query(sql_query):
with sqlite3.connect('user.db') as connection:
cursor = connection.cursor()
try:
cursor.execute(sql_query)
except Error:
pass
result = cursor.fetchall()
return result
def create_tables():
users_query = '''CREATE TABLE IF NOT EXISTS USERS
(user_id INTEGER PRIMARY KEY NOT NULL,
nickname TEXT,
reg_date TEXT);'''
post_sql_query(users_query)
def register_user(user, nickname):
user_check_query = f'SELECT * FROM USERS WHERE user_id = {user};'
user_check_data = post_sql_query(user_check_query)
if not user_check_data:
insert_to_db_query = f'INSERT INTO USERS (user_id, nickname, reg_date) VALUES ({user}, "{nickname}", "{ctime()}");'
post_sql_query(insert_to_db_query)
# БД для никнеймов пользователей
def post_sql_query2(sql_query):
with sqlite3.connect('nickname.db') as connection:
cursor = connection.cursor()
try:
cursor.execute(sql_query)
except Error:
pass
result = cursor.fetchall()
return result
def create_table2():
nickname = '''CREATE TABLE IF NOT EXISTS NICKNAME
(nickname TEXT PRIMARY KEY);'''
post_sql_query2(nickname)
def nickname_user(nickname):
user_check_query = f'SELECT * FROM NICKNAME WHERE nickname = {nickname};'
user_check_data = post_sql_query2(user_check_query)
if not user_check_data:
insert_to_db_query = f'INSERT INTO NICKNAME (nickname) VALUES ("{nickname}");'
post_sql_query2(insert_to_db_query)
def delete_nickname(nickname):
delete = f'DELETE FROM NICKNAME WHERE nickname = {nickname};'
post_sql_query2(delete)
create_tables()
create_table2()
# Старт бота
@bot.message_handler(commands=['start'])
def start(message):
msg = bot.send_message(message.chat.id, texts.start)
bot.register_next_step_handler(msg, setName)
# Кнопки
@bot.message_handler(content_types=['text'])
def button(message):
t = telebot
# Кнопки для Village
markupv = t.types.ReplyKeyboardMarkup()
button_Main_Building = t.types.KeyboardButton('Главное здание')
button_shops = t.types.KeyboardButton('Лавки')
button_news = t.types.KeyboardButton('Новости')
button_gambling = t.types.KeyboardButton('Азартный игры')
button_back = t.types.KeyboardButton('Назад')
markupv.add(button_Main_Building, button_shops, button_news, button_gambling, button_back)
# Кнопки для backpack
markupb = t.types.InlineKeyboardMarkup()
markupb.add(t.types.InlineKeyboardButton(text='Ресурсы', callback_data='resources'))
markupb.add(t.types.InlineKeyboardButton(text='Алхимия', callback_data='Alchemy'))
markupb.add(t.types.InlineKeyboardButton(text='Металлы и драгоценности', callback_data='metalAndJewelry'))
markupb.add(t.types.InlineKeyboardButton(text='Платы', callback_data='payment'))
markupb.add(t.types.InlineKeyboardButton(text='Назад', callback_data='back'))
# Кнопки для home
markuph = t.types.ReplyKeyboardMarkup()
button_sleep = t.types.KeyboardButton('Лечь спать\n(Восстановить выносливость)')
button_chest = t.types.KeyboardButton('Сундук')
button_farms = t.types.KeyboardButton('Фермы')
button_corrals = t.types.KeyboardButton('Загоны')
markuph.add(button_sleep, button_farms, button_chest, button_corrals, button_back)
# Установка псевдонима
@bot.message_handler(commands=['set_my_name'])
def setName(message):
msg = bot.send_message(message.chat.id, texts.SetName)
bot.register_next_step_handler(msg, setName2)
# Установка псевдонима 2
def setName2(message):
msg = message.text
markup = telebot.types.InlineKeyboardMarkup()
markup.add(telebot.types.InlineKeyboardButton(text='Да', callback_data='yesName'))
markup.add(telebot.types.InlineKeyboardButton(text='Нет', callback_data='noName'))
bot.send_message(message.chat.id, text=f"Вы уверены на это имя-{msg}?", reply_markup=markup)
# Старт игры!
@bot.message_handler(commands=['play'])
def startGaming(message):
bot.send_message(message.chat.id, texts.playGaming)
t = telebot
markupv = t.types.ReplyKeyboardMarkup()
button_Main_Building = t.types.KeyboardButton('Главное здание')
button_shops = t.types.KeyboardButton('Лавки')
button_news = t.types.KeyboardButton('Новости')
button_gambling = t.types.KeyboardButton('Азартный игры')
button_back = t.types.KeyboardButton('Назад')
markupv.add(button_Main_Building, button_shops, button_news, button_gambling, button_back)
bot.send_message(message.chat.id, texts.PersonBeginning, reply_markup=markupv)
# Обработчик инлайн-кнопок
@bot.callback_query_handler(func=lambda call: True)
def query_handler(call):
if call.message:
if call.data == 'yes_N':
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=texts.yes_N)
elif call.data == 'no_N':
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=texts.no_N)
elif call.data == 'yesName':
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=texts.yesName)
elif call.data == 'noName':
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=texts.noName)
if __name__ == '__main__':
bot.polling(none_stop=True)