Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'Database' from 'db' #301

Open
ArtyomMedved opened this issue Oct 18, 2023 · 0 comments
Open

ImportError: cannot import name 'Database' from 'db' #301

ArtyomMedved opened this issue Oct 18, 2023 · 0 comments

Comments

@ArtyomMedved
Copy link

I don’t know what I did wrong but it gives an error, I’m using a MacBook version of Sonoma, I hope for your help)

import config
import logging

from aiogram import Bot, Dispatcher, executor, types
from aiogram.types.message import ContentType

import markups as nav
from db import Database

# log
logging.basicConfig(level=logging.INFO)

# init
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)

db = Database('database.db')

#start
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
    if(not db.user_exists(message.from_user.id)):
        db.add_user(message.from_user.id)
        await bot.send_message(message.from_user.id, "Укажите ваш ник:")
    else:
        await bot.send_message(message.from_user.id, "Вы уже зарегестрированы!", reply_markup=nav.mainMenu)

@dp.message_handler()
async def bot_message(message: types.Message):
    if message.chat.type == 'private':
        if message.text == 'Профиль':
            pass

        else:
            if db.get_singup(message.from_user.id) == "setnickname":
                if(len(message.text) > 15):
                    await bot.send_message(message.from_user.id, "Никнейм не должен превышать 15 символов")
                elif '@' in message.text or '/' in message.text:
                    await bot.send_message(message.from_user.id, "Никнейм не должен содержать @ или /")
                else:
                    db.set_nickname(message.from_user.id, message.text)
                    db.set_singup(message.from_user.id, "done")
                    await bot.send_message(message.from_user.id, "Регистрация успешна!", reply_markup=nav.mainMenu)
            else:
                await bot.send_message(message.from_user.id, "что?")


# prices
PRICE = types.LabeledPrice(label="Подписка на 1 месяц", amount=500*100)  # в копейках (руб)


# buy
@dp.message_handler(commands=['buy'])
async def buy(message: types.Message):
    if config.PAYMENTS_TOKEN.split(':')[1] == 'TEST':
        await bot.send_message(message.chat.id, "Тестовый платеж!!!")

    await bot.send_invoice(message.chat.id,
                           title="Подписка на бота",
                           description="Активация подписки на бота на 1 месяц",
                           provider_token=config.PAYMENTS_TOKEN,
                           currency="rub",
                           photo_url="https://www.aroged.com/wp-content/uploads/2022/12/Telegram-Premium-has-collected-a-million-subscribers-in-five-months.png",
                           photo_width=416,
                           photo_height=234,
                           photo_size=416,
                           is_flexible=False,
                           prices=[PRICE],
                           start_parameter="one-month-subscription",
                           payload="test-invoice-payload")

# pre checkout  (must be answered in 10 seconds)
@dp.pre_checkout_query_handler(lambda query: True)
async def pre_checkout_query(pre_checkout_q: types.PreCheckoutQuery):
    await bot.answer_pre_checkout_query(pre_checkout_q.id, ok=True)


# successful payment
@dp.message_handler(content_types=ContentType.SUCCESSFUL_PAYMENT)
async def successful_payment(message: types.Message):
    print("SUCCESSFUL PAYMENT:")
    payment_info = message.successful_payment.to_python()
    for k, v in payment_info.items():
        print(f"{k} = {v}")

    await bot.send_message(message.chat.id,
                           f"Платеж на сумму {message.successful_payment.total_amount // 100} {message.successful_payment.currency} прошел успешно!!!"
                           f"Скачать скрипт:.....(ссылка одноразовая, не пытайтесь ее кому то отпрвить)")


# run long-polling
if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant