Advertisement
Guest User

Untitled

a guest
May 6th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 45.22 KB | None | 0 0
  1. # !/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import threading
  5. import vk_api
  6. from vk_api.longpoll import VkLongPoll, VkEventType
  7. from vk_api.keyboard import VkKeyboard, VkKeyboardColor
  8. from datetime import datetime
  9. import random
  10. import time
  11. import os
  12. import pymysql.cursors
  13. import logging
  14. import vkcoin
  15.  
  16. file_log = logging.FileHandler('Log.log')
  17. console_out = logging.StreamHandler()
  18. merchant = vkcoin.VKCoinApi(user_id=242193778, )  # Ваш ID и ключ
  19. logging.basicConfig(handlers=(file_log, console_out),
  20.                     level=logging.INFO)
  21.  
  22.  
  23. logging.basicConfig(filename="sample.log", level=logging.INFO)
  24. """ БД """
  25. def connecti():
  26.     conn = pymysql.connect(host='127.0.0.1',
  27.                                  user='root',
  28.                                  password='',
  29.                                  db='vkbot',
  30.                                  charset='utf8mb4',
  31.                                  cursorclass=pymysql.cursors.DictCursor)
  32.     return conn
  33.  
  34. def register(imid):
  35.     connection = connecti()
  36.     try:
  37.         with connection.cursor() as cursor:
  38.             result = cursor.execute(f"SELECT * FROM account WHERE idvk={imid}")
  39.             row = cursor.fetchone()
  40.             if result == 0:
  41.                 cursor.execute(f"INSERT INTO account(idvk) VALUES({imid})")
  42.                 connection.commit()
  43.             else:
  44.                 return row
  45.     finally:
  46.         connection.close()
  47.  
  48. def getdate (imid):
  49.     connect = connecti()
  50.     try:
  51.         with connect.cursor() as cursor:
  52.             result = cursor.execute(f"SELECT * FROM account WHERE idvk={imid}")
  53.             row = cursor.fetchone()
  54.            
  55.             if result == 1:
  56.                 return row
  57.     finally:
  58.         connect.close()
  59.  
  60. def savedate (imid, iq1, nickname1, job1, jobn1, timeend1, pazle1, paper1, excoins1, frac1, chees,doc,prog,sprog,atack,defend,regen,vs,vkcoin):
  61.     connect = connecti()
  62.     try:
  63.         with connect.cursor() as cursor:
  64.             result = cursor.execute(f"UPDATE account SET iq={iq1}, nickname='{nickname1}', job='{job1}', jobn={jobn1}, timeend={timeend1}, pazle={pazle1}, paper={paper1}, excoins={excoins1}, frac='{frac1}', chees={chees}, doc={doc}, prog = {prog}, sprog = {sprog}, atack = {atack}, defend = {defend}, regen = {regen}, vs={vs}, vkcoin={vkcoin} WHERE idvk={imid}")
  65.             connect.commit()
  66.             return result
  67.     finally:
  68.         connect.close()
  69. def savedatecoin (imid, vkcoin):
  70.     connect = connecti()
  71.     try:
  72.         with connect.cursor() as cursor:
  73.             result = cursor.execute(f"UPDATE account SET vkcoin={vkcoin} WHERE idvk={imid}")
  74.             connect.commit()
  75.             return result
  76.     finally:
  77.         connect.close()
  78. token = ""
  79. vk_session = vk_api.VkApi(token=token)
  80. session_api = vk_session.get_api()
  81. longpoll = VkLongPoll(vk_session)
  82.  
  83. def captcha_handler(captcha):
  84.     key = input("Enter captcha code {0}: ".format(captcha.get_url())).strip()
  85.     return captcha.try_again(key)
  86.  
  87. def create_keyboard(response):
  88.     keyboard = VkKeyboard(one_time=True)
  89.  
  90.     keyboard.add_button('Я', color=VkKeyboardColor.NEGATIVE)
  91.     keyboard.add_button('Работы', color=VkKeyboardColor.POSITIVE)
  92.     # keyboard.add_button('Магазин', color=VkKeyboardColor.POSITIVE)
  93.     keyboard.add_line()
  94.     keyboard.add_button('Дела', color=VkKeyboardColor.DEFAULT)
  95.     keyboard.add_button('Vkcoin', color=VkKeyboardColor.POSITIVE)
  96.     keyboard.add_button('Битва', color=VkKeyboardColor.POSITIVE)
  97.     keyboard.add_line()
  98.     keyboard.add_button('Работать', color=VkKeyboardColor.DEFAULT)
  99.  
  100.     keyboard = keyboard.get_keyboard()
  101.     return keyboard
  102.  
  103. def noiq(imid, iqneed,iq):
  104.     keyboard = create_rabota(response)
  105.     vk_session.method('messages.send', {'user_id': imid, 'message': f'У вас не достаточно {iqneed-iq} IQ, чтобы его прокачать, зайдите в пункт дела', 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  106.  
  107. def create_rabota(response):
  108.     keyboard = VkKeyboard(one_time=True)
  109.  
  110.     keyboard.add_button('Уборщик', color=VkKeyboardColor.POSITIVE)
  111.     keyboard.add_button('Дворник', color=VkKeyboardColor.POSITIVE)
  112.     keyboard.add_line()
  113.     keyboard.add_button('Строитель', color=VkKeyboardColor.POSITIVE)
  114.     keyboard.add_button('Архитектор', color=VkKeyboardColor.POSITIVE)
  115.     keyboard.add_line()
  116.     keyboard.add_button('Cпасатель', color=VkKeyboardColor.POSITIVE)
  117.     keyboard.add_button('Юрист', color=VkKeyboardColor.POSITIVE)
  118.     keyboard.add_line()
  119.     keyboard.add_button('Дизайнер', color=VkKeyboardColor.POSITIVE)
  120.     keyboard.add_button('Разработчик', color=VkKeyboardColor.POSITIVE)
  121.     keyboard.add_line()
  122.     keyboard.add_button('Я', color=VkKeyboardColor.NEGATIVE)
  123.  
  124.     keyboard = keyboard.get_keyboard()
  125.     return keyboard
  126.  
  127. def create_dela(response):
  128.     keyboard = VkKeyboard(one_time=True)
  129.  
  130.     keyboard.add_button('Собирать пазлы', color=VkKeyboardColor.DEFAULT)
  131.     keyboard.add_button('Читать газету', color=VkKeyboardColor.POSITIVE)
  132.     keyboard.add_line()
  133.     keyboard.add_button('Играть в шахматы', color=VkKeyboardColor.POSITIVE)
  134.     keyboard.add_button('Читать техническую документацию', color=VkKeyboardColor.POSITIVE)
  135.     keyboard.add_line()
  136.     keyboard.add_button('Практиковаться в программировании', color=VkKeyboardColor.POSITIVE)
  137.     keyboard.add_button('Написать высоконагруженный проект', color=VkKeyboardColor.POSITIVE)
  138.     keyboard.add_line()
  139.     keyboard.add_button('Я', color=VkKeyboardColor.NEGATIVE)
  140.  
  141.  
  142.     keyboard = keyboard.get_keyboard()
  143.     return keyboard
  144.  
  145. def create_fractionkey(response):
  146.     keyboard = VkKeyboard(one_time=True)
  147.     keyboard.add_button('Фракция1', color=VkKeyboardColor.DEFAULT)
  148.     keyboard.add_button('Фракция2', color=VkKeyboardColor.POSITIVE)
  149.     keyboard = keyboard.get_keyboard()
  150.     return keyboard
  151. def create_atackkey(response):
  152.     keyboard = VkKeyboard(one_time=True)
  153.     keyboard.add_button('Атака', color=VkKeyboardColor.NEGATIVE)
  154.     keyboard.add_button('Защита', color=VkKeyboardColor.POSITIVE)
  155.     keyboard = keyboard.get_keyboard()
  156.     return keyboard
  157. def create_nz(response):
  158.     keyboard = VkKeyboard(one_time=True)
  159.     keyboard.add_button('Я', color=VkKeyboardColor.NEGATIVE)
  160.     keyboard = keyboard.get_keyboard()
  161.     return keyboard
  162. def create_vkcoinkey(response):
  163.     keyboard = VkKeyboard(one_time=True)
  164.     keyboard.add_button('Пополнить', color=VkKeyboardColor.NEGATIVE)
  165.     keyboard = keyboard.get_keyboard()
  166.     return keyboard
  167.  
  168. """
  169.     Поток и его поведение
  170. """
  171. def mesed (imid, responsce):
  172.  row = register(imid)
  173.  row = getdate(imid)
  174.  job = row['job']
  175.  iq = row['iq']
  176.  nickname = row['nickname']
  177.  excoins = row['excoins']
  178.  timeend = row['timeend']
  179.  jobn = row['jobn']
  180.  pazle = row['pazle']
  181.  paper = row['paper']
  182.  frac = str(row['frac'])
  183.  chees = row['chees']
  184.  doc = row['doc']
  185.  prog = row['prog']
  186.  strongprog = row['sprog']
  187.  atack = row['atack']
  188.  defend = row['defend']
  189.  regen = row['regen']
  190.  vs = row['vs']
  191.  
  192.  vkcoin = row['vkcoin']
  193.  
  194.  if nickname == "":
  195.     vk_session.method('messages.send', {'user_id': event.user_id, 'message': 'У вас не установлен ник, пожалуйста введите его :) ', 'random_id': random.randint(0, 9999999999), 'captcha_handler': captcha_handler})
  196.     nickname = "*"
  197.  elif nickname == "*":
  198.      nickname = response
  199.      keyboard = create_fractionkey(response)
  200.      vk_session.method('messages.send',{'user_id': event.user_id, 'message': ' /*Ник установлен*/ Так же, тебе надо выбрать фракцию за которую ты будешь играть ', 'keyboard': keyboard,'random_id': random.randint(0, 9999999999), 'captcha_handler': captcha_handler})
  201.      frac = "404"
  202.  elif frac == "404":
  203.      vk_session.method('messages.send', {'user_id': imid, 'message': "/*Фракция выбрана*/ \n О чём игра? \n Ты уже выбрал фракцию за которую ты будешь воевать, теперь именно они твои братья. \n Каждый день в 3 часа проходит битва в которой ты должен сражаться как атакующий или защищающий \n Чтобы увеличить урон или защиту, нужно купить предметы в магазине за excoins \n Чтобы заработать деньги нужно устроиться на работу, но не все работы будут доступны тебе сразу, для некоторых работ требуется равзитие тоесть очки IQ которые можно заработать в разделе Дела. \n Ну что-ж! Начнём. Для продолжения введите Я", 'random_id': random.randint(0, 9999999999), 'captcha_handler': captcha_handler})
  204.      if response == "фракция1":
  205.          frac = "фракция1"
  206.      if response == "фракция2":
  207.          frac = "фракция2"
  208.  else:
  209.             if response == "я":
  210.                 d1 = datetime.utcnow()
  211.                 d2 = datetime(d1.year,d1.month,d1.day,12)
  212.                 sc = round((d2-d1).total_seconds())
  213.                 mc = int(sc/60)
  214.                 hc = mc/60
  215.                 if mc - round(hc)*60 <= 0:
  216.                     timebitva = f"Завтра в 18:00"
  217.                 elif hc < 1:
  218.                     timebitva = f"через {mc} минут"
  219.                 elif hc >=1:
  220.                     timebitva = f"через {round(hc)} часов {mc - round(hc)*60} минут"
  221.  
  222.                 keyboard = create_keyboard(response)
  223.                 messa = "🔎Я, " + str(nickname) + f"\n🚧Ваша фракция {frac}"
  224.                 messa = messa + "\n\n🔥Ваша работа:  " + str(job) +  " \n🧬Ваш IQ: " + str(iq) + "\n💰Ваш баланс: " + str(excoins) + f" excoins | {vkcoin} vkcoins"+f"\n\n 🧰Навыки: \n\n ⚔Атака:{atack} \n 🧯Защита:{defend} \n ⚒Регенерация:{regen} \n 🔋Выносливость:{vs} \n\n 🚨Битва  {timebitva} \n 🚦Вы собрались"
  225.                 vk_session.method('messages.send', {'user_id': imid, 'message': messa, 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  226.             elif response =="vkcoin":
  227.                 keyboard = create_vkcoinkey(response)
  228.                 vk_session.method('messages.send', {'user_id': event.user_id,
  229.                                                     'message': 'Меню действий с vkcoin',
  230.                                                     'keyboard': keyboard, 'random_id': random.randint(0, 9999999999),
  231.                                                     'captcha_handler': captcha_handler})
  232.             elif response == "пополнить":
  233.                 keyboard = create_nz(response)
  234.                 result = merchant.get_payment_url(amount=10, payload=78922, free_amount=True)
  235.                 vk_session.method('messages.send', {'user_id': event.user_id,
  236.                                                     'message': f'Вот ваша ссылка - {result} Сумму выбирайте сами.',
  237.                                                     'keyboard': keyboard, 'random_id': random.randint(0, 9999999999),
  238.                                                     'captcha_handler': captcha_handler})
  239.  
  240.  
  241.  
  242.             elif response == "битва":
  243.                 keyboard = create_atackkey(response)
  244.                 vk_session.method('messages.send',{'user_id': imid, 'message': f'Это меню битвы, выберите будите вы атаковать или защищаться\n При атаке важен навыки ⚔Атака и 🔋Выносливость \n При Защите навыки ⚒Регенерация и 🧯Защита. \n Точный алгоритм битвы засекречен, но есть смысл и атаковать и защищаться. \n А теперь выбирите, будете вы защищться или атаковать', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  245.             elif response == "атака":
  246.                 statsb2 = "атаковать"
  247.                 keyboard = create_nz(response)
  248.                 vk_session.method('messages.send', {'user_id': event.user_id,
  249.                                                     'message': 'Вы установили статус битвы, чтобы вернуться нажмите назад ',
  250.                                                     'random_id': random.randint(0, 9999999999),
  251.                                                     'captcha_handler': captcha_handler, 'keyboard': keyboard} )
  252.  
  253.             elif response == "защита":
  254.                 statsb2 = "защищять"
  255.                 keyboard = create_nz(response)
  256.                 vk_session.method('messages.send', {'user_id': event.user_id,
  257.                                                     'message': 'Вы установили статус битвы, чтобы вернуться нажмите назад ',
  258.                                                     'random_id': random.randint(0, 9999999999),
  259.                                                     'captcha_handler': captcha_handler, 'keyboard': keyboard})
  260.  
  261.  
  262.  
  263.             elif response == "работы":
  264.                 keyboard = create_rabota(response)
  265.                 vk_session.method('messages.send', {'user_id': imid, 'message': 'Работы: \n Название\iq необходиморемяарплата \nУборщик 0iq 1мин 1coin \nДворник 5iq 1.5 мин 3coin\nСтроитель 10iq 2мин 8сoin\nАрхитектор 30iq 2мин 10 coin\nСпасатель 50iq 2мин 20coin\nЮрист 100iq 3 мин 40coin\nДизайнер 120iq 4мин 50coin\nРазработчик 300iq 5мин 100coin', 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  266.             elif response == "уборщик":
  267.                 job = "уборщик"
  268.                 jobn = 1
  269.                 keyboard = create_keyboard(response)
  270.                 vk_session.method('messages.send',{'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  271.             elif response == "дворник":
  272.                 if iq>=5:
  273.                     job = "дворник"
  274.                     jobn = 2
  275.                     keyboard = create_keyboard(response)
  276.                     vk_session.method('messages.send', {'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  277.                 else:
  278.                     noiq(imid,5,iq)
  279.             elif response == "строитель":
  280.                 if iq >= 10:
  281.                     job = "строитель"
  282.                     jobn = 3
  283.                     keyboard = create_keyboard(response)
  284.                     vk_session.method('messages.send',{'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  285.                 else:
  286.                     noiq(imid,10,iq)
  287.             elif response == "архитектор":
  288.                 if iq >= 30:
  289.                     job = "архитектор"
  290.                     jobn = 4
  291.                     keyboard = create_keyboard(response)
  292.                     vk_session.method('messages.send', {'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  293.                 else:
  294.                     noiq(imid,30,iq)
  295.             elif response == "спасатель":
  296.                 if iq >= 50:
  297.                     job = "спасатель"
  298.                     jobn = 5
  299.                     keyboard = create_keyboard(response)
  300.                     vk_session.method('messages.send', {'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  301.                 else:
  302.                     noiq(imid,50,iq)
  303.             elif response == "юрист":
  304.                 if iq >= 100:
  305.                     job = "юрист"
  306.                     jobn = 6
  307.                     keyboard = create_keyboard(response)
  308.                     vk_session.method('messages.send',{'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  309.                 else:
  310.                     noiq(imid,100,iq)
  311.             elif response == "дизайнер":
  312.                 if iq >= 120:
  313.                     job = "дизайнер"
  314.                     jobn = 7
  315.                     keyboard = create_keyboard(response)
  316.                     vk_session.method('messages.send',{'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  317.                 else:
  318.                     noiq(imid,120,iq)
  319.             elif response == "разработчик":
  320.                 if iq >= 300:
  321.                     job = "разработчик"
  322.                     jobn = 8
  323.                     keyboard = create_keyboard(response)
  324.                     vk_session.method('messages.send', {'user_id': imid, 'message': f'Вы устроились на работу {job}', 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  325.                 else:
  326.                     noiq(imid,300,iq)
  327.             elif response == "дела":
  328.                 keyboard = create_dela(response)
  329.                 vk_session.method('messages.send', {'user_id': imid, 'message': f'Дела нужны чтобы прокачать ваш IQ \n 1) Собрать пазлы Стоимость: {pazle} +0.1iq \n2) Читать газету Стоимость: {paper} +0.2 iq \n3) Играть в шахматы Стоимость:{chees} +0.5iq \n4) Читать техническую документацию Стоимость: {doc} + 1iq \n5) Практиковаться в программировании Стоимость: {prog}  +3iq Только при iq>50 \n6) Написать высоконагруженный проект Стоимость: {strongprog} +10 iq Только при iq>150', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  330.             elif response == "собирать пазлы":
  331.                 if int(excoins) >= float(pazle):
  332.                     excoins = excoins - pazle
  333.                     pazle = pazle*1.5
  334.                     iq = iq+0.1
  335.                     keyboard = create_dela(response)
  336.                     vk_session.method('messages.send',
  337.                                       {'user_id': imid, 'message': f'Вы собррпли пазлы для детей от 3-ёх лет. \n +0.1 IQ, теперь у вас {iq}',
  338.                                        'random_id': random.randint(0, 9999999999),
  339.                                        'keyboard': keyboard, 'captcha_handler': captcha_handler})
  340.                 else:
  341.                     keyboard = create_dela(response)
  342.                     vk_session.method('messages.send',{'user_id': imid, 'message': f'У вас не хватает {pazle - excoins} денег', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  343.             elif response == "играть в шахматы":
  344.                 if int(excoins) >= float(chees):
  345.                     excoins = excoins - chees
  346.                     chees = chees * 1.5
  347.                     iq = iq + 0.5
  348.                     keyboard = create_dela(response)
  349.                     vk_session.method('messages.send', {'user_id': imid, 'message': f'Вы поиграли в шахматы, +0.5 IQ, теперь у вас {iq}',
  350.                                                         'random_id': random.randint(0, 9999999999),
  351.                                                         'keyboard': keyboard, 'captcha_handler': captcha_handler})
  352.                 else:
  353.                     keyboard = create_dela(response)
  354.                     vk_session.method('messages.send',{'user_id': imid, 'message': f'У вас не хватает {chees - excoins} денег', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  355.             elif response == "читать газету":
  356.                 if int(excoins) >= float(paper):
  357.                     paper = excoins - paper
  358.                     paper = paper * 1.5
  359.                     iq = iq + 0.2
  360.                     keyboard = create_dela(response)
  361.                     vk_session.method('messages.send', {'user_id': imid, 'message': f'Вы прочитали газету, там было очень много жёлтых новостей, но попались и интерестные статьи \n +0.2 IQ, теперь у вас {iq}',
  362.                                                         'random_id': random.randint(0, 9999999999),
  363.                                                         'keyboard': keyboard, 'captcha_handler': captcha_handler})
  364.                 else:
  365.                     keyboard = create_dela(response)
  366.                     vk_session.method('messages.send',{'user_id': imid, 'message': f'У вас не хватает 💰 {paper - excoins} excoins ', 'random_id': random.randint(0, 9999999999),'keyboard': keyboard, 'captcha_handler': captcha_handler})
  367.             elif response == "читать техническую документацию":
  368.                 if int(excoins) >= float(doc):
  369.                     doc = excoins - doc
  370.                     paper = paper * 1.5
  371.                     iq = iq + 1
  372.                     keyboard = create_dela(response)
  373.                     vk_session.method('messages.send', {'user_id': imid, 'message': f'Вы прочитали техническую документацию, может быть, не до конца всё поняли, но определённая польза всё же была \n +1 IQ, теперь у вас {iq}',
  374.                                                         'random_id': random.randint(0, 9999999999),
  375.                                                         'keyboard': keyboard, 'captcha_handler': captcha_handler})
  376.                 else:
  377.                     keyboard = create_dela(response)
  378.                     vk_session.method('messages.send',
  379.                                       {'user_id': imid, 'message': f'У вас не хватает 💰 {doc - excoins} excoins',
  380.                                        'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,
  381.                                        'captcha_handler': captcha_handler})
  382.             elif response == "практиковаться в программировании":
  383.                 if iq >= 50:
  384.                     if int(excoins) >= float(prog):
  385.                         excoins = excoins - doc
  386.                         doc = doc * 1.5
  387.                         iq = iq + 3
  388.                         keyboard = create_dela(response)
  389.                         vk_session.method('messages.send', {'user_id': imid,
  390.                                                             'message': f'Вы попрактиковались в программировании и написали не сложную программку \n +3 IQ, теперь у вас {iq}',
  391.                                                             'random_id': random.randint(0, 9999999999),
  392.                                                              'keyboard': keyboard, 'captcha_handler': captcha_handler})
  393.                     else:
  394.                         keyboard = create_dela(response)
  395.                         vk_session.method('messages.send',{'user_id': imid, 'message': f'У вас не хватает 💰 {doc - excoins} excoins ',
  396.                                                            'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,
  397.                                                            'captcha_handler': captcha_handler})
  398.                 else:
  399.                     keyboard = create_dela(response)
  400.                     vk_session.method('messages.send',
  401.                                       {'user_id': imid, 'message': f'Вы ещё не достаточно умны чтобы программировать нехваатет {50-iq}IQ',
  402.                                        'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,
  403.                                        'captcha_handler': captcha_handler})
  404.             elif response == "практиковаться в программировании":
  405.                 if iq >= 150:
  406.                     if int(excoins) >= float(sprog):
  407.                         excoins = excoins - sprog
  408.                         sprog = sprog * 1.5
  409.                         iq = iq + 7
  410.                         keyboard = create_dela(response)
  411.                         vk_session.method('messages.send', {'user_id': imid,
  412.                                                             'message': f'Вы попрактиковались в программировании и написали не сложную программу \n +7 IQ, теперь у вас {iq}',
  413.                                                             'random_id': random.randint(0, 9999999999),
  414.                                                              'keyboard': keyboard, 'captcha_handler': captcha_handler})
  415.                     else:
  416.                         keyboard = create_dela(response)
  417.                         vk_session.method('messages.send',{'user_id': imid, 'message': f'У вас не хватает {sprog - excoins} денег',
  418.                                                            'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,
  419.                                                            'captcha_handler': captcha_handler})
  420.                 else:
  421.                     keyboard = create_dela(response)
  422.                     vk_session.method('messages.send',
  423.                                       {'user_id': imid, 'message': f'Вы ещё не достаточно умны чтобы писать сложные программы нехваатет {150-iq}IQ',
  424.                                        'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,
  425.                                        'captcha_handler': captcha_handler})
  426.  
  427.  
  428.  
  429.             elif response == "работать":
  430.                 gg = 0
  431.                 if timeend != 0:
  432.                     ep = datetime(1970,1,1,0,0,0)
  433.                     timegagh = (datetime.utcnow()- ep).total_seconds()
  434.                     gg = timegagh - timeend
  435.                 if jobn == 1:
  436.                     if gg >= 60 and timeend != 0:
  437.                         keyboard = create_keyboard(response)
  438.                         excoins = int(excoins)+1
  439.                         vk_session.method('messages.send', {'user_id': imid, 'message': "+1 excoin\nЧтобы вернуться нажмите Я", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  440.                         timeend = 0
  441.                     elif gg < 60 and timeend != 0:
  442.                         keyboard = create_keyboard(response)
  443.                         endf = round(60 - gg)
  444.                         endf = int(endf)
  445.                         if endf / 60 < 1:
  446.                             mf = 0
  447.                         else:
  448.                             mf = endf / 60
  449.                         vk_session.method('messages.send', {'user_id': imid,
  450.                                                             'message': f"Вы еще не доработали, осталось {mf} минут {endf % 60} секунд",
  451.                                                             'random_id': random.randint(0, 9999999999),
  452.                                                             'keyboard': keyboard, 'captcha_handler': captcha_handler})
  453.                     elif timeend == 0:
  454.                         keyboard = create_keyboard(response)
  455.                         vk_session.method('messages.send', {'user_id': imid, 'message': "Вы начали работать уборщиком, это займет 1 минуту. \nВажно, чтобы получить зарплату через 1 или более минуту сного нажмите Работать", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  456.                         ep = datetime(1970,1,1,0,0,0)
  457.                         timeend = round((datetime.utcnow()- ep).total_seconds())
  458.                 elif jobn == 2:
  459.                     if gg >= 90 and timeend != 0:
  460.                         keyboard = create_keyboard(response)
  461.                         excoins = int(excoins)+5
  462.                         vk_session.method('messages.send', {'user_id': imid, 'message': "+3 excoin\nЧтобы вернуться нажмите Я", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  463.                         timeend = 0
  464.                     elif gg < 90 and timeend != 0:
  465.                         keyboard = create_keyboard(response)
  466.                         endf = round(90 - gg)
  467.                         if endf/60 < 1:
  468.                             mf = 0
  469.                         else:
  470.                             mf =  endf/60
  471.                         vk_session.method('messages.send', {'user_id': imid, 'message': f"Вы еще не доработали, осталось {mf} минут {endf%60} секунд"  , 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  472.                     elif timeend == 0:
  473.                         keyboard = create_keyboard(response)
  474.                         vk_session.method('messages.send', {'user_id': imid, 'message': f"Вы начали работать Дворником, это займет 1.5 минуты. \nВажно, чтобы получить зарплату через 1.5 или более минут ещё раз нажмите Работать", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  475.                         ep = datetime(1970,1,1,0,0,0)
  476.                         timeend = round((datetime.utcnow()- ep).total_seconds())
  477.                 elif jobn == 3:
  478.                     timek = 120
  479.                     if gg >= timek and timeend != 0:
  480.                         keyboard = create_keyboard(response)
  481.                         excoins = int(excoins)+8
  482.                         vk_session.method('messages.send', {'user_id': imid, 'message': "+5 excoin\nЧтобы вернуться нажмите Я", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  483.                         timeend = 0
  484.                     elif gg < timek and timeend != 0:
  485.                         keyboard = create_keyboard(response)
  486.                         endf = round(timek - gg)
  487.                         if endf / 60 < 1:
  488.                             mf = 0
  489.                         else:
  490.                             mf = endf / 60
  491.                         vk_session.method('messages.send', {'user_id': imid,
  492.                                                             'message': f"Вы еще не доработали, осталось {mf} минут {endf % 60} секунд",
  493.                                                             'random_id': random.randint(0, 9999999999),
  494.                                                             'keyboard': keyboard, 'captcha_handler': captcha_handler})
  495.                     elif timeend == 0:
  496.                         keyboard = create_keyboard(response)
  497.                         vk_session.method('messages.send', {'user_id': imid, 'message': f"Вы начали работать Строителем, это займет {timek/60} минут. \nВажно, чтобы получить зарплату через {timek/60} или более минут ещё раз нажмите Работать", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  498.                         ep = datetime(1970,1,1,0,0,0)
  499.                         timeend = round((datetime.utcnow()- ep).total_seconds())
  500.                 elif jobn == 4:
  501.                     timek = 120
  502.                     if gg >= timek and timeend != 0:
  503.                         keyboard = create_keyboard(response)
  504.                         excoins = int(excoins)+10
  505.                         vk_session.method('messages.send', {'user_id': imid, 'message': "+20 excoin\nЧтобы вернуться нажмите Я", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  506.                         timeend = 0
  507.                     elif gg < timek and timeend != 0:
  508.                         keyboard = create_keyboard(response)
  509.                         endf = round(timek - gg)
  510.                         if endf / 60 < 1:
  511.                             mf = 0
  512.                         else:
  513.                             mf = endf / 60
  514.                         vk_session.method('messages.send', {'user_id': imid,
  515.                                                             'message': f"Вы еще не доработали, осталось {mf} минут {endf % 60} секунд",
  516.                                                             'random_id': random.randint(0, 9999999999),
  517.                                                             'keyboard': keyboard, 'captcha_handler': captcha_handler})
  518.                     elif timeend == 0:
  519.                         keyboard = create_keyboard(response)
  520.                         vk_session.method('messages.send', {'user_id': imid, 'message': f"Вы начали работать Архитектором, это займет {timek/60} минут. \nВажно, чтобы получить зарплату через {timek/60} или более минут ещё раз нажмите Работать", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  521.                         ep = datetime(1970,1,1,0,0,0)
  522.                         timeend = round((datetime.utcnow()- ep).total_seconds())
  523.                 elif jobn == 5:
  524.                     timek = 120
  525.                     if gg >= timek and timeend != 0:
  526.                         keyboard = create_keyboard(response)
  527.                         excoins = int(excoins)+20
  528.                         vk_session.method('messages.send', {'user_id': imid, 'message': "+20 excoin\nЧтобы вернуться нажмите Я", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  529.                         timeend = 0
  530.                     elif gg < timek and timeend != 0:
  531.                         keyboard = create_keyboard(response)
  532.                         endf = round(timek - gg)
  533.                         if endf / 60 < 1:
  534.                             mf = 0
  535.                         else:
  536.                             mf = endf / 60
  537.                         vk_session.method('messages.send', {'user_id': imid,
  538.                                                             'message': f"Вы еще не доработали, осталось {mf} минут {endf % 60} секунд",
  539.                                                             'random_id': random.randint(0, 9999999999),
  540.                                                             'keyboard': keyboard, 'captcha_handler': captcha_handler})
  541.                     elif timeend == 0:
  542.                         keyboard = create_keyboard(response)
  543.                         vk_session.method('messages.send', {'user_id': imid, 'message': f"Вы начали работать Спасателем, это займет {timek/60} минут. \nВажно, чтобы получить зарплату через {timek/60} или более минут ещё раз нажмите Работать", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  544.                         ep = datetime(1970,1,1,0,0,0)
  545.                         timeend = round((datetime.utcnow()- ep).total_seconds())
  546.                 elif jobn == 6:
  547.                     timek = 180
  548.                     if gg >= timek and timeend != 0:
  549.                         keyboard = create_keyboard(response)
  550.                         excoins = int(excoins)+40
  551.                         vk_session.method('messages.send', {'user_id': imid, 'message': "+40 excoin\nЧтобы вернуться нажмите Я", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  552.                         timeend = 0
  553.                     elif gg < timek and timeend != 0:
  554.                         keyboard = create_keyboard(response)
  555.                         endf = round(timek - gg)
  556.                         if endf / 60 < 1:
  557.                             mf = 0
  558.                         else:
  559.                             mf = endf / 60
  560.                         vk_session.method('messages.send', {'user_id': imid,
  561.                                                             'message': f"Вы еще не доработали, осталось {mf} минут {endf % 60} секунд",
  562.                                                             'random_id': random.randint(0, 9999999999),
  563.                                                             'keyboard': keyboard, 'captcha_handler': captcha_handler})
  564.                     elif timeend == 0:
  565.                         keyboard = create_keyboard(response)
  566.                         vk_session.method('messages.send', {'user_id': imid, 'message': f"Вы начали работать Юристом, это займет {timek/60} минут. \nВажно, чтобы получить зарплату через {timek/60} или более минут ещё раз нажмите Работать", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  567.                         ep = datetime(1970,1,1,0,0,0)
  568.                         timeend = round((datetime.utcnow()- ep).total_seconds())
  569.                 elif jobn == 7:
  570.                     timek = 240
  571.                     if gg >= timek and timeend != 0:
  572.                         keyboard = create_keyboard(response)
  573.                         excoins = int(excoins) + 50
  574.                         vk_session.method('messages.send',{'user_id': imid, 'message': "+50 excoin\nЧтобы вернуться нажмите Я",'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  575.                         timeend = 0
  576.                     elif gg < timek and timeend != 0:
  577.                         keyboard = create_keyboard(response)
  578.                         endf = round(timek - gg)
  579.                         if endf / 60 < 1:
  580.                             mf = 0
  581.                         else:
  582.                             mf = endf / 60
  583.                         vk_session.method('messages.send', {'user_id': imid,
  584.                                                             'message': f"Вы еще не доработали, осталось {mf} минут {endf % 60} секунд",
  585.                                                             'random_id': random.randint(0, 9999999999),
  586.                                                             'keyboard': keyboard, 'captcha_handler': captcha_handler})
  587.                     elif timeend == 0:
  588.                         keyboard = create_keyboard(response)
  589.                         vk_session.method('messages.send', {'user_id': imid,'message': f"Вы начали работать Дизайнером, это займет {timek / 60} минут. \nВажно, чтобы получить зарплату через {timek / 60} или более минут ещё раз нажмите Работать", 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,'captcha_handler': captcha_handler})
  590.                         ep = datetime(1970, 1, 1, 0, 0, 0)
  591.                         timeend = round((datetime.utcnow() - ep).total_seconds())
  592.                 elif jobn == 8:
  593.                     timek = 300
  594.                     if gg >= timek and timeend != 0:
  595.                         keyboard = create_keyboard(response)
  596.                         excoins = int(excoins) + 100
  597.                         vk_session.method('messages.send',{'user_id': imid, 'message': "+50 excoin\nЧтобы вернуться нажмите Я",'random_id': random.randint(0, 9999999999), 'keyboard': keyboard, 'captcha_handler': captcha_handler})
  598.                         timeend = 0
  599.                     elif gg < timek and timeend != 0:
  600.                         keyboard = create_keyboard(response)
  601.                         endf = round(timek - gg)
  602.                         if endf / 60 < 1:
  603.                             mf = 0
  604.                         else:
  605.                             mf = endf / 60
  606.                         vk_session.method('messages.send', {'user_id': imid,
  607.                                                             'message': f"Вы еще не доработали, осталось {mf} минут {endf % 60} секунд",
  608.                                                             'random_id': random.randint(0, 9999999999),
  609.                                                             'keyboard': keyboard, 'captcha_handler': captcha_handler})
  610.                     elif timeend == 0:
  611.                         keyboard = create_keyboard(response)
  612.                         vk_session.method('messages.send', {'user_id': imid,'message': f"Вы начали работать Разработчиком, это займет {timek / 60} минут. \nВажно, чтобы получить зарплату через {timek / 60} или более минут ещё раз нажмите Работать",'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,'captcha_handler': captcha_handler})
  613.                         ep = datetime(1970, 1, 1, 0, 0, 0)
  614.                         timeend = round((datetime.utcnow() - ep).total_seconds())
  615.  
  616.             elif response == "назад":
  617.                 keyboard = create_keyboard(response)
  618.                 messa = "Я," + str(nickname)
  619.                 messa = messa + "\nВаша работа: " + str(job) + " \nВаш уровень: " + str(lvl) + " \nВаш IQ: " + str(iq) + "\nВаш баланс: " + str(excoins) + "excoins"
  620.                 vk_session.method('messages.send',{'user_id': imid, 'message': messa, 'random_id': random.randint(0, 9999999999), 'keyboard': keyboard,'captcha_handler': captcha_handler})
  621.  
  622.  savedate (imid, iq, nickname, job, jobn, timeend, pazle, paper, excoins, frac, chees,doc,prog,strongprog,atack,defend,regen,vs, vkcoin)
  623.          
  624. """
  625.     Основной цикл запуска потоков для пользователей
  626. """
  627.  
  628.  
  629.  
  630. @merchant.lp_handler
  631. def payment_received(data):
  632.     """
  633.    При получении платежа будет запущена эта функция. Она может называться как угодно
  634.    :param data.to_id: Ваш ID ВКонтакте
  635.    :param data.id: ID платежа
  636.    :param data.created_at: Unix timestamp, время когда был совершён платёж
  637.    :param data.from_id: ID отправителя платежа
  638.    :param data.amount: Количество полученных VK Coin
  639.    """
  640.     user_id = data.to_id
  641.     amount = data.amount
  642.  
  643.     print('Получен платёж на сумму {amount} от {user_id}'.format(amount=amount, user_id=user_id))
  644.     row = getdate(data.from_id)
  645.     vkcoin = row['vkcoin']
  646.     vkcoin = vkcoin + int(data.amount)/1000
  647.     savedatecoin(data.from_id, vkcoin)
  648.  
  649. def traz():
  650.     while True:
  651.         merchant.longpoll_start(tx=[1])
  652.  
  653. while True:
  654.     geg = threading.Thread(target = traz)
  655.     geg.start()
  656.  
  657.  
  658.     for event in longpoll.listen():
  659.         if event.type == VkEventType.MESSAGE_NEW:
  660.             print(f'<{str(datetime.strftime(datetime.now(), "%H:%M:%S"))}> ({str(event.user_id)}) -> {str(event.text)}')
  661.             response = event.text.lower()
  662.             if event.from_user and not event.from_me:
  663.                     idid = event.user_id
  664.                     t = threading.Thread(target = mesed,name = str(idid), args = (idid, response))
  665.                     t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement