import telebot
from telebot import types
from telebot import TeleBot
import time
import json
import requests
import random
bot = telebot.TeleBot('897115094:AAH4UWOsIQHNSBTPHUxSyJPnloIWlcgIR2Y')

#TELETHON
#from threading import Thread
#from telethon import TelegramClient, sync

#api_id = 1165395
#api_hash = "98d176b4d335a69da3e191868208c5ab"
#client = TelegramClient('session', api_id, api_hash)
#client.start()
#participants = client.get_participants('t.me/joinchat/AAAAAE2DSCVFUoxDrXjK8Q')
#a = 0
#def my_func():
#	for x in range(100000):
#	    time.sleep(30)
#	    try:
#	    	b = participants[a].id
#	    	print(b)
#	    	a +=1
#	    	try:
#	    		with open ('id'+str(b)+'.json') as id:
#	    			pass
#	    	except FileNotFoundError:
#	    		client.kick_participant('https://t.me/joinchat/AAAAAE2DSCVFUoxDrXjK8Q', b)
#	    except IndexError:
#	    	pass
#	    else: 
#	    	pass
#			
#Thread(target=my_func).start()


api_access_token = '27c72abc784adc309385afbb810ec0хххх'# токен qiwi
my_login = 79128732ххх # номер QIWI Кошелька

s = requests.Session()
s.headers['authorization'] = 'Bearer ' + api_access_token
parameters = {'rows': '49'}
h = s.get('https://edge.qiwi.com/payment-history/v1/persons/'+str(my_login)+'/payments', params = parameters)
qiwi = json.loads(h.text)
comment1 = qiwi['data'][0]['comment']
sum1 = qiwi['data'][0]['sum']['amount']
status1 = qiwi['data'][0]['status']
comment2 = qiwi['data'][0]['comment']
sum2 = qiwi['data'][0]['sum']['amount']
status2 = qiwi['data'][0]['status']
comment3 = qiwi['data'][0]['comment']
sum3 = qiwi['data'][0]['sum']['amount']
status3 = qiwi['data'][0]['status']
comment4 = qiwi['data'][0]['comment']
sum4 = qiwi['data'][0]['sum']['amount']
status4 = qiwi['data'][0]['status']
comment5 = qiwi['data'][0]['comment']
sum5 = qiwi['data'][0]['sum']['amount']
status5 = qiwi['data'][0]['status']
comment6 = qiwi['data'][0]['comment']
sum6 = qiwi['data'][0]['sum']['amount']
status6 = qiwi['data'][0]['status']
comment7 = qiwi['data'][0]['comment']
sum7 = qiwi['data'][0]['sum']['amount']
status7 = qiwi['data'][0]['status']
comment8 = qiwi['data'][0]['comment']
sum8 = qiwi['data'][0]['sum']['amount']
status8 = qiwi['data'][0]['status']
comment9 = qiwi['data'][0]['comment']
sum9 = qiwi['data'][0]['sum']['amount']
status9 = qiwi['data'][0]['status']
comment10 = qiwi['data'][0]['comment']
sum10 = qiwi['data'][0]['sum']['amount']
status10 = qiwi['data'][0]['status']
print(status1, status10)

#СТАРТОВОЕ МЕНЮ
@bot.message_handler(commands=['start'])
def get_id(message):
	keyboard_menu = types.InlineKeyboardMarkup()
	button_bonus = types.InlineKeyboardButton(text = 'Бонусная программа', callback_data ='bonus')
	button_pay = types.InlineKeyboardButton(text='Сигналы', callback_data = 'pay')
	button_contacts = types.InlineKeyboardButton(text = 'Контакты', callback_data = 'contacts')
	keyboard_menu.add(button_pay, button_contacts)
	keyboard_menu.add(button_bonus)
	name = message.from_user.first_name
	bot.send_message(message.from_user.id , '😃Привет' + name + '...', reply_markup=keyboard_menu)
	
	
	
	
	
	#КНОПКИ СИГНАЛЫ И БОНУСНАЯ ПРОГРАММА			
@bot.callback_query_handler(func=lambda call:call.data in ['bonus', 'pay'])
def calls(call):
	if call.data == 'bonus':
		with open('bal.json', 'r') as bala:
			json_data = json.load(bala)
			json_data['bal'+str(call.message.chat.id)] = 0
		with open('bal.json', 'w') as d:
			d.write(json.dumps(json_data))
		button_invite = types.InlineKeyboardButton(text = 'Ввод промо-кодов', callback_data = 'enter')
		button_balans = types.InlineKeyboardButton(text = 'Баланс', callback_data = 'bal')
		button_promo = types.InlineKeyboardButton(text = 'Программа обмена', callback_data='promo')
		button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back')
		keyboard_bonus = types.InlineKeyboardMarkup()
		keyboard_bonus.add(button_balans, button_invite) 
		keyboard_bonus.add(button_promo)
		keyboard_bonus.add(button_back)
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text ='...')
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_bonus)
		keyboard_back = types.InlineKeyboardMarkup()
		keyboard_back.add(button_back)		
	elif call.data == 'pay':
		keyboard_time = types.InlineKeyboardMarkup()
		button_pay_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back')
		keyboard_time_button_1d = types.InlineKeyboardButton(text = '24 часа', callback_data = '24h')
		keyboard_time_button_7d = types.InlineKeyboardButton(text = '1 неделя', callback_data = '7d')
		keyboard_time_button_30d = types.InlineKeyboardButton(text = '1 месяц', callback_data = '30d')
		keyboard_time.add(keyboard_time_button_1d, keyboard_time_button_7d)
		keyboard_time.add(keyboard_time_button_30d)
		keyboard_time.add(button_pay_back)
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="...")
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_time)
		
		
		
		

														
#ОПЛАТА
@bot.callback_query_handler(func=lambda call:call.data in ['24h', '7d', '30d'])
def v(call):
	if call.data == '24h':
		user_id = call.message.chat.id
		print(user_id)
		back_url_button = types.InlineKeyboardButton(text='Назад', callback_data = 'back2')
		keyboard_pay = types.InlineKeyboardMarkup()
		button_pay = types.InlineKeyboardButton(text = 'Перейти к оплате', url = 'https://qiwi.com/payment/form/99?amountInteger=1&amountFraction=0&currency=643&extra[%E2%80%98account%E2%80%99]=791287325хх&extra[%E2%80%98comment%E2%80%99]=' + str(user_id)+ '&blocked[0]=account&blocked[1]=sum&blocked[2]=comment', callback_data = "url1")
		button_pay_finish = types.InlineKeyboardButton(text = 'Я оплатил!', callback_data = 'pay_finish1')
		keyboard_pay.add(button_pay)
		keyboard_pay.add(button_pay_finish)
		keyboard_pay.add(back_url_button)
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Нажмите на кнопку, чтобы оплатить подписку на 24 часа.')
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_pay)
	
		keyboard_back_pay = types.InlineKeyboardMarkup()
		
		keyboard_back_pay.add(back_url_button)
	elif call.data == '7d':
		user_id = call.message.chat.id
		back_url_button = types.InlineKeyboardButton(text='Назад', callback_data = 'back2')
		keyboard_pay = types.InlineKeyboardMarkup()
		button_pay = types.InlineKeyboardButton(text = 'Перейти к оплате', url = 'https://qiwi.com/payment/form/99?amountInteger=1000&amountFraction=0&currency=643&extra[%E2%80%98account%E2%80%99]=791287325ххх&extra[%E2%80%98comment%E2%80%99]=' + str(user_id)+ '&blocked[0]=account&blocked[1]=sum&blocked[2]=comment', callback_data = "url1")
		button_pay_finish = types.InlineKeyboardButton(text = 'Я оплатил!', callback_data = 'pay_finish2')
		keyboard_pay.add(button_pay)
		keyboard_pay.add(button_pay_finish)
		keyboard_pay.add(back_url_button)
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Нажмите на кнопку, чтобы оплатить подписку на 7 дней.')
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_pay)
	elif call.data == '30d':
		user_id = call.message.chat.id
		back_url_button = types.InlineKeyboardButton(text='Назад', callback_data = 'back2')
		keyboard_pay = types.InlineKeyboardMarkup()
		button_pay = types.InlineKeyboardButton(text = 'Перейти к оплате', url = 'https://qiwi.com/payment/form/99?amountInteger=3000&amountFraction=0&currency=643&extra[%E2%80%98account%E2%80%99]=791287325хх&extra[%E2%80%98comment%E2%80%99]=' + str(user_id)+ '&blocked[0]=account&blocked[1]=sum&blocked[2]=comment', callback_data = "url1")
		button_pay_finish = types.InlineKeyboardButton(text = 'Я оплатил!', callback_data = 'pay_finish3')
		keyboard_pay.add(button_pay)
		keyboard_pay.add(button_pay_finish)
		keyboard_pay.add(back_url_button)
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Нажмите на кнопку, чтобы оплатить подписку на 30 дней')
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_pay)
	
	
	
	
		
	
@bot.callback_query_handler(func = lambda call:call.data in ['pay_finish1','pay_finish2', 'pay_finish3'])
def finish(call):
	user_id = call.message.chat.id
	id = user_id	
	if call.data == 'pay_finish1':	
		time_to_kick1 = 60
		print(comment1, sum1, status1)
		if (comment1 == str(user_id) and sum1 == 1) or  (comment2 == str(user_id) and sum2 == 1)  or (comment3 == str(user_id) and sum3 == 1) or (comment4 == str(user_id) and sum4 == 1) or (comment5 == str(user_id) and sum5 == 1) or (comment6 == str(user_id) and sum6 == 1) or (comment7 == str(user_id) and sum7 == 1) or (comment8 == str(user_id) and sum8 == 1) or (comment9 == str(user_id) and sum9 == 1) or (comment10 == str(user_id) and sum10 == 1):
			try:
				bot.unban_chat_member(-1001300449317, user_id)
			except:
				pass
				
			file = open('id'+str(id)+'.json', 'w')
	    # Создаем json строку 
			json_str = json.dumps({ 'id': id})
	    # Записываем наш json
			file.write(json_str)
   	 # Закрываем файл
			file.close()		
			keyboard_url = types.InlineKeyboardMarkup()
			url_button = types.InlineKeyboardButton(text="Перейти", url="https://t.me/joinchat/AAAAAE2DSCVFUoxDrXjK8Q", callback_data = 'url')	
			keyboard_url.add(url_button)
			
			bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Благодарим, что выбрали именно нас!\n\n Вы оплатили подписку на 24 часа!\n\nПройдите по ссылке ниже и начинайте зарабатывать прямо сейчас!")	
			bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_url)

				
			bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_url)
			time.sleep(time_to_kick1)#изменить на дата
			bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="До окончания подписки 1 минут!\n Не забудьте продлить подписку по истечению времени!")
			time.sleep(60)
			bot.kick_chat_member(-1001300449317, user_id)
		else: 
			bot.answer_callback_query(call.id, text='Вы не оплатили!', show_alert=True)	
			
#КНОПКИ НАЗАД 
@bot.callback_query_handler(func=lambda call:call.data in['back'])
def back(call):
	if call.data == 'back':
		keyboard_menu = types.InlineKeyboardMarkup()
	button_bonus = types.InlineKeyboardButton(text = 'Бонусная программа', callback_data ='bonus')
	button_pay = types.InlineKeyboardButton(text='Сигналы', callback_data = 'pay')
	button_contacts = types.InlineKeyboardButton(text = 'Контакты', callback_data = 'contacts')
	keyboard_menu.add(button_pay, button_contacts)
	keyboard_menu.add(button_bonus)
	bot.edit_message_text(chat_id=call.message.chat.id , message_id=call.message.message_id, text= '...')
	bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_menu)
	
@bot.callback_query_handler(func = lambda call:call.data in ['back2'])
def some(call):
	keyboard_time = types.InlineKeyboardMarkup()
	keyboard_time_button_1d = types.InlineKeyboardButton(text = '24 часа', callback_data = '24h')
	keyboard_time_button_7d = types.InlineKeyboardButton(text = '7 дней', callback_data = '7d')
	keyboard_time_button_30d = types.InlineKeyboardButton(text = '30 дней', callback_data = '30d')
	keyboard_time.add(keyboard_time_button_1d, keyboard_time_button_7d)
	keyboard_time.add(keyboard_time_button_30d)
	bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выберите время действии подписки:")
	bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_time)


@bot.message_handler(content_types=['text'])
def shoto(message):
	button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back')
	keyboard_back = types.InlineKeyboardMarkup()
	keyboard_back.add(button_back)	
	with open('promos.json', 'r') as f:
		a = json.load(f)['promo1']
	with open('promos.json', 'r') as f: 
		b = json.load(f)['promo2']
	with open('promos.json', 'r') as f: 
		c = json.load(f)['promo3']
	with open('promos.json', 'r') as f: 
		d = json.load(f)['promo4']
	with open('promos.json', 'r') as f: 
		e = json.load(f)['promo5']
	with open('promos.json', 'r') as f: 
		f = json.load(f)['promo6']
	with open('promos.json', 'r') as f: 
		g = json.load(f)['promo7']
	with open('promos.json', 'r') as f: 
		h = json.load(f)['promo8']
	with open('promos.json', 'r') as f: 
		i = json.load(f)['promo9']
	with open('promos.json', 'r') as f: 
		j = json.load(f)['promo10']
	if message.text == '06120709':
		keyboard_admin = types.InlineKeyboardMarkup()
		button_promotypes= types.InlineKeyboardButton(text = '100 бонусов/одноразовые' , callback_data = '100one')
		keyboard_admin.add(button_promotypes)
		bot.send_message(730888010, text = 'Выбери какой промо-код хочешь создать:', reply_markup=keyboard_admin)
	elif message.text == '/start':
		pass	
	elif message.text == a:
		id = message.from_user.id
		print(id)
		with open('bal.json', 'r') as bala:
			balai = json.load(bala)['bal'+str(id)]	
			bala1 = int(balai)
		with open('bal.json', 'r') as bala:	
			json_data = json.load(bala)
			json_data['bal'+str(id)] = str(bala1 + 100)
		with open('bal.json', 'w') as d:
			d.write(json.dumps(json_data))	
		with open('bal.json', 'r') as bala:
			print(bala.read())
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo1'] = 'some must to be'    
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))
		with open('bal.json', "r") as soam:
			print(soam.read())
		bot.send_message(id, '100 бонусов успешно зачислены!')	
	else:
		id = message.from_user.id		
		bot.send_message(id, 'Некорректный ввод!', reply_markup=keyboard_back)
		
@bot.callback_query_handler(func=lambda call:call.data in ['enter', 'bal', 'promo'])			
def bonus_answer(call):
	if call.data == 'enter':
		button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back1')
		keyboard_back = types.InlineKeyboardMarkup()
		keyboard_back.add(button_back)
		bot.edit_message_text(chat_id=call.message.chat.id,message_id=call.message.message_id, text = 'Введите промо-код:')
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_back)
		
	elif call.data == 'bal':			
		button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back1')
		keyboard_back = types.InlineKeyboardMarkup()
		keyboard_back.add(button_back)
		with open('bal.json', 'r') as bala:		
			da_zapustis_ty=json.load(bala)['bal730888010']
		print(da_zapustis_ty)
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text= 'На вашем балансе ' + str(da_zapustis_ty) +' баллов.')
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_back)
		
	elif call.data == 'promo':
		keyboard_back = types.InlineKeyboardMarkup()
		user_id = call.message.chat.id
		button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back1')
		button_buy = types.InlineKeyboardButton(text = 'Обменять', callback_data = 'obmen')
		keyboard_back.add(button_buy)
		keyboard_back.add(button_back)	
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text= 'Обменяй баллы на 1-дневную подписку')
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_back)	 

#																														
#	elif message.text == b:
#		id =message.from_user.id
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal730888010'] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#			bot.send_message(id, '100 бонусов успешно зачислены!')
#			with open('promos.json', 'r') as f:
#				json_data = json.load(f)
#				json_data['promo2'] = 'somes must to be'    
#			with open('promos.json', 'w') as d:
#				d.write(json.dumps(json_data))				
#						
#	elif message.text == c:
#		id =message.from_user.id
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal'+str(id)] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#			bot.send_message(id, '100 бонусов успешно зачислены!')		
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo3'] = 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data))					
#															
#	elif message.text == d:
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal'+str(id)] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#		bot.send_message(id, '100 бонусов успешно зачислены!')		
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo4'] = 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data))		
#			
#	elif message.text == e:
#		id =message.from_user.id
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal'+str(id)] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#		bot.send_message(id, '100 бонусов успешно зачислены!')			
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo5'] = 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data))					
#						
#	elif message.text == f:
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal'+str(id)] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#		bot.send_message(id, '100 бонусов успешно зачислены!')	
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo6'] = 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data))									
#			
#	elif message.text == g:
#		id =message.from_user.id
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal'+str(id)] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#		bot.send_message(id, '100 бонусов успешно зачислены!')		
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo7'] = 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data))		

#	elif message.text == h:
#		id =message.from_user.id
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal730888010'] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#		bot.send_message(id, '100 бонусов успешно зачислены!')				
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo8'] = 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data))		
#								
#	elif message.text == i:
#		id =message.from_user.id
#		with open('bal.json', 'r') as bala:
#			bala = json.load(bala)['bal'+str(id)]	
#			bala = int(bala)		
#		with open('bal.json', 'r') as bad:
#			json_data = json.load(bad)
#			json_data['bal'+str(id)] = str(bala + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#		bot.send_message(id, '100 бонусов успешно зачислены!')	
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo9']= 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data))		
#			
#	elif message.text == j:
#		id =message.from_user.id
#		with open('bal.json', 'r') as l:
#			ab = json.load(l)['bal'+str(id)]			
#		with open('bal.json', 'r') as d:
#			json_data = json.load(d)
#			json_data['bal'+str(id)] = str(ab + 100)
#		with open('bal.json', 'w') as d:
#			d.write(json.dumps(json_data))
#		bot.send_message(id, '100 бонусов успешно зачислены!', reply_markup=keyboard_back)
#		with open('promos.json', 'r') as f:
#			json_data = json.load(f)
#			json_data['promo10'] = 'somes must to be'    
#		with open('promos.json', 'w') as d:
#			d.write(json.dumps(json_data),)			
			
@bot.callback_query_handler(func = lambda call:call.data in ['obmen'])
def sasa(call):
	id = call.message.chat.id
	with open("bal.json") as bala:
		ba = json.load(bala)['bal'+str(id)]
	if ba >= 100:
		with open('bal.json', 'r') as f:
			json_data = json.load(f)
			json_data['bal'+str(id)] = str(ba - 100) 
		with open('bal.json', 'w') as d:
			d.write(json.dumps(json_data))		

		time_to_kick1 = 60
		keyboard_url = types.InlineKeyboardMarkup()
		url_button = types.InlineKeyboardButton(text="Перейти", url="https://t.me/joinchat/AAAAAE2DSCVFUoxDrXjK8Q", callback_data = 'url')	
		keyboard_url.add(url_button)				
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Вы успешно оплатили бесплатную 24-часовую подписку!")		
		bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard_url)
		time.sleep(time_to_kick1)#изменить на дата
		bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="До окончания подписки 1 минутa!")
		time.sleep(60)
		bot.kick_chat_member(-1001300449317, call.message.from_user.id)
	else: 
			bot.answer_callback_query(call.id, text='Недостаточно средств!', show_alert=True)
		
@bot.callback_query_handler(func = lambda call:call.data in ['100one'])
def bonuses(call):
	first = ('A', 'B', 'C', 'D', 'E','F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
	second = first
	third = ( '1', '2', '3', '4', '5', '6', '7', '8', '9', '0')
	fourth =  third
	fifth = first
	sixth = first
	seven = third
	eight = third
	def some1():
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta		
		a = 1	
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus       
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))		

	def some2():		
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta
		a = 2	
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus       
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))
		with open('promos.json', 'r') as c:
			print(c.read())		

	def some3():	
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta
		a = 3	
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus      
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))

	def some4():	
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta	
		a = 4	
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus      
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))

	def some5():			
		firsta = random.choice(first)
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta		
		a = 5
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus      
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))

	def some6():	
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta			
		a = 6
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus      
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))

	def some7():	
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta			
		a = 7	
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus    
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))

	def some8():	
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta		
		a = 8
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus       
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))

	def some9():	
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta			
		a = 9
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus       
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))

	def some10():	
		firsta = random.choice(first)
		seconda = random.choice(second)
		thirda = random.choice(third)
		fourtha = random.choice(fourth)
		fiftha = random.choice(fifth)
		sixtha = random.choice(sixth)
		sevena = random.choice(seven)
		eighta = random.choice(eight)
		promo_bonus = firsta + seconda + thirda + fourtha  + '-' + fiftha + sixtha+sevena + eighta			
		a = 10
		with open('promos.json', 'r') as f:
			json_data = json.load(f)
			json_data['promo'+str(a)] = promo_bonus       
		with open('promos.json', 'w') as d:
			d.write(json.dumps(json_data))
		some1()
		some2()
		some3()
		some4()
		some5()
		some6()
		some7()
		some8()
		some9()
		some10()	
	with open('promos.json', 'r') as f: 		
		promo1 = json.load(f)['promo1']
	with open('promos.json', 'r') as f: 
		promo2 = json.load(f)['promo2']
	with open('promos.json', 'r') as f: 
		promo3 = json.load(f)['promo3']
	with open('promos.json', 'r') as f: 
		promo4 = json.load(f)['promo4']
	with open('promos.json', 'r') as f: 
		promo5 = json.load(f)['promo5']
	with open('promos.json', 'r') as f: 
		promo6 = json.load(f)['promo6']
	with open('promos.json', 'r') as f: 
		promo7 = json.load(f)['promo7']
	with open('promos.json', 'r') as f: 
		promo8 = json.load(f)['promo8']
	with open('promos.json', 'r') as f: 
		promo9 = json.load(f)['promo9']
	with open('promos.json', 'r') as f: 		
		promo10 = json.load(f)['promo10']
		bot.edit_message_text(chat_id=730888010, message_id=call.message.message_id, text = 'Твои промо-коды:+\n' + str(promo1) + '\n' + str(promo2) + '\n' + str(promo3) + '\n' + str(promo4) + '\n' + str(promo5) + '\n' + str(promo6) + '\n' + str(promo7) + '\n' + str(promo8) + '\n' + str(promo9) + '\n' + str(promo10) + '\n')
		button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back1')
		keyboard_back = types.InlineKeyboardMarkup()
		keyboard_back.add(button_back)	
		bot.edit_message_reply_markup(chat_id=730888010, message_id=call.message.message_id, reply_markup=keyboard_back)

bot.polling(none_stop=True)