Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ADMIN_ID=776149633
BOT_TOKEN=1491703059:AAEIkkEyx9bB2WxmGdYA2bcXf7eu7h1h_cA
ip=localhost
3 changes: 0 additions & 3 deletions .env.dist

This file was deleted.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
------------------------------

Телеграм бот

Помощ пользователям в получении кредита
13 changes: 12 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@

from loader import db
#from utils.set_bot_commands import set_default_commands

async def on_startup(dp):
import filters
import middlewares
filters.setup(dp)
middlewares.setup(dp)

from utils.notify_admins import on_startup_notify
await on_startup_notify(dp)
try:
db.create_table_users()
except Exception as e:
print(e)
db.delete_users()


await on_startup_notify(dp)
#await set_default_commands(dp)

if __name__ == '__main__':
from aiogram import executor
from handlers import dp
Expand Down
Binary file added data/main.db
Binary file not shown.
1 change: 1 addition & 0 deletions handlers/users/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .help import dp
from .start import dp
from .body import dp
from .echo import dp

__all__ = ["dp"]
174 changes: 174 additions & 0 deletions handlers/users/body.py

Large diffs are not rendered by default.

70 changes: 68 additions & 2 deletions handlers/users/start.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,75 @@
from aiogram import types
from aiogram.types import ContentType, Message

from photos import *
from aiogram.types import InputFile
from keyboards.default.text_button import start_button, menu

from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters import Command, Text
from aiogram.dispatcher.filters.builtin import CommandStart

from loader import dp
from loader import dp, db, bot
import sqlite3



@dp.message_handler(CommandStart())
async def bot_start(message: types.Message):
await message.answer(f'Привет, {message.from_user.full_name}!')
name = message.from_user.full_name
try:
db.add_user(id=message.from_user.id, name=name)
except sqlite3.IntegrityError as err:
print(err)

photo = InputFile(path_or_bytesio="photos/photo1.jpg")
await bot.send_photo(chat_id=message.from_user.id,
photo=photo,
caption=(f'Привет, {message.from_user.full_name}!\n\n'
f'Я твой финансовый бот-помошник 😊\n'
f'Я могу помочь тебе получить деньги на самых выгодных условиях под 0%!\n'
f'Для этого мне нужно задать пару вопросов.\n\n'
f'Жми на кнопку «Запустить»👇'), reply_markup=start_button)


@dp.message_handler(Command("data"))
async def database(message: types.Message):
count_users = db.count_users()[0]
await message.answer(
"\n".join([
f'Привет, {message.from_user.full_name}!',
'Ти есть в базе',
f'В базе <b>{count_users}</b> Пользователей',
])
)


@dp.message_handler(text="Запустить 🚀")
async def user_old(message: types.Message, state:FSMContext):
await message.answer(f"Сколько вам лет ?\n"
f"Напиши свой возраст...")
await state.set_state("years")


@dp.message_handler(state="years")
async def enter_old(message: types.Message, state: FSMContext):
years = message.text
db.update_user_age(age=years, id=message.from_user.id)

photo = InputFile(path_or_bytesio='photos/photo2.jpg')
await bot.send_photo(chat_id=message.from_user.id,
photo=photo,
caption=(f'Благодарю тебя, {message.from_user.full_name}!\n'
f'Чтобы подобрать банк, который готов дать тебе деньги\n'
f'на самых лучших условиях\n'
f'воспользуйся кнопкой "🏪Подобрать банк"'
f'Тестови данние '), reply_markup=menu)

await state.finish()

@dp.message_handler(text="📝Мои настройки")
async def My_setting(message: Message):
user = db.select_user(id=message.from_user.id)
await message.answer(f"Страна: Україна\n"
f"Возраст: {user}")

Empty file added handlers/users/update_db.py
Empty file.
27 changes: 27 additions & 0 deletions keyboards/default/text_button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton

start_button = ReplyKeyboardMarkup(
keyboard=[
[
KeyboardButton(text="Запустить 🚀")
],
],
resize_keyboard=True, one_time_keyboard=True
)


menu = ReplyKeyboardMarkup(
keyboard=[
[
KeyboardButton(text="🏪Подобрать банк"),
KeyboardButton(text="👑Популяриные предложения")
],
[
KeyboardButton(text="📝Мои настройки")
],
[
KeyboardButton(text="🛸Поделиться с другом")
]
],
resize_keyboard=True
)
112 changes: 112 additions & 0 deletions keyboards/inline/callback_buttom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from aiogram.utils.callback_data import CallbackData

#Поделится с другом
send_bot = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Поделиться ботом👍🏼", switch_inline_query=f"\n"
f"https://t.me/money_zaim_bot\n"
f"Смотри какой крутой бот 😊")
]
])

show_search = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="🔍Показать результат поиска ", callback_data="show_credit")
]
])

popular_menu = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Под 0%", callback_data="crediplus")
],
[
InlineKeyboardButton(text="С плохой кредитной историей", callback_data="gotivochka3")
],
[
InlineKeyboardButton(text="Лучшие займы", callback_data="next_variant")
],
[
InlineKeyboardButton(text="Все варианты", callback_data="give_next")
]
])


#______________________менюшка для кредитив____________---

first_klick = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Получить деньги", url="https://rozetka.com.ua/")
],
[
InlineKeyboardButton(text="Еще варианты", callback_data="give_next")
],

])

second_menu = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Получить деньги", url="https://rozetka.com.ua/")
],
[
InlineKeyboardButton(text="Назад", callback_data="show_credit"),
InlineKeyboardButton(text="Еще варианты", callback_data="next_variant")
],

])

there_menu = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Получить деньги", url="https://rozetka.com.ua/")
],
[
InlineKeyboardButton(text="Назад", callback_data="give_next"),
InlineKeyboardButton(text="Еще варианты", callback_data="gotivochka3")
],

])

foo_menu = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Получить деньги", url="https://rozetka.com.ua/")
],
[
InlineKeyboardButton(text="Назад", callback_data="next_variant"),
InlineKeyboardButton(text="Еще варианты", callback_data="crediplus")
],

])

five_menu = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Получить деньги", url="https://rozetka.com.ua/")
],
[
InlineKeyboardButton(text="Назад", callback_data="gotivochka3"),
InlineKeyboardButton(text="Еще варианты", callback_data="evrogroshi")
],

])

six_menu = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Получить деньги", url="https://rozetka.com.ua/")
],
[
InlineKeyboardButton(text="Назад", callback_data="crediplus"),
InlineKeyboardButton(text="Еще варианты", callback_data="zeccredit")
],

])

seven_menu = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="Получить деньги", url="https://rozetka.com.ua/")
],
[
InlineKeyboardButton(text="Назад", callback_data="crediplus"),
InlineKeyboardButton(text="Еще варианты", callback_data="done")
],

])

3 changes: 3 additions & 0 deletions loader.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage


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)
db = Database(path_to_db="data/main.db")
Binary file added photos/credit_image/Miloan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/credit_image/bistro_dengi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/credit_image/credit1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/credit_image/credit2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/credit_image/evrogroshi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/credit_image/zecreditor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/loading1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/loading2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/photo1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added photos/photo2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions utils/db_api/sqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import sqlite3


class Database:
def __init__(self, path_to_db="main.db"):
self.path_to_db = path_to_db

@property
def connection(self):
return sqlite3.connect(self.path_to_db)

def execute(self, sql: str, parameters: tuple = None, fetchone=False, fetchall=False, commit=False):
if not parameters:
parameters = ()
connection = self.connection
connection.set_trace_callback(logger)
cursor = connection.cursor()
data = None
cursor.execute(sql, parameters)

if commit:
connection.commit()
if fetchall:
data = cursor.fetchall()
if fetchone:
data = cursor.fetchone()
connection.close()
return data

def create_table_users(self):
sql = """
CREATE TABLE Users (
id int NOT NULL,
Name varchar(255) NOT NULL,
email varchar(255),
age varchar(50),
PRIMARY KEY (id)
);
"""
self.execute(sql, commit=True)

@staticmethod
def format_args(sql, parameters: dict):
sql += " AND ".join([
f"{item} = ?" for item in parameters
])
return sql, tuple(parameters.values())

def add_user(self, id: int, name: str, email: str = None, age: str = None):
# SQL_EXAMPLE = "INSERT INTO Users(id, Name, email) VALUES(1, 'John', 'John@gmail.com')"

sql = """
INSERT INTO Users(id, Name, email, age) VALUES(?, ?, ?, ?)
"""
self.execute(sql, parameters=(id, name, email, age), commit=True)

def select_all_users(self):
sql = """
SELECT * FROM Users
"""
return self.execute(sql, fetchall=True)

def select_user(self, **kwargs):
# SQL_EXAMPLE = "SELECT * FROM Users where id=1 AND Name='John'"
sql = "SELECT * FROM Users WHERE "
sql, parameters = self.format_args(sql, kwargs)

return self.execute(sql, parameters=parameters, fetchone=True)


def count_users(self):
return self.execute("SELECT COUNT(*) FROM Users;", fetchone=True)

def update_user_email(self, email, id):
# SQL_EXAMPLE = "UPDATE Users SET email=mail@gmail.com WHERE id=12345"

sql = f"""
UPDATE Users SET email=? WHERE id=?
"""
return self.execute(sql, parameters=(email, id), commit=True)

def update_user_age(self, age, id):
sql = f"""
UPDATE Users SET age=? WHERE id=?
"""
return self.execute(sql, parameters=(age, id), commit=True)


def delete_users(self):
self.execute("DELETE FROM Users WHERE TRUE", commit=True)


def logger(statement):
print(f"""
_____________________________________________________
Executing:
{statement}
_____________________________________________________
""")
6 changes: 6 additions & 0 deletions utils/db_api/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from utils.db_api.sqlite import Database

db = Database()

def test():