Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, RegexHandler, Handler
- import psycopg2 as sql
- import telegram
- #import os
- ############################################################ Инициализация
- up = Updater("763589555:AAELoW39YwQFEGHVX8Uk1aBxhSIsE5Q2SvQ")
- dp = up.dispatcher
- conn=sql.connect(host="ec2-54-247-82-210.eu-west-1.compute.amazonaws.com",
- dbname="d4m8tmi7uq08i",user="xsbnkpmygiimfd",
- password="fcab0544cc54a0f3af9d75c339ef1adac60f41716454fabca95853c331e02614")
- cur=conn.cursor()
- ############################################################
- #ID
- conf=-367886782
- my=61174279
- logs=-1001354716839
- bot_id=up.bot.id
- def check_id(id):## Пополнение базы user_data2
- cur.execute("SELECT id from user_data2;")
- datat=cur.fetchall()
- if (id,) not in datat:
- cur.execute("INSERT into user_data2 VALUES({0});".format(id))
- conn.commit()
- def add_ban(id,text): #Бан пользователя
- cur.execute("INSERT into ban_list VALUES({0},'{1}');".format(int(id),text))
- conn.commit()
- def start(bot,up): #Приветствие
- up.message.reply_text("Пиши что хочешь."+
- "Я пока рубаю андертейл. Если не выкладываю - значит цензура или бессмысленное сообщение")
- def conf_callback(bot,up):# Обработка конфы
- if up.message.text=="Block User":
- bot.sendMessage(conf,"Введите id пользователя {}".format(up.message.from_user.name),reply_markup=force)
- if up.message.reply_to_message.text=="Введите id пользователя {}".format(up.message.from_user.name):
- global ban_id
- ban_id=up.message.text
- bot.sendMessage(conf,"Введите текст блокировки пользователя, {0}"
- .format(up.message.from_user.name),reply_markup=force)
- if up.message.reply_to_message.text=="Введите текст блокировки пользователя, {0}".format(up.message.from_user.name):
- global ban_text
- ban_text=up.message.text
- bot.sendMessage(conf,"Пользователь с id {0} заблокирован. Текст блокировки: {1}"
- .format(ban_id,ban_text))
- add_ban(ban_id,ban_text)
- user_answer(bot,up)
- def user_answer(bot,up):# Ответ юзеру
- if up.message.reply_to_message.from_user.id==bot_id :#Обработка ответа юзеру
- #bot.forwardMessage(logs, up.message.chat.id, up.message.message_id)# Пересылка в архив logs
- if up.message.text is not None: #Обработка текста
- bot.sendMessage(up.message.reply_to_message.forward_from.id,up.message.text)
- elif up.message.voice :#Обработка голоса
- bot.sendVoice(up.message.reply_to_message.forward_from.id,up.message.voice)
- elif up.message.photo :#Оработка фото
- bot.sendPhoto(up.message.reply_to_message.forward_from.id,up.message.photo[0],caption=up.message.caption)
- def user_chat(bot, up):#Обработка чата с юзером
- if up.message.chat.id != conf:
- bot.forwardMessage(conf, up.message.chat.id, up.message.message_id) #Пересылка в конфу
- #bot.forwardMessage(logs, up.message.chat.id, up.message.message_id) #Пересылка в архив logs
- if ((up.message.forward_from is not None)or(up.message.forward_from_chat is not None)): #проверка на наличие forward
- bot.sendMessage(conf,"^Sender: @{}".format(up.message.from_user.username)) # Пересылка username отправителя в конфу
- #bot.sendMessage(logs,"^Sender: @{}".format(up.message.from_user.username)) #Пересылка username отправителя в архив logs
- check_id(up.message.chat.id)
- def admin(bot,up):#admin панель
- bot.sendMessage(up.message.chat.id,"Доступ к панели администратора получен {}"
- .format(up.message.from_user.name),reply_markup=admin_panel)
- #cur.execute("SELECT id from user_data2;")
- #datat=cur.fetchall()
- #test=str(datat)
- #up.message.reply_text("Admin panel beta test")
- #bot.sendMessage(conf,"Admin alert @"+str(up.message.chat.username))
- #if up.message.chat.id==conf:
- # bot.sendMessage(conf,test)
- ############################################### Клавиатуры
- keyb=[["Block User","button 2"],["button 3","button 4"]] #Custom keyboard
- admin_panel=telegram.ReplyKeyboardMarkup(keyb,resize_keyboard=True,one_time_keyboard=True,selective=True)
- force=telegram.ForceReply(selective=True) #force reply_markup
- remove=telegram.ReplyKeyboardRemove
- ban_text=""
- ban_id=""
- ################################################ Инициализация
- start = CommandHandler("start", start)
- admin = CommandHandler("admin",admin)
- conf_handler=MessageHandler(Filters.chat(conf),conf_callback)
- user = MessageHandler(Filters.all, user_chat)
- dp.add_handler(admin)
- dp.add_handler(conf_handler)
- dp.add_handler(start)
- dp.add_handler(user)
- a = up.start_polling()
- #webhook settings
- #PORT = int(os.environ.get('PORT', '5000'))
- #TOKEN="721715826:AAHM8yvAY2oh44IEYMi-a5Kw4ooULWxIS3I"
- #up.start_webhook(listen='0.0.0.0', port=PORT, url_path=TOKEN)
- #up.bot.set_webhook("https://confession-bot-py.herokuapp.com/721715826:AAHM8yvAY2oh44IEYMi-a5Kw4ooULWxIS3I")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement