Guest User

Untitled

a guest
Feb 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.93 KB | None | 0 0
  1. from flask import Flask
  2. from flask import request
  3. from flask import jsonify
  4. from telebot import types
  5. import urllib.request as urllib2
  6. import telebot
  7. import random
  8. import time
  9. from flask_sslify import SSLify
  10. import requests
  11. import os
  12.  
  13. app = Flask(__name__)
  14.  
  15. bot = telebot.TeleBot("token")
  16.  
  17. def func1():
  18.     global a
  19.     global user
  20.     global lines
  21.     global doc
  22.     a = 1
  23.     f = open("zakazz.txt", 'r')
  24.     lines = f.readlines()
  25.     for line in lines:
  26.         if line == user + "\n":
  27.             a = user + "\n"
  28.             f.close()
  29.  
  30.  
  31. def func2():
  32.     global a
  33.     global user
  34.     global doc
  35.     f = open("zakazz.txt", 'a')
  36.     f.write(user + "\n")
  37.     f.close()
  38.  
  39.  
  40. def func3():
  41.     global a
  42.     global user
  43.     global lines
  44.     global doc
  45.     f = open("zakazz.txt", "w")
  46.     for line in lines:
  47.         if line != user + "\n":
  48.             f.write(line)
  49.     f.close()
  50.     print("OKSSS")
  51.  
  52.  
  53. @app.route('/', methods=['POST', 'GET'])
  54. def index():
  55.     global a
  56.     global user
  57.     global lines
  58.     global doc
  59.     global callback_query_id
  60.     global chat_id
  61.     if request.method == 'POST':
  62.         r = request.get_json()
  63.         if 'message' in r:
  64.             chat_id = r['message']['chat']['id']
  65.             message = r['message']['text']
  66.             user = str(r["message"]["from"]["id"])
  67.             if '/start' in message:
  68.                 print(1)
  69.                 func1()
  70.                 if a == user + "\n":
  71.                     print("OK")
  72.                 else:
  73.                     func2()
  74.                 user_markup = telebot.types.ReplyKeyboardMarkup(True, True)
  75.                 user_markup.row('πŸ€³Π£ΡΠ»ΡƒΠ³ΠΈ')
  76.                 user_markup.row('πŸ’ΈΠžΠΏΠ»Π°Ρ‚Π°', 'πŸ§žβ€β™‚ΠŸΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ°')
  77.                 bot.send_message(chat_id,
  78.                                  'Π”ΠΎΠ±Ρ€ΠΎ ΠΏΠΎΠΆΠ°Π»ΠΎΠ²Π°Ρ‚ΡŒ Π² ΠΎΡ„ΠΈΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΉ Π±ΠΎΡ‚',
  79.                                  parse_mode='markdown',
  80.                                  reply_markup=user_markup)
  81.                 key = types.InlineKeyboardMarkup(True)
  82.                 but_1 = types.InlineKeyboardButton(text='ВСст', callback_data="rtgf")
  83.                 key.add(but_1)
  84.                 bot.send_message(chat_id, '*Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ Услугу:*', parse_mode='markdown', reply_markup=key)
  85.                 return jsonify(r)
  86.             else:
  87.                 print(5)
  88.                 doc = "zakazz.txt"
  89.                 func1()
  90.                 if a == user + "\n":
  91.                     return jsonify(r)
  92.                 else:
  93.                     func2()
  94.                     bot.send_message(248953, message,
  95.                                      parse_mode='markdown')
  96.                     bot.send_message(chat_id, 'Бпасибо Π·Π° ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΠ΅ Π·Π°ΠΊΠ°Π·Π°, ΠΌΡ‹ свяТСмся с Π’Π°ΠΌΠΈ Π² блиТайшСС врСмя!',
  97.                                      parse_mode='markdown')
  98.                     return jsonify(r)
  99.  
  100.         elif 'callback_query' in r:
  101.             callback_query_id = r['callback_query']['message']['chat']['id']
  102.             data = r['callback_query']['data']
  103.             user = str(r["callback_query"]["from"]["id"])
  104.             if "rtgf" in data:
  105.                 print(7)
  106.                 func1()
  107.                 if a == user + "\n":
  108.                     func3()
  109.                     bot.send_message(callback_query_id, "*Π’Ρ‹ приступили ΠΊ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ Π·Π°ΠΊΠ°Π·Π°*", parse_mode='markdown')
  110.                     bot.send_message(callback_query_id, "Услуга - Π’Π•Π‘Π’", parse_mode='markdown')
  111.                     bot.send_message(callback_query_id,
  112.                                      "ΠžΡ‚ΠΏΡ€Π°Π²ΡŒΡ‚Π΅ Π±ΠΎΡ‚Ρƒ сообщСниС, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅:\nΠ”Π΅Ρ‚Π°Π»ΠΈ Π·Π°ΠΊΠ°Π·Π°",
  113.                                      parse_mode='markdown')
  114.                     return jsonify(r)
  115.                 else:
  116.                     return jsonify(r)
  117.  
  118.  
  119. if __name__ == '__main__':
  120.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment