import bases, ru, uk
bot = Bot(token=obamka)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
await message.delete()
connect = sqlite3.connect(r'C:\obamabot\base.db')
db = connect.cursor()
db.execute("SELECT language FROM users WHERE id = ?;", (message.from_user.id,))
data = db.fetchone()
if data is not None:
lang = data[0]
if lang == 'ru':
await bases.login(message)
await ru.setup(dp)
connect.commit()
connect.close()
elif lang == 'uk':
pass
else:
pass
else:
print(data)
if __name__ == '__main__':
from aiogram import executor
executor.start_polling(dp, skip_updates=True)
bot = Bot(token=obamka)
storage = MemoryStorage()
async def setup(dp):
@dp.message_handler()
async def ru_bot(message: types.Message):
stkb = await inlines.start_kb_ru()
hi_stick = await message.answer_sticker(sticker='CAACAgIAAxkBAAIB5mWULDDVy6iRndrHiSOZaKo3L9eNAALmPQACddihSAQdg_51tWFuNAQ')
hi_mess = await message.answer(f'Приветствую, {message.from_user.first_name}\n\
Ты оказался в <b>Russian Box Bot</b>.\nПодробную информацию о боте, можешь узнать по кнопкам ниже',
reply_markup=stkb,
parse_mode='HTML')
return stkb
@dp.callback_query_handler()
async def handle_callback_ru(callback_query: types.CallbackQuery):
if callback_query.data == 'info':
stkb = await inlines.info_kb_ru()
info_mes = await information.info_bot()
await bot.edit_message_text(
chat_id=callback_query.message.chat.id,
message_id=callback_query.message.message_id,
text=info_mes,
parse_mode='HTML')
await bot.edit_message_reply_markup(
chat_id=callback_query.message.chat.id,
message_id=callback_query.message.message_id,
reply_markup=stkb)
async def login(message: types.Message):
connect = sqlite3.connect(r'C:\obamabot\base.db')
db = connect.cursor()
db.execute("""CREATE TABLE IF NOT EXISTS users(id INTEGER, name TEXT, language TEXT)""").fetchall()
connect.commit()
people_id = message.from_user.id
name = message.from_user.first_name
lang = 'ru'
db.execute("SELECT * FROM users WHERE id = ?;", (people_id,))
data = db.fetchone()
if data is None:
db.execute("INSERT INTO users(id, name) VALUES(?, ?);", (people_id, name))
db.execute(f"UPDATE users SET id = ? WHERE id = ?", (people_id, message.from_user.id))
db.execute(f"UPDATE users SET name = ? WHERE id = ?;", (name, message.from_user.id))
db.execute(f"UPDATE users SET language = ? WHERE id = ?;", (lang, message.from_user.id))
connect.commit()
connect.close()
return
else:
db.execute(f"UPDATE users SET id = ? WHERE id = ?", (people_id, message.from_user.id))
db.execute(f"UPDATE users SET name = ? WHERE id = ?;", (name, message.from_user.id))
db.execute(f"UPDATE users SET language = ? WHERE id = ?;", (lang, message.from_user.id))
connect.commit()
connect.close()
have_login = await message.answer(f'{message.from_user.first_name}, ты уже зарегистрирован в боте! Поиск информации в базе данных...')
await asyncio.sleep(3)
await have_login.delete()
return