Created
June 15, 2021 16:00
-
-
Save vsecoder-old-account/1090eec79347b187b2ffabf0b4ddc7dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# AIOGRAM | |
import aiogram.utils.markdown as md | |
from aiogram import Bot, Dispatcher, types, filters | |
from aiogram.contrib.fsm_storage.memory import MemoryStorage | |
from aiogram.dispatcher import FSMContext | |
from aiogram.dispatcher.filters import Text | |
from aiogram.dispatcher.filters.state import State, StatesGroup | |
from aiogram.types import ParseMode, reply_keyboard | |
from aiogram.utils import executor | |
import aiogram.utils | |
from aiogram.types import ReplyKeyboardRemove, \ | |
ReplyKeyboardMarkup, KeyboardButton, \ | |
InlineKeyboardMarkup, InlineKeyboardButton | |
from aiogram.utils.executor import start_webhook | |
from aiogram.contrib.middlewares.logging import LoggingMiddleware | |
# DB models | |
from models import db_session | |
from models.users import User | |
# ... | |
import json | |
db_session.global_init('database.db') | |
bot_token = '1709408761:AAHmGR7CvKGhHiD4TOUSBBI08aHMxDlj9HY' # @referalsys_bot | |
bot = Bot(token=bot_token) | |
# For example use simple MemoryStorage for Dispatcher. | |
storage = MemoryStorage() | |
dp = Dispatcher(bot, storage=storage) | |
# считаем для статистики | |
users = 12 # юзеры | |
newrefs = 5 # новых реферералов | |
money_lose = 36.7 # денег выведено | |
admin_id = 1218845111 # id админа | |
# json основа | |
dict_json = { | |
'1': '', | |
'2': '', | |
'3': '', | |
'4': '', | |
'5': '', | |
'6': '' | |
} | |
# кол-во денег за новых юзеров разных кругов | |
circle_1 = 100 | |
circle_2 = 50 | |
circle_3 = 25 | |
circle_4 = 10 | |
circle_5 = 5 | |
# функция | |
def extract_unique_code(text): | |
return text.split()[1] if len(text.split()) > 1 else None | |
#Класс для теста | |
class Test(StatesGroup): | |
youare18 = State() # Вам есть 18? | |
english = State() # Понимание английского | |
documents = State() # Подтверждаеющие документы | |
country = State() # Страна проживания | |
ready = State() # Готовность пройти аутентификацию | |
user_data = State() # О себе(анкета) | |
wait = State() # Ожидание | |
# /start | |
@dp.message_handler(commands=['start']) | |
async def send_welcome(message: types.Message): | |
global users | |
# | |
iduser = message.from_user.id | |
session = db_session.create_session() | |
# | |
user_all = session.query(User).all() | |
T = True | |
for all in user_all: | |
if all.id == iduser: | |
T = False | |
if T == True: | |
# добавить нового юзера | |
session = db_session.create_session() | |
name = message.from_user.first_name | |
url = message.from_user.username | |
iduser = message.from_user.id | |
user = User( | |
id=iduser, | |
name=name, | |
ref='', | |
refs='', | |
test='', | |
money=0 | |
) | |
users += 1 | |
session.add(user) | |
session.commit() | |
unique_code = extract_unique_code(message.text) | |
if unique_code != None: | |
ref = unique_code | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if str(user.id) == str(unique_code) or user.id == unique_code: | |
if user.refs: | |
user.refs += ', ' + str(message.from_user.id) | |
else: | |
user.refs += str(message.from_user.id) | |
await bot.send_message(user.id, f'👤 У вас новый реферал!\n<a href="tg://user?id={message.from_user.id}">ID{message.from_user.id}</a>', parse_mode='HTML') | |
user.money += circle_1 | |
if str(user.id) == str(message.from_user.id): | |
user.ref = unique_code | |
session.commit() | |
# Клавиатура | |
yes_bt = KeyboardButton('Да') | |
no_bt = KeyboardButton('Нет') | |
main_kb = ReplyKeyboardMarkup(resize_keyboard=True) | |
main_kb.add(yes_bt) | |
main_kb.add(no_bt) | |
await message.reply('Приветствую! Пожалуйста, заполните анкету для продолжения') | |
await message.reply('Вам есть 18+?', reply_markup=main_kb) | |
await Test.youare18.set() | |
else: | |
# юзер есть | |
test = '' | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
test = user.test | |
session.commit() | |
if test: | |
keyboard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True) | |
profile = types.KeyboardButton(text='👤 Профиль') | |
stop = types.KeyboardButton(text='📑 Вывести') | |
info = types.KeyboardButton(text='ℹ️ Инфа') | |
stats = types.KeyboardButton(text='📈 Статистика') | |
donat = types.KeyboardButton(text='🎟 Валюта') | |
piar = types.KeyboardButton(text='💸 Задания') | |
faq = types.KeyboardButton(text='🧮 FAQ') | |
buttons_to_add = [profile, stop, info, stats, donat, piar, faq] | |
keyboard.add(*buttons_to_add) | |
await bot.send_message(message.chat.id, '🙋Здравствуйте!', reply_markup=keyboard) | |
else: | |
await bot.send_message(message.chat.id, 'Ваша заявка ещё на рассмотрении!') | |
# /verify | |
@dp.message_handler(commands=['verify']) | |
async def verify(message: types.Message): | |
try: | |
text = message.text.replace('/verify ', '') | |
test = '' | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if str(user.id) == text: | |
user.test = 'verify' | |
test = 'verify' | |
session.commit() | |
if test: | |
await bot.send_message(message.chat.id, '👍 Success verify') | |
else: | |
await bot.send_message(message.chat.id, '👎 Verify failed\n\nID is not defined') | |
except Exception as e: | |
await bot.send_message(message.chat.id, f'👎 Verify failed\n\n{e}') | |
# Тебе есть 18? | |
@dp.message_handler(state=Test.youare18) | |
async def yr18(message): | |
yes_bt = KeyboardButton('Знаю хорошо') | |
no_bt = KeyboardButton('Не знаю') | |
understand = KeyboardButton('Понимаю') | |
main_kb = ReplyKeyboardMarkup(resize_keyboard=True) | |
main_kb.add(yes_bt) | |
main_kb.add(understand) | |
main_kb.add(no_bt) | |
if message.text == 'Да' or message.text == 'Нет': | |
dict_json['1'] = message.text | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
user.data = json.dumps(dict_json) | |
session.commit() | |
await message.reply('Знаете ли вы Английский?', reply_markup=main_kb) | |
await Test.english.set() | |
else: | |
await message.reply('Ошибка! Выберите один из вариантов ниже.') | |
# ты знаешь английский? | |
@dp.message_handler(state=Test.english) | |
async def knowen(message): | |
# Клавиатура | |
yes_bt = KeyboardButton('Есть, хочу знать для чего.') | |
no_bt = KeyboardButton('Есть, но не хочу показывать.') | |
main_kb = ReplyKeyboardMarkup(resize_keyboard=True) | |
main_kb.add(yes_bt) | |
main_kb.add(no_bt) | |
if message.text == 'Знаю хорошо' or message.text == 'Понимаю' or message.text == 'Не знаю': | |
dict_json['2'] = message.text | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
user.data = json.dumps(dict_json, ensure_ascii=False) | |
session.commit() | |
await message.reply('Есть ли у вас возможность показать документы?',reply_markup=main_kb) | |
await Test.documents.set() | |
else: | |
await message.reply('Ошибка! Выберите один из вариантов ниже.') | |
# документы | |
@dp.message_handler(state=Test.documents) | |
async def docvi(message): | |
ru_bt = KeyboardButton('Россия') | |
uk_bt = KeyboardButton('Украина') | |
be_bt = KeyboardButton('Беларусь') | |
main_kb = ReplyKeyboardMarkup(resize_keyboard=True) | |
main_kb.add(ru_bt) | |
main_kb.add(uk_bt) | |
main_kb.add(be_bt) | |
if message.text == 'Есть, хочу знать для чего.' or message.text == 'Есть, но не хочу показывать.': | |
dict_json['3'] = message.text | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
user.data = json.dumps(dict_json, ensure_ascii=False) | |
session.commit() | |
await message.reply('В какой стране вы проживаете?', reply_markup=main_kb) | |
await Test.country.set() | |
else: | |
await message.reply('Ошибка! Выберите один из вариантов ниже.') | |
# страна | |
@dp.message_handler(state=Test.country) | |
async def countryvi(message): | |
yes_bt = KeyboardButton('Да, готов') | |
no_bt = KeyboardButton('Нет, не готов') | |
main_kb = ReplyKeyboardMarkup(resize_keyboard=True) | |
main_kb.add(yes_bt) | |
main_kb.add(no_bt) | |
if message.text == 'Россия' or message.text == 'Украина' or message.text == 'Беларусь': | |
dict_json['4'] = message.text | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
user.data = json.dumps(dict_json, ensure_ascii=False) | |
session.commit() | |
await message.reply('Готовы пройти аутентификацию/верификацию?', reply_markup=main_kb) | |
await Test.ready.set() | |
else: | |
await message.reply('Ошибка! Выберите один из вариантов ниже.') | |
# готовность | |
@dp.message_handler(state=Test.ready) | |
async def readyvi(message): | |
if message.text == 'Да, готов': | |
dict_json['5'] = message.text | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
user.data = json.dumps(dict_json, ensure_ascii=False) | |
session.commit() | |
await message.reply('Расскажите немного о себе для того чтобы подать заявку:', reply_markup=types.ReplyKeyboardRemove()) | |
await Test.user_data.set() | |
else: | |
await message.reply('Вы всегда сможете пройти аутентификацию, чтобы подать заявку напишите о себе:', reply_markup=types.ReplyKeyboardRemove()) | |
await Test.user_data.set() | |
# анкета | |
@dp.message_handler(state=Test.user_data) | |
async def readyvi(message): | |
if len(message.text) >= 5: | |
dict_json['6'] = message.text | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
user.data = json.dumps(dict_json, ensure_ascii=False) | |
session.commit() | |
await message.reply('Отлично, ваша заявка на рассмотрении, ожидайте!') | |
await bot.send_message(admin_id, f'Новая заявка:\n{dict_json}\n\nОт id {message.from_user.id}') | |
await Test.wait.set() | |
else: | |
await message.reply('Напишите о себе побольше!') | |
# ожидание | |
@dp.message_handler(state=Test.wait) | |
async def readyvi(message): | |
test = '' | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
test = user.test | |
session.commit() | |
if test: | |
await message.reply('Ваша заявка рассмотрена, нажмите на -> /start') | |
state = dp.current_state(user=message.from_user.id) | |
await state.reset_state() | |
else: | |
await message.reply('Заявка ещё на рассмотрении!') | |
@dp.message_handler(content_types=["text"]) | |
async def check(message: types.Message): | |
global money_lose, newrefs, users | |
try: | |
if message.text == "👤 Профиль": | |
ref1 = 0 | |
ref2 = 0 | |
ref3 = 0 | |
ref4 = 0 | |
ref5 = 0 | |
refs = 0 | |
ref = '' | |
money = 0 | |
session = db_session.create_session() | |
user_all = session.query(User).all() | |
for user in user_all: | |
if user.id == message.from_user.id: | |
if user.ref: | |
ref = f'<a href="tg://user?id={user.ref}">ID{user.ref}</a>' | |
else: | |
ref = 'GAME' | |
ref1 = user.refs | |
if ref1: | |
refs = len(ref1.split(', ')) | |
else: | |
refs = 0 | |
money = user.money | |
session.commit() | |
keyboard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True) | |
chat = types.KeyboardButton(text='💬 Наш чат') | |
helpe = types.KeyboardButton(text='🆘 Тех.поддержка') | |
back = types.KeyboardButton(text='◀️ Назад') | |
keyboard.add(chat, helpe, back) | |
await bot.send_message(message.chat.id, f'💰 Баланс: {money}₽\n' + \ | |
f'🗣 Реферер: {ref}\n' + \ | |
f'👥 Рефералов: {refs}\n\n' + \ | |
f'🔗 Реферальная ссылка: https://t.me/referalsys_bot?start={message.from_user.id}', parse_mode='HTML', reply_markup=keyboard) | |
elif message.text == "📑 Вывести": | |
await bot.send_message(message.chat.id, '💻 В разработке') | |
elif message.text == "ℹ️ Инфа": | |
await bot.send_message(message.chat.id, '💻 Вся подробная информация доступна по ссылке: https://telegra.ph/Referalnaya-sistema--bot-06-14') | |
elif message.text == "📈 Статистика": | |
await bot.send_message(message.chat.id, f'📈 Статистика:\n🟢 Пользователей онлайн: {users}\n👥 Новых рефералов за сегодня: {newrefs}\n💸 Выведено денег: {money_lose}') | |
elif message.text == "🎟 Валюта": | |
await bot.send_message(message.chat.id, '💵 Рубль(₽) в боте равен реальному рублю(₽)\nПо поводу доната обращаться @vsecoder') | |
elif message.text == "💸 Задания": | |
keyboard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True) | |
back = types.KeyboardButton(text='◀️ Назад') | |
keyboard.add(back) | |
await bot.send_message(message.chat.id, '💻 В разработке', reply_markup=keyboard) | |
elif message.text == "🧮 FAQ": | |
await bot.send_message(message.chat.id, '🤑 Бот для заработка на привлечение новых пользователей в бота по специальной ссылке, наши плюсы:\n 💳 Честный заработок\n 💰 Быстрый вывод\n ⚙️ Отзывчивая тех.поддержка\n ⛓ И многое другое') | |
elif message.text == "💬 Наш чат": | |
await bot.send_message(message.chat.id, '💻 В разработке') | |
elif message.text == "🆘 Тех.поддержка": | |
keyboard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True) | |
back = types.KeyboardButton(text='◀️ Назад') | |
keyboard.add(back) | |
await bot.send_message(message.chat.id, '💻 В разработке', reply_markup=keyboard) | |
elif message.text == "◀️ Назад": | |
keyboard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True) | |
profile = types.KeyboardButton(text='👤 Профиль') | |
stop = types.KeyboardButton(text='📑 Вывести') | |
info = types.KeyboardButton(text='ℹ️ Инфа') | |
stats = types.KeyboardButton(text='📈 Статистика') | |
donat = types.KeyboardButton(text='🎟 Валюта') | |
piar = types.KeyboardButton(text='💸 Задания') | |
faq = types.KeyboardButton(text='🧮 FAQ') | |
buttons_to_add = [profile, stop, info, stats, donat, piar, faq] | |
keyboard.add(*buttons_to_add) | |
await bot.send_message(message.chat.id, '📚 Главное меню', reply_markup=keyboard) | |
else: | |
keyboard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True) | |
profile = types.KeyboardButton(text='👤 Профиль') | |
stop = types.KeyboardButton(text='📑 Вывести') | |
info = types.KeyboardButton(text='ℹ️ Инфа') | |
stats = types.KeyboardButton(text='📈 Статистика') | |
donat = types.KeyboardButton(text='🎟 Валюта') | |
piar = types.KeyboardButton(text='💸 Задания') | |
faq = types.KeyboardButton(text='🧮 FAQ') | |
buttons_to_add = [profile, stop, info, stats, donat, piar, faq] | |
keyboard.add(*buttons_to_add) | |
await bot.send_message(message.chat.id, '🤕 Я не понял вас, используйте клавиатуру!', reply_markup=keyboard) | |
except BaseException as e: | |
await bot.send_message(1218845111, 'В системе ошибка...\n<code>' + str(e) + '</code>', parse_mode='html') | |
await bot.send_message(message.chat.id, 'Упс, ошибка...') | |
# | |
if __name__ == "__main__": | |
executor.start_polling(dp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment