Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.75 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):
  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):
  28.     cur.execute("INSERT into ban_list VALUES({0});".format(id))
  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 пользователя",reply_markup=force)
  40.     if up.message.reply_to_message.text=="Введите id пользователя":
  41.         bot.sendMessage(conf,"Id={0}".format(up.message.text))    
  42.     if up.message.reply_to_message.from_user.id==bot_id :#Обработка ответа юзеру
  43.        #bot.forwardMessage(logs, up.message.chat.id, up.message.message_id)# Пересылка в архив logs
  44.         if up.message.text is not None: #Обработка текста
  45.             bot.sendMessage(up.message.reply_to_message.forward_from.id,up.message.text)
  46.         elif up.message.voice :#Обработка голоса
  47.             bot.sendVoice(up.message.reply_to_message.forward_from.id,up.message.voice)
  48.         elif up.message.photo :#Оработка фото
  49.             bot.sendPhoto(up.message.reply_to_message.forward_from.id,up.message.photo[0],caption=up.message.caption)
  50.    
  51.    
  52.    
  53.  
  54. def user_chat(bot, up):#Обработка чата с юзером
  55.     if up.message.chat.id != conf:
  56.         bot.forwardMessage(conf, up.message.chat.id, up.message.message_id) #Пересылка в конфу
  57.        #bot.forwardMessage(logs, up.message.chat.id, up.message.message_id) #Пересылка в архив logs
  58.         if ((up.message.forward_from is not None)or(up.message.forward_from_chat is not None)): #проверка на наличие forward            
  59.             bot.sendMessage(conf,"^Sender: @{}".format(up.message.from_user.username)) # Пересылка username отправителя в конфу
  60.           #bot.sendMessage(logs,"^Sender: @{}".format(up.message.from_user.username)) #Пересылка username отправителя в архив logs
  61.         check_id(up.message.chat.id)  
  62.    
  63.    
  64.    
  65.    
  66.                          
  67.                          
  68.                          
  69.                          
  70. def admin(bot,up):
  71.     bot.sendMessage(up.message.chat.id,"Доступ к панели администратора получен",reply_markup=admin_panel)
  72.     cur.execute("SELECT id from user_data2;")
  73.     datat=cur.fetchall()
  74.     test=str(datat)
  75.     up.message.reply_text("Admin panel beta test")
  76.     bot.sendMessage(conf,"Admin alert @"+str(up.message.chat.username))
  77.     if up.message.chat.id==conf:
  78.         bot.sendMessage(conf,test)
  79.  
  80.    
  81.  
  82.  
  83. ############################################### Клавиатуры
  84. keyb=[["Block User","button 2"],["button 3","button 4"]] #Custom keyboard
  85. admin_panel=telegram.ReplyKeyboardMarkup(keyb,resize_keyboard=True,one_time_keyboard=True)
  86. force=telegram.ForceReply() #force reply_markup  
  87. remove=telegram.ReplyKeyboardRemove
  88.        
  89.        
  90.      
  91.  
  92. ################################################ Инициализация      
  93. start = CommandHandler("start", start)
  94. admin = CommandHandler("admin",admin)
  95. conf_handler=MessageHandler(Filters.chat(conf),conf_callback)
  96. user = MessageHandler(Filters.all, user_chat)
  97. dp.add_handler(admin)
  98. dp.add_handler(conf_handler)
  99. dp.add_handler(start)
  100. dp.add_handler(user)
  101. a = up.start_polling()
  102. #webhook settings
  103. #PORT = int(os.environ.get('PORT', '5000'))
  104. #TOKEN="721715826:AAHM8yvAY2oh44IEYMi-a5Kw4ooULWxIS3I"
  105. #up.start_webhook(listen='0.0.0.0', port=PORT, url_path=TOKEN)
  106. #up.bot.set_webhook("https://confession-bot-py.herokuapp.com/721715826:AAHM8yvAY2oh44IEYMi-a5Kw4ooULWxIS3I")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement