Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.68 KB | None | 0 0
  1. from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, RegexHandler, Handler
  2. import psycopg2 as sql
  3. import telegram
  4. #import os
  5. ############################################################ Инициализация
  6. up = Updater("763589555:AAELoW39YwQFEGHVX8Uk1aBxhSIsE5Q2SvQ")
  7. dp = up.dispatcher
  8. conn=sql.connect(host="ec2-54-247-82-210.eu-west-1.compute.amazonaws.com",
  9.                  dbname="d4m8tmi7uq08i",user="xsbnkpmygiimfd",
  10.                  password="fcab0544cc54a0f3af9d75c339ef1adac60f41716454fabca95853c331e02614")
  11. cur=conn.cursor()
  12. ############################################################
  13. #ID
  14. conf=-367886782
  15. my=61174279
  16. logs=-1001354716839
  17. bot_id=up.bot.id
  18.  
  19.  
  20. def check_id(id):## Пополнение базы user_data2
  21.     cur.execute("SELECT id from user_data2;")
  22.     datat=cur.fetchall()
  23.     if (id,) not in datat:
  24.         cur.execute("INSERT into user_data2 VALUES({0});".format(id))
  25.         conn.commit()
  26.  
  27. def add_ban(id,text): #Бан пользователя
  28.     cur.execute("INSERT into ban_list VALUES({0},'{1}');".format(int(id),text))
  29.     conn.commit()
  30.  
  31.  
  32. def start(bot,up): #Приветствие
  33.     up.message.reply_text("Пиши что хочешь."+
  34.                           "Я пока рубаю андертейл. Если не выкладываю - значит цензура или бессмысленное сообщение")
  35.  
  36.        
  37. def conf_callback(bot,up):# Обработка конфы
  38.     if up.message.text=="Block User":
  39.         bot.sendMessage(conf,"Введите id пользователя {}".format(up.message.from_user.name),reply_markup=force)
  40.     if up.message.reply_to_message.text=="Введите id пользователя {}".format(up.message.from_user.name):
  41.         global ban_id
  42.         ban_id=up.message.text
  43.         bot.sendMessage(conf,"Введите текст блокировки пользователя, {0}"
  44.                         .format(up.message.from_user.name),reply_markup=force)
  45.        
  46.     if up.message.reply_to_message.text=="Введите текст блокировки пользователя, {0}".format(up.message.from_user.name):
  47.         global ban_text
  48.         ban_text=up.message.text
  49.         bot.sendMessage(conf,"Пользователь с id {0} заблокирован. Текст блокировки: {1}"
  50.                         .format(ban_id,ban_text))
  51.         add_ban(ban_id,ban_text)
  52.            
  53.  
  54.    
  55.    
  56.     user_answer(bot,up)
  57.    
  58.    
  59. def user_answer(bot,up):# Ответ юзеру
  60.     if up.message.reply_to_message.from_user.id==bot_id :#Обработка ответа юзеру
  61.        #bot.forwardMessage(logs, up.message.chat.id, up.message.message_id)# Пересылка в архив logs
  62.         if up.message.text is not None: #Обработка текста
  63.             bot.sendMessage(up.message.reply_to_message.forward_from.id,up.message.text)
  64.         elif up.message.voice :#Обработка голоса
  65.             bot.sendVoice(up.message.reply_to_message.forward_from.id,up.message.voice)
  66.         elif up.message.photo :#Оработка фото
  67.             bot.sendPhoto(up.message.reply_to_message.forward_from.id,up.message.photo[0],caption=up.message.caption)
  68.    
  69.  
  70. def user_chat(bot, up):#Обработка чата с юзером
  71.     if up.message.chat.id != conf:
  72.         bot.forwardMessage(conf, up.message.chat.id, up.message.message_id) #Пересылка в конфу
  73.        #bot.forwardMessage(logs, up.message.chat.id, up.message.message_id) #Пересылка в архив logs
  74.         if ((up.message.forward_from is not None)or(up.message.forward_from_chat is not None)): #проверка на наличие forward            
  75.             bot.sendMessage(conf,"^Sender: @{}".format(up.message.from_user.username)) # Пересылка username отправителя в конфу
  76.           #bot.sendMessage(logs,"^Sender: @{}".format(up.message.from_user.username)) #Пересылка username отправителя в архив logs
  77.         check_id(up.message.chat.id)  
  78.    
  79.    
  80.    
  81.    
  82.                          
  83.                          
  84.                          
  85.                          
  86. def admin(bot,up):#admin панель
  87.     bot.sendMessage(up.message.chat.id,"Доступ к панели администратора получен {}"
  88.                     .format(up.message.from_user.name),reply_markup=admin_panel)
  89.     #cur.execute("SELECT id from user_data2;")
  90.     #datat=cur.fetchall()
  91.     #test=str(datat)
  92.     #up.message.reply_text("Admin panel beta test")
  93.     #bot.sendMessage(conf,"Admin alert @"+str(up.message.chat.username))
  94.     #if up.message.chat.id==conf:
  95.      #   bot.sendMessage(conf,test)
  96.  
  97.    
  98.  
  99.  
  100. ############################################### Клавиатуры
  101. keyb=[["Block User","button 2"],["button 3","button 4"]] #Custom keyboard
  102. admin_panel=telegram.ReplyKeyboardMarkup(keyb,resize_keyboard=True,one_time_keyboard=True,selective=True)
  103. force=telegram.ForceReply(selective=True) #force reply_markup  
  104. remove=telegram.ReplyKeyboardRemove
  105. ban_text=""
  106. ban_id=""
  107.        
  108.        
  109.      
  110.  
  111. ################################################ Инициализация      
  112. start = CommandHandler("start", start)
  113. admin = CommandHandler("admin",admin)
  114. conf_handler=MessageHandler(Filters.chat(conf),conf_callback)
  115. user = MessageHandler(Filters.all, user_chat)
  116. dp.add_handler(admin)
  117. dp.add_handler(conf_handler)
  118. dp.add_handler(start)
  119. dp.add_handler(user)
  120. a = up.start_polling()
  121. #webhook settings
  122. #PORT = int(os.environ.get('PORT', '5000'))
  123. #TOKEN="721715826:AAHM8yvAY2oh44IEYMi-a5Kw4ooULWxIS3I"
  124. #up.start_webhook(listen='0.0.0.0', port=PORT, url_path=TOKEN)
  125. #up.bot.set_webhook("https://confession-bot-py.herokuapp.com/721715826:AAHM8yvAY2oh44IEYMi-a5Kw4ooULWxIS3I")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement