Ndolanz

Untitled

May 7th, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.02 KB | None | 0 0
  1. MAIN:
  2.  
  3. import logging
  4. import sqlite3
  5. import configparser, time, random
  6. from aiogram import Bot, Dispatcher, executor, types
  7. from aiogram.dispatcher import FSMContext
  8. from aiogram.utils import executor
  9. from qiwipyapi import Wallet
  10. from aiogram.contrib.fsm_storage.memory import MemoryStorage
  11. from aiogram.dispatcher.filters.state import State, StatesGroup
  12. from aiogram.dispatcher.filters import BoundFilter
  13. from string import ascii_letters, digits
  14. import db
  15. import functions as fc
  16. import keyboard as kb
  17. import keyboard as key
  18. from config import number, QIWI_SEC_TOKEN, admin
  19. from aiogram.dispatcher import FSMContext
  20.  
  21.  
  22.  
  23.  
  24. config = configparser.ConfigParser()
  25. config.read("settings.ini")
  26. TOKEN = config["tgbot"]["token"]
  27. class IsPrivate(BoundFilter):
  28. async def check(self, message: types.Message):
  29. return message.chat.type == types.ChatType.PRIVATE
  30. class Info(StatesGroup):
  31. upload_file = State()
  32. upload_file_password = State()
  33. delete_file = State()
  34. check_password = State()
  35.  
  36.  
  37. logging.basicConfig(level=logging.INFO)
  38. bot = Bot(token=TOKEN)
  39. storage = MemoryStorage()
  40. dp = Dispatcher(bot, storage=MemoryStorage())
  41.  
  42. connection = sqlite3.connect('data.db')
  43. q = connection.cursor()
  44.  
  45.  
  46. wallet_p2p = Wallet(number, p2p_sec_key=QIWI_SEC_TOKEN)
  47.  
  48. class Form(StatesGroup):
  49. report = State()
  50.  
  51.  
  52. @dp.message_handler(IsPrivate(), commands=['start', 'help'], state='*')
  53. async def start_command(message: types.Message, state: FSMContext):
  54. args = message.get_args()
  55. bot_data = await bot.get_me()
  56. bot_name = bot_data['username']
  57. if db.get_users_exist(message.chat.id) == False:
  58. await db.add_user_to_db(message)
  59. if not args:
  60. await bot.send_message(chat_id=message.chat.id, text=f'👋, <b>{message.from_user.first_name} \n</b> Я помогу тебе поделиться файлами.\n👇👇👇👇👇', reply_markup = kb.menu_kb(), parse_mode='html')
  61. else:
  62. type_file, fileID, viwes, password = db.get_file(args)
  63. if type_file is None and fileID is None:
  64. await bot.send_message(chat_id=message.chat.id, text='Я не нашел данный файл:(', reply_markup = kb.menu_kb())
  65. else:
  66. if password == (None,):
  67. db.update_viwes(args)
  68. if type_file[0] == 'photo':
  69. await bot.send_photo(chat_id=message.chat.id, photo=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  70. elif type_file[0] == 'video':
  71. await bot.send_video(chat_id=message.chat.id, video=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  72. elif type_file[0] == 'voice':
  73. await bot.send_voice(chat_id=message.chat.id, voice=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  74. elif type_file[0] == 'document':
  75. await bot.send_document(chat_id=message.chat.id, document=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  76. else:
  77. await bot.send_message(chat_id=message.chat.id, text='Упс, кажется файл защищен паролем, введите пароль:', reply_markup = kb.back_kb())
  78. await state.update_data(check_password=args)
  79. await Info.check_password.set()
  80. else:
  81. if not args:
  82. await bot.send_message(chat_id=message.chat.id, text=f'Привет, <b>{message.from_user.first_name}</b>\nЯ помогу тебе поделиться файлами.', reply_markup=key.menu, parse_mode="HTML")
  83. else:
  84. type_file, fileID, viwes, password = db.get_file(args)
  85. if type_file is None and fileID is None:
  86. await bot.send_message(chat_id=message.chat.id, text='Я не нашел данный файл:(', reply_markup = kb.menu)
  87. else:
  88. if password == (None,):
  89. db.update_viwes(args)
  90. if type_file[0] == 'photo':
  91. await bot.send_photo(chat_id=message.chat.id, photo=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  92. elif type_file[0] == 'video':
  93. await bot.send_video(chat_id=message.chat.id, video=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  94. elif type_file[0] == 'voice':
  95. await bot.send_voice(chat_id=message.chat.id, voice=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  96. elif type_file[0] == 'document':
  97. await bot.send_document(chat_id=message.chat.id, document=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={args}', reply_markup = kb.menu)
  98. else:
  99. await bot.send_message(chat_id=message.chat.id, text='Упс, кажется файл защищен паролем, введите пароль:', reply_markup = kb.back_kb())
  100. await state.update_data(check_password=args)
  101. await Info.check_password.set()
  102.  
  103.  
  104.  
  105. @dp.message_handler(text='📤Download')
  106. async def create_post(message: types.Message):
  107. if db.get_users_exist(message.chat.id) == True:
  108. await bot.send_message(chat_id=message.chat.id, text='Отправь мне файл.', reply_markup = kb.back_kb())
  109. await Info.upload_file.set()
  110.  
  111.  
  112. # @dp.message_handler(text='👤 Профиль 👤')
  113. # async def profile(message: types.Message):
  114. # if db.get_users_exist(message.chat.id) == True:
  115. # await bot.send_message(chat_id=message.chat.id, text=f'Ваше имя: <b>{message.from_user.first_name}</b>\n'
  116. # f'🫵 ник: <i>@{message.from_user.username}</i>\n'
  117. # f'Твой ID: {message.from_user.id}', parse_mode="HTML")
  118.  
  119.  
  120. @dp.message_handler(text='📁Мои файлы')
  121. async def create_post(message: types.Message):
  122. if db.get_users_exist(message.chat.id) == True:
  123. bot_data = await bot.get_me()
  124. bot_name = bot_data['username']
  125. all_types, all_ids, all_viwes, passwords = db.get_files_user(message.from_user.id)
  126. if all_types == []:
  127. await bot.send_message(chat_id=message.chat.id, text='У вас нету загруженных файлов, чтобы загрузить файлы нажмите "📤Download"', reply_markup = kb.menu)
  128. else:
  129. text='Ваши файлы: \n\n'
  130. for i, id_file in enumerate(all_ids):
  131. text+=f'{i+1}. https://t.me/{str(bot_name)}?start={id_file[0]} | {all_types[i][0]} | 👁 {all_viwes[i][0]} | Пароль: {passwords[i][0]}\n\n'
  132. await bot.send_message(chat_id=message.chat.id, text=text, reply_markup = kb.delete_file())
  133.  
  134.  
  135. # Работа с файлами добавление/удаление/пароль
  136. @dp.message_handler(state=Info.check_password, content_types=types.ContentTypes.ANY)
  137. async def upload_file(message: types.Message, state: FSMContext):
  138. bot_data = await bot.get_me()
  139. bot_name = bot_data['username']
  140. if message.text:
  141. if message.text.lower() == 'отмена':
  142. await bot.send_message(chat_id=message.chat.id, text='Вы вернулись в главное меню.', reply_markup=key.menu)
  143. await state.finish()
  144. else:
  145. user_data = await state.get_data()
  146. code = user_data['check_password']
  147. type_file, fileID, viwes, password = db.get_file(code)
  148. print(viwes[0])
  149. if message.text == password[0]:
  150. db.update_viwes(code)
  151. if type_file[0] == 'photo':
  152. await bot.send_photo(chat_id=message.chat.id, photo=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={code}', reply_markup = kb.menu_kb())
  153. elif type_file[0] == 'video':
  154. await bot.send_video(chat_id=message.chat.id, video=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={code}', reply_markup = kb.menu_kb())
  155. elif type_file[0] == 'voice':
  156. await bot.send_voice(chat_id=message.chat.id, voice=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={code}', reply_markup = kb.menu_kb())
  157. elif type_file[0] == 'document':
  158. await bot.send_document(chat_id=message.chat.id, document=fileID[0], caption=f'Вот ваш файл:\n\n👁 Просмотры: {int(viwes[0])+1}\n\nВы перешли по ссылке: https://t.me/{str(bot_name)}?start={code}', reply_markup = kb.menu_kb())
  159. await state.finish()
  160. else:
  161. await bot.send_message(chat_id=message.chat.id, text='Упс, это не верный пароль, попробуй еще раз:', reply_markup = kb.back_kb())
  162. else:
  163. await bot.send_message(chat_id=message.chat.id, text='Упс, это не верный пароль, попробуй еще раз:', reply_markup = kb.back_kb())
  164.  
  165.  
  166. @dp.message_handler(state=Info.upload_file_password, content_types=types.ContentTypes.TEXT)
  167. async def upload_file(message: types.Message, state: FSMContext):
  168. bot_data = await bot.get_me()
  169. bot_name = bot_data['username']
  170. user_data = await state.get_data()
  171. file_data = user_data['upload_file_password']
  172. if message.text == '-':
  173. if file_data.split('|')[1] == 'photo':
  174. code = file_data.split('|')[2]
  175. db.add_new_file(file_data.split('|')[0], 'photo', file_data.split('|')[2], file_data.split('|')[3])
  176. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  177. await state.finish()
  178. elif file_data.split('|')[1] == 'video':
  179. code = file_data.split('|')[2]
  180. db.add_new_file(file_data.split('|')[0], 'video', file_data.split('|')[2], file_data.split('|')[3])
  181. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  182. await state.finish()
  183. elif file_data.split('|')[1] == 'voice':
  184. code = file_data.split('|')[2]
  185. db.add_new_file(file_data.split('|')[0], 'voice', file_data.split('|')[2], file_data.split('|')[3])
  186. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  187. await state.finish()
  188. elif file_data.split('|')[1] == 'document':
  189. code = file_data.split('|')[2]
  190. db.add_new_file(file_data.split('|')[0], 'document', file_data.split('|')[2], file_data.split('|')[3])
  191. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  192. await state.finish()
  193. elif message.text.lower() == 'отмена':
  194. await bot.send_message(chat_id=message.chat.id, text='Вы вернулись в главное меню.', reply_markup=key.menu)
  195. await state.finish()
  196. else:
  197. if file_data.split('|')[1] == 'photo':
  198. code = file_data.split('|')[2]
  199. db.add_new_file_with_password(file_data.split('|')[0], 'photo', file_data.split('|')[2], file_data.split('|')[3], message.text)
  200. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nПароль: {message.text}\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  201. await state.finish()
  202. elif file_data.split('|')[1] == 'video':
  203. code = file_data.split('|')[2]
  204. db.add_new_file_with_password(file_data.split('|')[0], 'video', file_data.split('|')[2], file_data.split('|')[3], message.text)
  205. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nПароль: {message.text}\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  206. await state.finish()
  207. elif file_data.split('|')[1] == 'voice':
  208. code = file_data.split('|')[2]
  209. db.add_new_file_with_password(file_data.split('|')[0], 'voice', file_data.split('|')[2], file_data.split('|')[3], message.text)
  210. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nПароль: {message.text}\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  211. await state.finish()
  212. elif file_data.split('|')[1] == 'document':
  213. code = file_data.split('|')[2]
  214. db.add_new_file_with_password(file_data.split('|')[0], 'document', file_data.split('|')[2], file_data.split('|')[3], message.text)
  215. await bot.send_message(chat_id=message.chat.id, text=f'Файл был успешно загружен.\n\nПароль: {message.text}\n\nЧтобы 👁 на файл перейди по сылке:\nhttps://t.me/{bot_name}?start={code}', reply_markup=kb.menu)
  216. await state.finish()
  217.  
  218.  
  219.  
  220. @dp.message_handler(state=Info.upload_file, content_types=types.ContentTypes.ANY)
  221. async def upload_file(message: types.Message, state: FSMContext):
  222. bot_data = await bot.get_me()
  223. bot_name = bot_data['username']
  224. if message.photo:
  225. fileID = message.photo[-1].file_id
  226. code = ''.join(random.sample(ascii_letters + digits, random.randint(33, 40)))
  227. await state.update_data(upload_file_password=f'{message.from_user.id}|photo|{code}|{fileID}')
  228. await bot.send_message(chat_id=message.chat.id, text='Введи пароль, для файла. Если не хочешь, то напиши "-".', reply_markup=kb.back_kb())
  229. await Info.upload_file_password.set()
  230. elif message.text:
  231. if message.text.lower() == 'отмена':
  232. await bot.send_message(chat_id=message.chat.id, text='Ты вернулся в назад.', reply_markup=key.menu)
  233. await state.finish()
  234. else:
  235. await bot.send_message(chat_id=message.chat.id, text='Отправь мне файл.', reply_markup = kb.back_kb())
  236. elif message.voice:
  237. fileID = message.voice.file_id
  238. code = ''.join(random.sample(ascii_letters + digits, random.randint(33, 40)))
  239. await state.update_data(upload_file_password=f'{message.from_user.id}|voice|{code}|{fileID}')
  240. await bot.send_message(chat_id=message.chat.id, text='Введи пароль, для файла. Если не хочешь, то напиши "-".', reply_markup=kb.back_kb())
  241. await Info.upload_file_password.set()
  242. elif message.video:
  243. fileID = message.video.file_id
  244. code = ''.join(random.sample(ascii_letters + digits, random.randint(33, 40)))
  245. await state.update_data(upload_file_password=f'{message.from_user.id}|video|{code}|{fileID}')
  246. await bot.send_message(chat_id=message.chat.id, text='Введи пароль, для файла. Если не хочешь, то напиши "-".', reply_markup=kb.back_kb())
  247. await Info.upload_file_password.set()
  248. elif message.document:
  249. fileID = message.document.file_id
  250. code = ''.join(random.sample(ascii_letters + digits, random.randint(33, 40)))
  251. await state.update_data(upload_file_password=f'{message.from_user.id}|document|{code}|{fileID}')
  252. await bot.send_message(chat_id=message.chat.id, text='Введи пароль, для файла. Если не хочешь, то напиши "-".', reply_markup=kb.back_kb())
  253. await Info.upload_file_password.set()
  254.  
  255. @dp.message_handler(state=Info.delete_file, content_types=types.ContentTypes.TEXT)
  256. async def del_file(message: types.Message, state: FSMContext):
  257. try:
  258. number = int(message.text)
  259. user_data = await state.get_data()
  260. mess_id = user_data['delete_file']
  261. all_types, all_ids, all_viwes, passwords = db.get_files_user(message.from_user.id)
  262. if number > len(all_ids):
  263. await bot.send_message(chat_id=message.chat.id, text='Такого файла не существует. Введи номер файла:', reply_markup=kb.delete_back())
  264. else:
  265. db.delete_file(all_ids[(number-1)][0])
  266. await bot.delete_message(message.chat.id, mess_id)
  267. await bot.send_message(chat_id=message.chat.id, text='Вы успешно удалили файл!', reply_markup=kb.menu_kb())
  268. await state.finish()
  269. except ValueError:
  270. await bot.send_message(chat_id=message.chat.id, text='Введи номер файла:', reply_markup=kb.delete_back())
  271.  
  272.  
  273. @dp.callback_query_handler(state='*')
  274. async def handler_call(call: types.CallbackQuery, state: FSMContext):
  275. bot_data = await bot.get_me()
  276. bot_name = bot_data['username']
  277. chat_id = call.from_user.id
  278. if call.data == 'delete_file':
  279. all_types, all_ids, all_viwes, passwords = db.get_files_user(chat_id)
  280. if all_ids == []:
  281. await bot.delete_message(chat_id, call.message.message_id)
  282. await bot.send_message(chat_id=chat_id, text='У вас нету загруженных файлов, чтобы загрузить файлы нажмите "Загрузить файл"', reply_markup = kb.menu_kb())
  283. else:
  284. text='Файлы для удаления: \n\n'
  285. for i, id_file in enumerate(all_ids):
  286. text+=f'{i+1}. https://t.me/{str(bot_name)}?start={id_file[0]} | {all_types[i][0]} | 👁 {all_viwes[i][0]} | Пароль: {passwords[i][0]}\n\n'
  287. text+='Введи номер файла, который ты хочешь удалить.'
  288. await bot.edit_message_text(chat_id=chat_id, message_id=call.message.message_id, text=text, reply_markup=kb.delete_back())
  289. await state.update_data(delete_file=call.message.message_id)
  290. await Info.delete_file.set()
  291. if call.data == 'delete_back':
  292. await state.finish()
  293. all_types, all_ids, all_viwes, passwords = db.get_files_user(chat_id)
  294. if all_ids == []:
  295. await bot.delete_message(chat_id, call.message.message_id)
  296. await bot.send_message(chat_id=chat_id, text='У вас нету загруженных файлов, чтобы загрузить файлы нажмите "Загрузить файл"', reply_markup = kb.menu_kb())
  297. else:
  298. text='Ваши файлы: \n\n'
  299. for i, id_file in enumerate(all_ids):
  300. text+=f'{i+1}. https://t.me/{str(bot_name)}?start={id_file[0]} | {all_types[i][0]} | 👁 {all_viwes[i][0]} | Пароль: {passwords[i][0]}\n\n'
  301. await bot.edit_message_text(chat_id=chat_id, message_id=call.message.message_id, text=text, reply_markup=kb.delete_file())
  302.  
  303.  
  304.  
  305.  
  306.  
  307. #Кубик бот
  308. @dp.message_handler()
  309. async def anytext(message: types.Message):
  310. chat_id = message.chat.id
  311. fc.first(chat_id=chat_id)
  312. if message.text == '👤 Профиль 👤':
  313. bal = q.execute(f'SELECT balance FROM users WHERE user_id = "{message.chat.id}"').fetchone()
  314. connection.commit()
  315. await message.answer(f'Ваш профиль:\nID - {message.chat.id}\nUsername - {message.from_user.mention}\nБаланс: {bal[0]}₽', reply_markup=key.buy)
  316. elif message.text == '🎲 Кубик 🎲':
  317. await message.answer('Установите сумму на которую хотите сыграть, с помощью кнопок ниже\nПримечание: сумма должна иметься на балансе!', reply_markup=key.summ)
  318. elif message.text == '✉️ Info':
  319. await message.answer(f'Это кубик-бот, вы ставите ставку на цифру и либо выигрываете, либо проигрываете.\nВывод от 100 рублей на балансе\nПри выводе взимается комиссия в размере 5%.\nПо всем вопросам обращаться - [клик](tg://user?id={admin})', reply_markup=key.menu, parse_mode='Markdown')
  320. elif message.text == '10р':
  321. summ = 10
  322. link = fc.pay(chat_id=chat_id, summ=summ)
  323. await message.answer(f'Ваш ID - {message.chat.id}\nК оплате - {summ}₽\n[Ссылка для оплаты]({link})', reply_markup=key.pay, parse_mode='Markdown')
  324. elif message.text == '50р':
  325. summ = 50
  326. link = fc.pay(chat_id=chat_id, summ=summ)
  327. await message.answer(f'Ваш ID - {message.chat.id}\nК оплате - {summ}₽\n[Ссылка для оплаты]({link})', reply_markup=key.pay, parse_mode='Markdown')
  328. elif message.text == '100р':
  329. summ = 100
  330. link = fc.pay(chat_id=chat_id, summ=summ)
  331. await message.answer(f'Ваш ID - {message.chat.id}\nК оплате - {summ}₽\n[Ссылка для оплаты]({link})', reply_markup=key.pay, parse_mode='Markdown')
  332. elif message.text == '500р':
  333. summ = 500
  334. link = fc.pay(chat_id=chat_id, summ=summ)
  335. await message.answer(f'Ваш ID - {message.chat.id}\nК оплате - {summ}₽\n[Ссылка для оплаты]({link})', reply_markup=key.pay, parse_mode='Markdown')
  336. elif message.text == '1000р':
  337. summ = 1000
  338. link = fc.pay(chat_id=chat_id, summ=summ)
  339. await message.answer(f'Ваш ID - {message.chat.id}\nК оплате - {summ}₽\n[Ссылка для оплаты]({link})', reply_markup=key.pay, parse_mode='Markdown')
  340. elif message.text == 'Назад':
  341. await message.answer('Возвращаюсь назад..', reply_markup=key.menu)
  342. elif message.text == '/admin':
  343. if str(chat_id) == str(admin):
  344. await message.answer('Добро пожаловать в админ панель:', reply_markup=key.apanel)
  345. else:
  346. await message.answer('Черт! Ты меня взломал🙃')
  347.  
  348. @dp.callback_query_handler(lambda call: True) # Inline часть
  349. async def cal(call):
  350. chat_id = call.message.chat.id
  351. bak = q.execute(f'SELECT balance FROM users WHERE user_id = "{chat_id}"').fetchone()
  352. balik = bak[0]
  353. connection.commit()
  354. if call.data == '10r':
  355. if balik >= 10:
  356. q.execute(f'UPDATE users SET stavka = 10 WHERE user_id IS "{chat_id}"')
  357. connection.commit()
  358. await call.message.answer('Установлена сумма ставки в размере 10 рублей\nТеперь выберите цифру на которую ставите.', reply_markup=key.cifr)
  359. else:
  360. await call.message.answer('Недостаточно средств, пополните баланс.', reply_markup=key.menu)
  361. elif call.data == '50r':
  362. if balik >= 50:
  363. q.execute(f'UPDATE users SET stavka = 50 WHERE user_id IS "{chat_id}"')
  364. connection.commit()
  365. await call.message.answer('Установлена сумма ставки в размере 50 рублей\nТеперь выберите цифру на которую ставите.', reply_markup=key.cifr)
  366. else:
  367. await call.message.answer('Недостаточно средств, пополните баланс.', reply_markup=key.menu)
  368. elif call.data == '100r':
  369. if balik >= 100:
  370. q.execute(f'UPDATE users SET stavka = 100 WHERE user_id IS "{chat_id}"')
  371. connection.commit()
  372. await call.message.answer('Установлена сумма ставки в размере 100 рублей\nТеперь выберите цифру на которую ставите.', reply_markup=key.cifr)
  373. else:
  374. await call.message.answer('Недостаточно средств, пополните баланс.', reply_markup=key.menu)
  375. elif call.data == '500r':
  376. if balik >= 500:
  377. q.execute(f'UPDATE users SET stavka = 500 WHERE user_id IS "{chat_id}"')
  378. connection.commit()
  379. await call.message.answer('Установлена сумма ставки в размере 500 рублей\nТеперь выберите цифру на которую ставите.', reply_markup=key.cifr)
  380. else:
  381. await call.message.answer('Недостаточно средств, пополните баланс.', reply_markup=key.menu)
  382. elif call.data == '1000r':
  383. if balik >= 1000:
  384. q.execute(f'UPDATE users SET stavka = 1000 WHERE user_id IS "{chat_id}"')
  385. connection.commit()
  386. await call.message.answer('Установлена сумма ставки в размере 1000 рублей\nТеперь выберите цифру на которую ставите.', reply_markup=key.cifr)
  387. else:
  388. await call.message.answer('Недостаточно средств, пополните баланс.', reply_markup=key.menu)
  389. elif call.data == '1':
  390. q.execute(f'UPDATE users SET num = 1 WHERE user_id IS "{chat_id}"')
  391. connection.commit()
  392. await call.message.answer('Вы поставили на цифру 1', reply_markup=key.next)
  393. elif call.data == '2':
  394. q.execute(f'UPDATE users SET num = 2 WHERE user_id IS "{chat_id}"')
  395. connection.commit()
  396. await call.message.answer('Вы поставили на цифру 2', reply_markup=key.next)
  397. elif call.data == '3':
  398. q.execute(f'UPDATE users SET num = 3 WHERE user_id IS "{chat_id}"')
  399. connection.commit()
  400. await call.message.answer('Вы поставили на цифру 3', reply_markup=key.next)
  401. elif call.data == '4':
  402. q.execute(f'UPDATE users SET num = 4 WHERE user_id IS "{chat_id}"')
  403. connection.commit()
  404. await call.message.answer('Вы поставили на цифру 4', reply_markup=key.next)
  405. elif call.data == '5':
  406. q.execute(f'UPDATE users SET num = 5 WHERE user_id IS "{chat_id}"')
  407. connection.commit()
  408. await call.message.answer('Вы поставили на цифру 5', reply_markup=key.next)
  409. elif call.data == '6':
  410. q.execute(f'UPDATE users SET num = 6 WHERE user_id IS "{chat_id}"')
  411. connection.commit()
  412. await call.message.answer('Вы поставили на цифру 6', reply_markup=key.next)
  413. elif call.data == 'next':
  414. ss = q.execute(f'SELECT stavka FROM users WHERE user_id IS "{chat_id}"').fetchone()
  415. connection.commit()
  416. number = q.execute(f'SELECT num FROM users WHERE user_id IS "{chat_id}"').fetchone()
  417. connection.commit()
  418. await call.message.answer(f'Отлично, вот ваша ставка:\nСумма: {ss[0]}\nСтавка на цифру {number[0]}\nЕсли все верно, жмите "Верно", если нет, жмите "Назад"', reply_markup=key.ask)
  419. elif call.data == 'back':
  420. await call.message.answer('Возвращаюсь назад...', reply_markup=key.menu)
  421. elif call.data == 'ok':
  422. rep = fc.dice()
  423. number = q.execute(f'SELECT num FROM users WHERE user_id IS "{chat_id}"').fetchone()
  424. nm = number[0]
  425. connection.commit()
  426. if rep == nm:
  427. ss = q.execute(f'UPDATE users SET balance = balance + stavka WHERE user_id IS "{chat_id}"').fetchone()
  428. connection.commit()
  429. bal = q.execute(f'SELECT balance FROM users WHERE user_id = "{chat_id}"').fetchone()
  430. connection.commit()
  431. await call.message.answer(f'Поздравляем! Вам повезло, выпало число: {rep}\nВаш баланс: {bal[0]}₽', reply_markup=key.menu)
  432. else:
  433. aa = q.execute(f'UPDATE users SET balance = balance - stavka WHERE user_id IS "{chat_id}"').fetchone()
  434. connection.commit()
  435. bal = q.execute(f'SELECT balance FROM users WHERE user_id = "{chat_id}"').fetchone()
  436. connection.commit()
  437. await call.message.answer(f'Увы, но вы проиграли, вам выпало число: {rep}\nВаш баланс: {bal[0]}₽', reply_markup=key.menu)
  438. elif call.data == 'pay':
  439. await call.message.answer('Выберите сумму для пополнения:', reply_markup=key.paysum)
  440. elif call.data == 'check':
  441. try:
  442. re = q.execute(f"SELECT bd FROM users WHERE user_id = {chat_id}").fetchone()
  443. status = wallet_p2p.invoice_status(bill_id=re[0])
  444. val = status['amount']['value']
  445. value = int(float(val))
  446. a = status['status']['value']
  447. if a == 'WAITING':
  448. await call.message.answer('Ошибка! Платёж не найден.', reply_markup=key.pay)
  449. elif a == 'PAID':
  450. await call.message.answer('Оплата успешно найдена.\nТеперь вы можете вывести баланс.', reply_markup=key.menu)
  451. q.execute(f'UPDATE users SET balance = balance + {value} WHERE user_id IS "{chat_id}"')
  452. q.execute(f'UPDATE users SET bd = 0 WHERE user_id IS "{chat_id}"')
  453. connection.commit()
  454. elif a == 'EXPIRED':
  455. await call.message.answer('Время жизни счета истекло. Счет не оплачен', reply_markup=key.pay)
  456. elif a == 'REJECTED':
  457. await call.message.answer('Счет отклонен', reply_markup=key.pay)
  458. elif a == 'UNPAID':
  459. await call.message.answer('Ошибка при проведении оплаты. Счет не оплачен', reply_markup=key.pay)
  460. except Exception as err:
  461. await call.message.answer(f'Ошибка:\n{err}')
  462. elif call.data == 'out':
  463. bal = q.execute(f'SELECT balance FROM users WHERE user_id = "{chat_id}"').fetchone()
  464. connection.commit()
  465. if bal[0] >= 100:
  466. await call.message.answer('Выберите сумму, которую хотите вывести:\nЕсли желаемой суммы нет в списке, нажмите на "Другое" и напишите администратору.', reply_markup=key.viv)
  467. else:
  468. await call.message.answer(f'Недостаточно средств на балансе\nВывод от 100 рублей!', reply_markup=key.menu)
  469. elif call.data == '100rub':
  470. bal = q.execute(f'SELECT balance FROM users WHERE user_id = "{chat_id}"').fetchone()
  471. connection.commit()
  472. q.execute(f'UPDATE users SET balance = balance - 100 WHERE user_id = "{chat_id}"')
  473. connection.commit()
  474. await call.message.answer(f'Заявка на вывод успешно отправлена администраторам, с вами скоро свяжутся.', reply_markup=key.menu)
  475. await bot.send_message(admin, f'Новая заявка на вывод:\nID - {chat_id}\nЮзернейм - {call.from_user.mention}\n[Ссылка на пользователя]({call.from_user.url})\nБаланс: {bal[0]}₽\nХочет вывести: 100 руб\nС учетом комиссии получит: 95\nСвяжитесь с пользователем, чтобы отправить ему деньги.', parse_mode='Markdown')
  476. elif call.data == '500rub':
  477. bal = q.execute(f'SELECT balance FROM users WHERE user_id = "{chat_id}"').fetchone()
  478. connection.commit()
  479. if bal[0] >= 500:
  480. q.execute(f'UPDATE users SET balance = balance - 500 WHERE user_id = "{chat_id}"')
  481. connection.commit()
  482. await call.message.answer(f'Заявка на вывод успешно отправлена администраторам, с вами скоро свяжутся.', reply_markup=key.menu)
  483. await bot.send_message(admin, f'Новая заявка на вывод:\nID - {chat_id}\nЮзернейм - {call.from_user.mention}\n[Ссылка на пользователя]({call.from_user.url})\nБаланс: {bal[0]}₽\nХочет вывести: 500 руб\nС учетом комиссии получит: 475\nСвяжитесь с пользователем, чтобы отправить ему деньги.', parse_mode='Markdown')
  484. else:
  485. await call.message.answer('Недостаточно средств на балансе', reply_markup=key.menu)
  486. elif call.data == '1000rub':
  487. bal = q.execute(f'SELECT balance FROM users WHERE user_id = "{chat_id}"').fetchone()
  488. connection.commit()
  489. if bal[0] >= 1000:
  490. q.execute(f'UPDATE users SET balance = balance - 1000 WHERE user_id = "{chat_id}"')
  491. connection.commit()
  492. await call.message.answer(f'Заявка на вывод успешно отправлена администраторам, с вами скоро свяжутся.', reply_markup=key.menu)
  493. await bot.send_message(admin, f'Новая заявка на вывод:\nID - {chat_id}\nЮзернейм - {call.from_user.mention}\n[Ссылка на пользователя]({call.from_user.url})\nБаланс: {bal[0]}₽\nХочет вывести: 1000 руб\nС учетом комиссии получит: 950\nСвяжитесь с пользователем, чтобы отправить ему деньги.', parse_mode='Markdown')
  494. else:
  495. await call.message.answer('Недостаточно средств на балансе', reply_markup=key.menu)
  496. elif call.data == 'stats':
  497. re = q.execute(f'SELECT * FROM users').fetchall()
  498. kol = len(re)
  499. bal = q.execute(f"SELECT sum(balance) FROM users").fetchone()
  500. connection.commit()
  501. await call.message.answer(f'Всего пользователей: {kol}\nОбщий баланс всех пользователей: {bal[0]}₽')
  502.  
  503.  
  504.  
  505.  
  506. if __name__ == "__main__":
  507. db.check_db()
  508. executor.start_polling(dp, skip_updates=True)
  509. KEYBOARD:
  510. from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardButton
  511. from aiogram import Bot, Dispatcher, executor, types
  512. from config import ausername
  513.  
  514.  
  515.  
  516. # Клавиатура
  517. menu = types.ReplyKeyboardMarkup(row_width=3, resize_keyboard=True)
  518. menu.add(
  519. types.KeyboardButton(text='Зароботок'),
  520. types.KeyboardButton(text='🎲 Кубик 🎲'),
  521. types.KeyboardButton(text='📤Download'),
  522. types.KeyboardButton(text='📁Мои файлы'),
  523. types.KeyboardButton(text='👤 Профиль 👤'),
  524. types.KeyboardButton(text='✉️ Info')
  525. )
  526.  
  527.  
  528. def back_kb():
  529. button1 = KeyboardButton('Отмена')
  530. back_kb1 = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
  531. back_kb1.add(button1)
  532. return back_kb1
  533.  
  534. def delete_file():
  535. markup = InlineKeyboardMarkup()
  536. btn2 = InlineKeyboardButton(text='🔄 Удалить файл 🔄', callback_data=f'delete_file')
  537. markup.add(btn2)
  538. return markup
  539.  
  540. def delete_back():
  541. markup = InlineKeyboardMarkup()
  542. btn2 = InlineKeyboardButton(text='Отмена', callback_data=f'delete_back')
  543. markup.add(btn2)
  544. return markup
  545.  
  546.  
  547.  
  548. summ = types.InlineKeyboardMarkup(row_width=3)
  549. summ.add(
  550. types.InlineKeyboardButton(text='10 руб', callback_data='10r'),
  551. types.InlineKeyboardButton(text='50 руб', callback_data='50r'),
  552. types.InlineKeyboardButton(text='100 руб', callback_data='100r'),
  553. types.InlineKeyboardButton(text='500 руб', callback_data='500r'),
  554. types.InlineKeyboardButton(text='1000 руб', callback_data='1000r'),
  555. types.InlineKeyboardButton(text='Назад', callback_data='back')
  556. )
  557.  
  558.  
  559. cifr = types.InlineKeyboardMarkup(row_width=3)
  560. cifr.add(
  561. types.InlineKeyboardButton(text='1', callback_data='1'),
  562. types.InlineKeyboardButton(text='2', callback_data='2'),
  563. types.InlineKeyboardButton(text='3', callback_data='3'),
  564. types.InlineKeyboardButton(text='4', callback_data='4'),
  565. types.InlineKeyboardButton(text='5', callback_data='5'),
  566. types.InlineKeyboardButton(text='6', callback_data='6'),
  567. types.InlineKeyboardButton(text='Назад', callback_data='back')
  568. )
  569.  
  570. next = types.InlineKeyboardMarkup(row_width=3)
  571. next.add(
  572. types.InlineKeyboardButton(text='Продолжить', callback_data='next'),
  573. types.InlineKeyboardButton(text='Назад', callback_data='back')
  574. )
  575.  
  576.  
  577. ask = types.InlineKeyboardMarkup(row_width=3)
  578. ask.add(
  579. types.InlineKeyboardButton(text='Верно', callback_data='ok'),
  580. types.InlineKeyboardButton(text='Назад', callback_data='back')
  581. )
  582.  
  583.  
  584. buy = types.InlineKeyboardMarkup(row_width=3)
  585. buy.add(
  586. types.InlineKeyboardButton(text='Пополнить', callback_data='pay'),
  587. types.InlineKeyboardButton(text='Вывод', callback_data='out'),
  588. types.InlineKeyboardButton(text='Назад', callback_data='back')
  589. )
  590.  
  591.  
  592. pay = types.InlineKeyboardMarkup(row_width=3)
  593. pay.add(
  594. types.InlineKeyboardButton(text='Проверить оплату', callback_data='check'),
  595. types.InlineKeyboardButton(text='Назад', callback_data='back')
  596. )
  597.  
  598. paysum = types.ReplyKeyboardMarkup(resize_keyboard=True)
  599. paysum.add(
  600. types.KeyboardButton(text='10р'),
  601. types.KeyboardButton(text='50р'),
  602. types.KeyboardButton(text='100р'),
  603. types.KeyboardButton(text='500р'),
  604. types.KeyboardButton(text='1000р'),
  605. types.KeyboardButton(text='Назад')
  606. )
  607.  
  608. apanel = types.InlineKeyboardMarkup(row_width=3)
  609. apanel.add(
  610. types.InlineKeyboardButton(text='Статистика', callback_data='stats'),
  611. types.InlineKeyboardButton(text='Розсилка', callback_data='rozsl')
  612. )
  613.  
  614. output = types.InlineKeyboardMarkup(row_width=3)
  615. output.add(
  616. types.InlineKeyboardButton(text='Вывести', callback_data='output'),
  617. types.InlineKeyboardButton(text='Назад', callback_data='back')
  618. )
  619.  
  620.  
  621. viv = types.InlineKeyboardMarkup(row_width=3, )
  622. viv.add(
  623. types.InlineKeyboardButton(text='500 руб', callback_data='500rub'),
  624. types.InlineKeyboardButton(text='1000 руб', callback_data='1000rub'),
  625. types.InlineKeyboardButton(text='Другое', url=f't.me/{ausername}'),
  626. types.InlineKeyboardButton(text='Назад', callback_data='back')
  627. )
Add Comment
Please, Sign In to add comment