import logging
import functions as func
import menu
import texts
import random
import time
import asyncio
import threading
import datetime
import utils.dice as dice
import traceback
from utils.user import
from states import
from aiogram import Bot, Dispatcher, executor, types
from aiogram.dispatcher import FSMContext
from aiogram.contrib.fsm_storage.memory import MemoryStorage
@dp.message_handler(commands=['admin'])
async def admin(message: types.Message):
if str(message.chat.id) in config.config('admin_id_manager'):
await message.answer('/check user_id - данные о пользователе', reply_markup=menu.admin_menu())
pre-formatted fixed-width code block written in the Python programming language
""",
parse_mode='html'
)
if call.data == 'create_dice':
await CreateGame.bet.set()
await bot.send_message(chat_id=chat_id,
text=f'💰 Введите сумму ставки от {config.config("min_bank")} до {User(chat_id).balance} RUB',
reply_markup=dice.cancel_dice())
if call.data == 'reload_dice':
await bot.edit_message_text(chat_id=chat_id, message_id=message_id,
text='Создайте игру или выберите уже имеющуюся:',
reply_markup=dice.dice_menu())
if call.data == 'my_games_dice':
resp = dice.my_games_dice(chat_id)
await bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=resp[0], reply_markup=resp[1])
if call.data == 'rating_dice':
await bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=dice.rating_dice(chat_id),
reply_markup=dice.back_dice())
if call.data == 'back_dice':
await bot.edit_message_text(chat_id=chat_id, message_id=message_id,
text='Создайте игру или выберите уже имеющуюся:',
reply_markup=dice.dice_menu())
if call.data == 'help_dice':
await bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=dice.help_txt)
if call.data == 'cancel_dice':
await bot.delete_message(chat_id=chat_id, message_id=message_id)
await bot.clear_step_handler_by_chat_id(chat_id)
if 'dice_game:' in call.data:
game = dice.Game(call.data.split(':')[1])
if game.status == True and game.user_id != str(chat_id):
info = dice.dice_game(call.data.split(':')[1])
if info == False:
await bot.send_message(chat_id=chat_id, text='🚫 Игра не найдена')
else:
await bot.send_message(chat_id=chat_id, text=info[0], reply_markup=info[1])
else:
await bot.send_message(chat_id=chat_id, text='🚫 Нельзя играть с самим собой')
if 'start_game_dice:' in call.data:
game = dice.Game(call.data.split(':')[1])
if game.status != False and game.user_id != str(chat_id):
if User(chat_id).balance >= game.bet:
await dice.main_start(game, bot, chat_id)
else:
await bot.send_message(chat_id=chat_id, text='❌Для игры пополните баланс')
else:
await bot.send_message(chat_id=chat_id, text='❌Ошибка')
if call.data == 'exit':
await bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='<b>Главное меню</b>', parse_mode='html')
if call.data == 'back_to_admin_menu':
await bot.send_message(chat_id=chat_id, text='Меню админа', reply_markup=menu.admin_menu())
if call.data == 'withdrawal_requests':
await bot.send_message(chat_id=chat_id, text='Лист', reply_markup=func.withdrawal_requests())
if 'withdraw:' in call.data:
info = func.get_info_withdraw(call.data.split(':')[1])
await bot.send_message(chat_id=chat_id, text=info[0], reply_markup=info[1])
if 'withdraw_del:' in call.data:
await func.withdraw_del(call.data.split(':')[1], bot)
await bot.send_message(chat_id=chat_id, text='Удалено')
if 'withdraw_send' in call.data:
a = func.withdraw_sender(call.data.split(':')[1], bot)
await bot.send_message(chat_id=chat_id, text=f'Статус отправки: {a}!')
@dp.message_handler(state=Admin_give_balance.user_id)
async def admin_give_balance_1(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['user_id'] = message.text
await Admin_give_balance.next()
await message.answer('Введите сумму на которую будет изменен баланс')
@dp.message_handler(state=Admin_give_balance.balance)
async def admin_give_balance_2(message: types.Message, state: FSMContext):
try:
async with state.proxy() as data:
data['balance'] = float(message.text)
chat_id = message.chat.id
try:
user = User(chat_id)
bet = float('{:.2f}'.format(float(message.text)))
if bet <= user.balance and bet >= float(config.config('min_bank')):
user.update_balance(-bet)
dice.create_game(chat_id, bet)
await bot.send_message(
chat_id=message.chat.id,
text='✅Ваша ставка принята!'
)
else:
await bot.send_message(
chat_id=message.chat.id,
text='⚠️ Неверная ставка'
)
except Exception as e:
await bot.send_message(
chat_id=message.chat.id,
text='⚠️ Что-то пошло не по плану'
)
user = User(chat_id)
if withdraw_sum >= float(config.config('min_withdraw_sum')) and withdraw_sum <= user.balance:
async with state.proxy() as data:
data['withdraw_sum'] = withdraw_sum
await Withdraw.next()
await message.answer('(например Qiwi +79999999999)\nУкажите реквизиты для вывода💰: ')
else:
await state.finish()
await bot.send_message(chat_id=message.chat.id, text='Неверная сумма')
except Exception as e:
await state.finish()
await bot.send_message(chat_id=message.chat.id, text='⚠️ Что-то пошло не по плану')
async with state.proxy() as data:
data['info'] = info
await Withdraw.next()
await message.answer(f'Ваши реквизиты:\n{info}\n\nДля подтверждения отправьте +')
except Exception as e:
await state.finish()
await bot.send_message(chat_id=message.chat.id, text='⚠️ Что-то пошло не по плану')
@dp.message_handler(state=Withdraw.confirm)
async def withdraw_confirm(message: types.Message, state: FSMContext):
chat_id = message.chat.id
try:
if message.text == '+':
async with state.proxy() as data:
if func.add_withdraw(chat_id, data['withdraw_sum'], data['info']) == True:
await bot.send_message(chat_id=message.chat.id, text='Вы подали заявку на вывод!')
else:
await bot.send_message(chat_id=message.chat.id, text='Вывод отменен')
await state.finish()
except Exception as e:
state.finish()
await bot.send_message(chat_id=message.chat.id, text='⚠️ Что-то пошло не по плану')
async def sending_check(wait_for):
while True:
await asyncio.sleep(wait_for)
try:
info = func.sending_check()
if info != False:
users = func.get_users_list()
start_time = time.time()
amount_message = 0
amount_bad = 0
if info[0] == 'text':
try:
await bot.send_message(
chat_id=config.config('admin_id_manager').split(':')[0],
text=f'✅ Запуск рассылки')
except: pass
for i in range(len(users)):
try:
await bot.send_message(users[i][0], info[1], parse_mode='html')
amount_message += 1
except Exception as e:
amount_bad += 1
sending_time = time.time() - start_time
try:
await bot.send_message(
chat_id=config.config('admin_id_manager').split(':')[0],
text=f'✅ Рассылка окончена\n'
f'👍 Отправлено: {amount_message}\n'
f'👎 Не отправлено: {amount_bad}\n'
f'🕐 Время выполнения рассылки - {sending_time} секунд'
)
except:
print('ERROR ADMIN SENDING')
elif info[0] == 'photo':
try:
await bot.send_message(
chat_id=config.config('admin_id_manager').split(':')[0],
text=f'✅ Запуск рассылки')
except: pass
for i in range(len(users)):
try:
with open(f'photos/{info[2]}.jpg', 'rb') as photo:
await bot.send_photo(
chat_id=users[i][0],
photo=photo,
caption=info[1],
parse_mode='html')
amount_message += 1
except:
amount_bad += 1
sending_time = time.time() - start_time
try:
await bot.send_message(
chat_id=config.config('admin_id_manager').split(':')[0],
text=f'✅ Рассылка окончена\n'
f'👍 Отправлено: {amount_message}\n'
f'👎 Не отправлено: {amount_bad}\n'
f'🕐 Время выполнения рассылки - {sending_time} секунд'
)
except:
print('ERROR ADMIN SENDING')
else:
pass
except Exception as e:
print(e)
import logging import functions as func import menu import texts import random import time import asyncio import threading import datetime
import utils.dice as dice
import traceback
from utils.user import from states import
from aiogram import Bot, Dispatcher, executor, types from aiogram.dispatcher import FSMContext from aiogram.contrib.fsm_storage.memory import MemoryStorage
Configure logging
logging.basicConfig(level=logging.INFO)
bot = Bot(token=config.config('bot_token'))
storage = MemoryStorage() dp = Dispatcher(bot, storage=storage)
@dp.message_handler(commands=['start', 'help']) async def send_welcome(message: types.Message): check = await func.first_join(message.chat.id, message.chat.first_name, message.chat.username, message.text, bot)
@dp.message_handler(commands=['admin']) async def admin(message: types.Message): if str(message.chat.id) in config.config('admin_id_manager'): await message.answer('/check user_id - данные о пользователе', reply_markup=menu.admin_menu())
@dp.message_handler() async def send_message(message: types.Message): chat_id = message.chat.id first_name = message.from_user.first_name username = message.from_user.username
USER_ID: {user.user_id} Ник: {user.first_name} Логин: {user.username} Баланс: {user.balance} Кто пригласил: {who_invite} Дата первого входа: {user.date} """ ) except: await message.answer('Ошибка')
@dp.callback_query_handler() async def handler_call(call: types.CallbackQuery, state: FSMContext): chat_id = call.from_user.id message_id = call.message.message_id first_name = call.from_user.first_name username = call.from_user.username
Для выделения текста в рассылке используйте следующий синтакс:
1 | bold, bold 2 | italic, italic 3 | underline, underline 4 |
10 | """) bot.send_message(chat_id=chat_id, text=""" Так это будет выглядить в рассылке:strikethrough,strikethrough,strikethrough5 | bold italic bolditalic bold strikethroughunderline italic bold bold 6 | inline URL 7 | inline mention of a user 8 |inline fixed-width code
9 |1 | bold, bold 2 | italic, italic 3 | underline, underline 4 |
10 | """, parse_mode='html' )strikethrough,strikethrough,strikethrough5 | bold italic bolditalic bold strikethroughunderline italic bold bold 6 | inline URL 7 | inline mention of a user 8 |inline fixed-width code
9 |@dp.message_handler(state=Admin_give_balance.user_id) async def admin_give_balance_1(message: types.Message, state: FSMContext): async with state.proxy() as data: data['user_id'] = message.text
@dp.message_handler(state=Admin_give_balance.balance) async def admin_give_balance_2(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['balance'] = float(message.text)
ID: {data['user_id']} Баланс изменится на: {data['balance']}
Для подтверждения отправьте + """) except: await state.finish() await message.answer('⚠️ ERROR ⚠️')
@dp.message_handler(state=Admin_give_balance.confirm) async def admin_give_balance_3(message: types.Message, state: FSMContext): if message.text == '+': async with state.proxy() as data: func.give_balance(data['balance'], data['user_id'])
@dp.message_handler(state=Email_sending_photo.photo, content_types=['photo']) async def email_sending_photo_1(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['photo'] = random.randint(111111111, 999999999)
@dp.message_handler(state=Email_sending_photo.text) async def email_sending_photo_2(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['text'] = message.text
@dp.message_handler(state=Email_sending_photo.action) async def email_sending_photo_3(message: types.Message, state: FSMContext): chat_id = message.chat.id try: if message.text in menu.admin_sending_btn: if message.text == menu.admin_sending_btn[0]: # Начать
Введите дату начала рассылке в формате: ДЕНЬ:ЧАСОВ:МИНУТ
Например 18:14:10 - рассылка будет сделана 18 числа в 14:10 """ )
@dp.message_handler(state=Email_sending_photo.set_down_sending) async def email_sending_photo_4(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['date'] = message.text date = data['date']
@dp.message_handler(state=Email_sending_photo.set_down_sending_confirm) async def email_sending_photo_5(message: types.Message, state: FSMContext): if message.text == '+': async with state.proxy() as data: data['type_sending'] = 'photo'
@dp.message_handler(state=Admin_sending_messages.text) async def admin_sending_messages_1(message: types.Message, state: FSMContext): async with state.proxy() as data: data['text'] = message.text
@dp.message_handler(state=Admin_sending_messages.action) async def admin_sending_messages_2(message: types.Message, state: FSMContext): chat_id = message.chat.id
Введите дату начала рассылке в формате: ДЕНЬ:ЧАСОВ:МИНУТ\n
Например 18:14:10 - рассылка будет сделана 18 числа в 14:10 """ )
@dp.message_handler(state=Admin_sending_messages.set_down_sending) async def admin_sending_messages_3(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['date'] = message.text date = data['date']
@dp.message_handler(state=Admin_sending_messages.set_down_sending_confirm) async def admin_sending_messages_4(message: types.Message, state: FSMContext): if message.text == '+': async with state.proxy() as data: data['type_sending'] = 'text' data['photo'] = random.randint(111111,9999999)
@dp.message_handler(state=Admin_buttons.admin_buttons_del) async def admin_buttons_del(message: types.Message, state: FSMContext): try: func.admin_del_btn(message.text)
@dp.message_handler(state=Admin_buttons.admin_buttons_add) async def admin_buttons_add(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['name'] = message.text
@dp.message_handler(state=Admin_buttons.admin_buttons_add_text) async def admin_buttons_add_text(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['text'] = message.text
@dp.message_handler(state=Admin_buttons.admin_buttons_add_photo, content_types=['photo']) async def admin_buttons_add_photo(message: types.Message, state: FSMContext): try: async with state.proxy() as data: data['photo'] = random.randint(111111111, 999999999)
@dp.message_handler(state=Admin_buttons.admin_buttons_add_confirm) async def admin_buttons_add_confirm(message: types.Message, state: FSMContext): if message.text == '+': async with state.proxy() as data: func.admin_add_btn(data["name"], data["text"], data["photo"])
@dp.message_handler(state=CreateGame.bet) async def creategame_bet(message: types.Message, state: FSMContext): await state.finish()
@dp.message_handler(state=Withdraw.withdraw_sum) async def withdraw_sum(message: types.Message, state: FSMContext): chat_id = message.chat.id try: withdraw_sum = float('{:.2f}'.format(float(message.text)))
@dp.message_handler(state=Withdraw.info) async def withdraw_info(message: types.Message, state: FSMContext): chat_id = message.chat.id try: info = message.text
@dp.message_handler(state=Withdraw.confirm) async def withdraw_confirm(message: types.Message, state: FSMContext): chat_id = message.chat.id try: if message.text == '+': async with state.proxy() as data: if func.add_withdraw(chat_id, data['withdraw_sum'], data['info']) == True: await bot.send_message(chat_id=message.chat.id, text='Вы подали заявку на вывод!') else: await bot.send_message(chat_id=message.chat.id, text='Вывод отменен')
async def sending_check(wait_for): while True: await asyncio.sleep(wait_for)
if name == 'main':