Exemplo n.º 1
0
async def bot_start(message: types.Message):
    await message.answer(
        'Для того чтобы узнать перевод слова/фразы выберите "Словарь"',
        reply_markup=start_but)
    db = Database()
    if db.check_user(id=message.chat.id) is None:
        db.add_user(id=message.chat.id, name=message.from_user.full_name)
    await State_start.start.set()
Exemplo n.º 2
0
async def bot_state_delete(message: types.Message):
    db = Database()
    if db.check_word(id=message.chat.id, word=message.text) is None:
        await message.answer('Такого слова нет в словарях 😢\n'
                             'Попробуйте другое слово', reply_markup=back_dict_but)
    else:
        await message.answer('Отлично! \n'
                     'Слово "' + message.text + '" удалено из словаря')
        db.delete_word(id=message.chat.id, word=message.text)
Exemplo n.º 3
0
async def bot_state_delete(call: types.CallbackQuery):
    db = Database()
    if call.data == "en":
        data = "Английский"
    else:
        data = "Русский"
    db.delete_all_words(call.from_user.id, call.data)
    await call.message.edit_text(data + " словарь удален",
                                 reply_markup=dict_but)
    await State_dict.dict_main.set()
Exemplo n.º 4
0
def translate_word(id_user, word):
    # translator = Translator()
    result = check_word(word)
    if not result:
        return 0

    if len(result.split()) > 3:
        return 1

    if has_latin(result):
        result = translator.translate(result, src="en", dest="ru")
    elif has_cyrillic(result):
        result = translator.translate(result, src="ru", dest="en")
    else:
        return 2

    if (result.extra_data['all-translations'] is None):
        return 2
    str = []
    str2 = [result.text.lower()]
    for lst in result.extra_data['all-translations']:
        str.append("\n" + translator.translate(lst[0], dest='ru').text + ":")
        for wrd in lst[1][:2]:
            if not wrd == result.text.lower():
                str2.append(wrd)
        str.append(', '.join(str2))
        str2 = []

    db = Database()
    if db.check_word(id=id_user, word=word) is None:
        db.add_word(id=id_user, word=word, lang=result.src)
    else:
        db.zero_value_word(id=id_user, word=word)
    return ' '.join(str)
Exemplo n.º 5
0
from utils.db_api.sqlite import Database

db = Database()


def test():
    db.create_table_users()
    users = db.select_all_users()
    print(f"До добавления пользователей: {users}")
    db.add_user(1, "One")
    db.add_user(2, "Two")
    db.add_user(3, "Tree")
    users = db.select_all_users()
    print(f"После добавления пользователей: {users}")
    user = db.select_user(Name="Tree", id=3)
    print(f"Получил пользователя {user}")


test()
Exemplo n.º 6
0
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage

from utils.db_api.sqlite import Database
from data import config

bot = Bot(token=config.BOT_TOKEN, parse_mode=types.ParseMode.HTML)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
db = Database(path_to_db="data/main.db")
Exemplo n.º 7
0
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiograph import Telegraph

from data import config
from utils.db_api.sqlite import Database

bot = Bot(token=config.BOT_TOKEN, parse_mode=types.ParseMode.HTML)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
telegraph = Telegraph()
usersdb = Database(path_to_db="data/users.db")
Exemplo n.º 8
0
def test():
    db = Database()
    db.create_table_users()
    db.add_user(10, "One", "email")
    db.add_user(20, "Vasya", "*****@*****.**")
    db.add_user(30, 1, 1)
    db.add_user(50, 1, 1)
    db.add_user(60, "John", "*****@*****.**")

    users = db.select_all_users()
    print(f"Получил всех пользователей: {users}")

    user = db.select_user(Name="John", id=5)
    print(f"Получил пользователя: {user}")

    users = db.select_all_users()
    print(f"Получил всех пользователей: {users}")