Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 69.64 KB | None | 0 0
  1. bot.pyPython
  2.  
  3. # -*- coding: utf-8 -*-
  4. import telebot
  5. import requests
  6. import sqlite3 as lite
  7. import sys
  8. import logging
  9. import time
  10. import os
  11. reload(sys)
  12. import os.path
  13. sys.setdefaultencoding('utf8')
  14. from telebot import types
  15. import botan
  16. from datetime import datetime, timedelta, date, time as dt_time
  17.  
  18. subfile='/mnt/files/s_sub.txt';
  19. banfile='/mnt/files/shameban.txt'
  20. ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  21.  
  22. sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  23. adminid='ваш ид!'
  24. bd='/mnt/files/test.db'
  25. API_TOKEN = ''
  26. botan_key = ''
  27. bot = telebot.TeleBot(API_TOKEN)
  28. bot.send_message(adminid,"Я запустился" )
  29. logger = telebot.logger
  30. telebot.logger.setLevel(logging.DEBUG)
  31.  
  32.  
  33. markup = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  34. markup2 = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  35. markup3 = types.ReplyKeyboardMarkup(row_width=2,resize_keyboard=True)
  36. markup_h = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  37. markup_h.add('','','','','\xF0\x9F\x8D\x80 История','', '\xF0\x9F\x93\x9D Рассказать','\xF0\x9F\x94\x99 Назад' )
  38. markup_f = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  39. markup_f.add('','','','','\xF0\x9F\x8D\x80 Фото','', '','\xF0\x9F\x94\x99 Назад' )
  40. markup2.add('\xE2\x9D\xA4 топ 5 фото','\xE2\x9D\xA4 топ 5 историй','','', '\xF0\x9F\x93\x9D Рассказать')
  41. markup3.add('Отмена')
  42. markup_start = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  43. markup_start.add('\xF0\x9F\x8E\xA8 Фото','\xF0\x9F\x93\x9D Истории','','Отписаться','\xF0\x9F\x93\x88 Статистика')
  44. markup_start_ne = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  45. markup_start_ne.add('\xF0\x9F\x8E\xA8 Фото','\xF0\x9F\x93\x9D Истории','','Подписаться','\xF0\x9F\x93\x88 Статистика')
  46.  
  47.  
  48.  
  49.  
  50. @bot.message_handler(commands=['unsubscribe','Stop','stop','off','OFF','Off'])
  51. def send_welcome(message):
  52.      os.system('sed -i "/'+str(message.chat.id)+'/d" "/mnt/files/s_sub.txt"')
  53.      bot.send_message(message.chat.id,"Отменили подписку! (", reply_markup=markup)
  54.      botan.track(botan_key, message.chat.id, message, 'Подписка остановлена', reply_markup=markup_start_ne)
  55.      
  56.      
  57.      
  58. @bot.message_handler(commands=['subscribe'])
  59. def send_welcome(message):
  60.    
  61.    
  62.     global sub
  63.     sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  64.     if str(message.chat.id) not in sub:
  65.        
  66.          with open(subfile, 'a') as f:
  67.                    f.write(str(message.chat.id)+"\n")
  68.          sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  69.          bot.send_message(message.chat.id,"Подписка оформлена, для отключения воспользуйтесь коммандой /unsubscribe", reply_markup=markup_start)
  70.          botan.track(botan_key, message.chat.id, message, 'Подписка оформлена')
  71.          bot.send_message(adminid,"Подписка оформлена")
  72.     else:
  73.         bot.send_message(message.chat.id,"Подписка уже оформлена. для отключения воспользуйтесь коммандой /unsubscribe", reply_markup=markup_start)
  74.  
  75.        
  76. @bot.message_handler(commands=['help', 'start'])
  77. def send_welcome(message):
  78.     global sub
  79.     sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  80.    
  81.    
  82.     if str(message.chat.id) not in sub:
  83.        
  84.           bot.send_message(message.chat.id,"Добро пожаловать в мир постыдных историй! Расскажи свою  историю анонимно! \n Добавляйте фото, ставьте оценки!\n список команд: \n /photo - Случайное фото \n /story - Случайная история \n  \n  /subscribe - подписка на истории и фото!!! \n /help - помощь   \nДля отключения рекламы - добавьте фото или историю!!!  \n Для связи с админом просто напишите сообщение в чат.", reply_markup=markup_start_ne)
  85.     else:
  86.       bot.send_message(message.chat.id,"Добро пожаловать в мир постыдных историй! Расскажи свою  историю анонимно! \n Добавляйте фото, ставьте оценки!\n список команд: \n /photo - Случайное фото \n /story - Случайная история \n  \n  /subscribe - подписка на истории и фото!!! \n /help - помощь   \nДля отключения рекламы - добавьте фото или историю!!!  \n Для связи с админом просто напишите сообщение в чат.", reply_markup=markup_start)
  87.    
  88.     botan.track(botan_key, message.chat.id, message, 'Добро пожаловать!')
  89. @bot.message_handler(commands=['off', 'stop','Stop','Off','OFF'])
  90. def send_off(message):
  91.    
  92.  
  93.      os.system('sed -i "/'+str(message.chat.id)+'/d" '+subfile)
  94.      bot.send_message(message.chat.id,"Отменили подписку! (", reply_markup=markup_start_ne)
  95.      botan.track(botan_key, message.chat.id, message, 'Подписка остановлена')
  96.      
  97.    
  98.  
  99. @bot.message_handler(content_types=['photo'])
  100. def handle_docs_photo(message):
  101.    try:
  102.        global ex
  103.      
  104.        chat_id = message.chat.id
  105.        keyboard = types.InlineKeyboardMarkup(row_width=4)
  106.        if str(message.chat.id) not in ex:
  107.         file_info = bot.get_file(message.photo[len(message.photo)-1].file_id)
  108.         downloaded_file = bot.download_file(file_info.file_path)
  109.      
  110.         pa='/mnt/files/bot/'+str(file_info.file_path);
  111.         with open(pa, 'wb') as new_file:
  112.            new_file.write(downloaded_file)
  113.        
  114.        
  115.    
  116.         con=lite.connect(bd, timeout=10)
  117.         cur=con.cursor()
  118.         cur.execute('INSERT INTO photo (id, cid, text,rating,be,fu) VALUES(NULL, "'+str(message.chat.id)+'","'+pa+'","0","0","0")')
  119.         con.commit()
  120.         id=cur.lastrowid;
  121.         con.close
  122.        
  123.        
  124.         bot.reply_to(message, "Спасибо :)")
  125.      
  126.         img = open(pa, 'rb')
  127.         callback_bad = types.InlineKeyboardButton(text="Удалить", callback_data=pa)
  128.         callback_button = types.InlineKeyboardButton(text="Отстой", callback_data='bad[!!!]'+str(chat_id))
  129.         callback_ban = types.InlineKeyboardButton(text="Бан", callback_data='ban[!!!]'+str(chat_id))
  130.         callback_send_story = types.InlineKeyboardButton(text="Рассылка", callback_data='sendphoto[!!!]'+str(id))
  131.          
  132.         keyboard.add(callback_button,callback_bad,callback_send_story,callback_ban)
  133.            
  134.        
  135.         bot.send_photo(adminid, img,reply_markup=keyboard)
  136.    
  137.    except Exception as e:
  138.         bot.send_message(adminid,e )
  139.  
  140.  
  141.        
  142. @bot.callback_query_handler(func=lambda call: True)
  143. def callback_inline(call):
  144.     global ex
  145.     if call.message:
  146.         print(call.message)
  147.         if '/mnt/files/bot/photo/' in call.data:
  148.          
  149.            try:
  150.            
  151.             os.remove(call.data)
  152.             con=lite.connect(bd, timeout=10)
  153.             cur=con.cursor()
  154.             con.execute('DELETE from photo where text="'+call.data+'";')
  155.  
  156.             con.commit()
  157.             con.close
  158.             bot.answer_callback_query(callback_query_id=call.id, show_alert=False, text=" удалено:"+str(con.total_changes))
  159.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="Удалил")
  160.            
  161.            except Exception as e:
  162.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  163.         elif 'lf[!!!]' in call.data:
  164.            
  165.            try:
  166.             words = call.data.split("[!!!]")
  167.            
  168.            
  169.             con=lite.connect(bd, timeout=10)
  170.             cur=con.cursor()
  171.             cur.execute("""UPDATE photo SET rating = rating + 1  WHERE id="""+str(words[1])+"""  """)
  172.          
  173.             con.commit()
  174.             con.close
  175.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="\xF0\x9F\x98\x88")
  176.            
  177.            
  178.            
  179.            except Exception as e:
  180.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  181.         elif 'nf[!!!]' in call.data:
  182.            
  183.            try:
  184.             words = call.data.split("[!!!]")
  185.            
  186.            
  187.             con=lite.connect(bd, timeout=10)
  188.             cur=con.cursor()
  189.             cur.execute("""UPDATE photo SET be = be + 1  WHERE id="""+str(words[1])+"""  """)
  190.          
  191.             con.commit()
  192.             con.close
  193.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="\xF0\x9F\x98\x87")
  194.            
  195.            
  196.            
  197.            except Exception as e:
  198.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  199.         elif 'ff[!!!]' in call.data:
  200.            
  201.            try:
  202.             words = call.data.split("[!!!]")
  203.            
  204.            
  205.             con=lite.connect(bd, timeout=10)
  206.             cur=con.cursor()
  207.             cur.execute("""UPDATE photo SET fu = fu + 1  WHERE id="""+str(words[1])+"""  """)
  208.          
  209.             con.commit()
  210.             con.close
  211.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="\xF0\x9F\x98\xA1")
  212.            
  213.            
  214.            
  215.            except Exception as e:
  216.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  217.         elif 'ls[!!!]' in call.data:
  218.            
  219.            try:
  220.             words = call.data.split("[!!!]")
  221.            
  222.            
  223.             con=lite.connect(bd, timeout=10)
  224.             cur=con.cursor()
  225.             cur.execute("""UPDATE story SET rating = rating + 1  WHERE id="""+str(words[1])+"""  """)
  226.          
  227.             con.commit()
  228.             con.close
  229.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=call.message.text+" +\xF0\x9F\x98\x88")
  230.            
  231.            
  232.            
  233.            except Exception as e:
  234.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  235.         elif 'ns[!!!]' in call.data:
  236.            
  237.            try:
  238.             words = call.data.split("[!!!]")
  239.            
  240.            
  241.             con=lite.connect(bd, timeout=10)
  242.             cur=con.cursor()
  243.             cur.execute("""UPDATE story SET be = be + 1  WHERE id="""+str(words[1])+"""  """)
  244.          
  245.             con.commit()
  246.             con.close
  247.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=call.message.text+" +\xF0\x9F\x98\x87")
  248.            
  249.            
  250.            
  251.            except Exception as e:
  252.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  253.         elif 'fs[!!!]' in call.data:
  254.            
  255.            try:
  256.             words = call.data.split("[!!!]")
  257.            
  258.            
  259.             con=lite.connect(bd, timeout=10)
  260.             cur=con.cursor()
  261.             cur.execute("""UPDATE story SET fu = fu + 1  WHERE id="""+str(words[1])+"""  """)
  262.          
  263.             con.commit()
  264.             con.close
  265.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=call.message.text+" +\xF0\x9F\x98\xA1")
  266.            
  267.            
  268.            
  269.            except Exception as e:
  270.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  271.         elif 'story[!!!]' in call.data:
  272.          
  273.            try:
  274.             words = call.data.split("[!!!]")
  275.             con=lite.connect(bd, timeout=10)
  276.             cur=con.cursor()
  277.             con.execute('DELETE from story where id="'+words[1]+'";')
  278.  
  279.             con.commit()
  280.             con.close
  281.             bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text="Удалено:"+str(con.total_changes))
  282.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="Удалил")
  283.            except Exception as e:
  284.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  285.         elif 'bad[!!!]' in call.data:
  286.            
  287.            try:
  288.             img = open('/mnt/files/bot/bad.jpeg', 'rb')
  289.             words = call.data.split("[!!!]")
  290.             bot.send_photo(words[1], img,"", reply_markup=markup_h)
  291.          
  292.          
  293.            except Exception as e:
  294.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  295.         elif 'ban[!!!]' in call.data:
  296.            
  297.            try:
  298.             words = call.data.split("[!!!]")
  299.            
  300.            
  301.             with open(banfile, 'a') as f:
  302.                    f.write(str(words[1])+"\n")
  303.            
  304.             ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  305.             bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text="Забанили пользователя: ["+str(words[1])+"]")
  306.            except Exception as e:
  307.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  308.         elif 'sendtext[!!!]' in call.data:
  309.            i=0;
  310.            try:
  311.            
  312.             words = call.data.split("[!!!]")
  313.             con=lite.connect(bd, timeout=10)
  314.             cur=con.cursor()
  315.             cur.execute('SELECT * FROM story where id='+words[1]+' ORDER BY RANDOM() LIMIT 1')
  316.             data = cur.fetchone()
  317.          
  318.                
  319.          
  320.             con.close
  321.             sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  322.             keyboard = types.InlineKeyboardMarkup(row_width=3)
  323.             callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='ls[!!!]'+str(data[0]))
  324.             callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='ns[!!!]'+str(data[0]))
  325.             callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='fs[!!!]'+str(data[0]))  
  326.             keyboard.add(callback_shame,callback_nshame,callback_fuu)  
  327.            
  328.             for line in sub:
  329.              
  330.              try:
  331.               i=i+1;
  332.               if  (i % 10 ==0 ):
  333.                time.sleep(1)
  334.               m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]);
  335.               msg = bot.send_message(line,m, reply_markup=keyboard)  
  336.               bot.register_next_step_handler(msg, lambda m: process_rating(m,data[0],line))
  337.              
  338.              except Exception as e:
  339.              
  340.               pass
  341.              
  342.            
  343.            
  344.            
  345.            
  346.            except Exception as e:
  347.              pass
  348.         elif 'sendphoto[!!!]' in call.data:
  349.            i=0
  350.            try:
  351.            
  352.             words = call.data.split("[!!!]")
  353.             con=lite.connect(bd, timeout=10)
  354.             cur=con.cursor()
  355.             cur.execute('SELECT * FROM photo where id='+words[1]+' ORDER BY RANDOM() LIMIT 1')
  356.             data = cur.fetchone()
  357.          
  358.                
  359.                
  360.             con.close
  361.             sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  362.              
  363.             keyboard = types.InlineKeyboardMarkup(row_width=3)
  364.             callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='lf[!!!]'+str(data[0]))
  365.             callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='nf[!!!]'+str(data[0]))
  366.             callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='ff[!!!]'+str(data[0]))
  367.             keyboard.add(callback_shame,callback_nshame,callback_fuu)
  368.             for line in sub:
  369.            
  370.              try:
  371.                i=i+1
  372.                if  (i % 10 ==0 ):
  373.                  time.sleep(1)
  374.                img = open(data[2], 'rb')
  375.                m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5])
  376.                msg =bot.send_photo(line, img,'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]), reply_markup=keyboard)  
  377.                bot.register_next_step_handler(msg, lambda m: process_rating_p(m,data[0],line))
  378.              except Exception as e:
  379.                pass
  380.              
  381.            
  382.            
  383.            
  384.            
  385.            except Exception as e:
  386.              pass
  387. def process_add(message):
  388.    try:
  389.        global ex
  390.        
  391.        chat_id = message.chat.id
  392.        text = message.text
  393.  
  394.        if (text in "Отмена"):
  395.         bot.reply_to(message,"Может в следующий раз )", reply_markup=markup_h)
  396.         return
  397.        if str(message.chat.id) not in ex:
  398.         if len(text)>30 and (len(text)<1001):
  399.             text=text.replace('\"', ' ')
  400.             text=text.replace('\'', ' ')
  401.             text=text.replace('.http://', ' ')
  402.             text=text.replace('.www', ' ')
  403.             text=text.replace('.ru', ' ')
  404.             text=text.replace('.com', ' ')
  405.             text=text.replace('.org', ' ')
  406.             text=text.replace('.org', ' ')
  407.             con=lite.connect(bd, timeout=10)
  408.             cur=con.cursor()
  409.             cur.execute('INSERT INTO story (id, cid, text,rating,be,fu) VALUES(NULL, "'+str(chat_id)+'","'+text+'","0","0","0")')
  410.             con.commit()
  411.             id=cur.lastrowid;
  412.             con.close
  413.            
  414.            
  415.             bot.reply_to(message, "Спасибо :)")
  416.            
  417.             keyboard = types.InlineKeyboardMarkup(row_width=4)
  418.             callback_bad = types.InlineKeyboardButton(text="Удалить", callback_data='story[!!!]'+str(id))
  419.             callback_button = types.InlineKeyboardButton(text="Отстой", callback_data='bad[!!!]'+str(chat_id))
  420.             callback_ban = types.InlineKeyboardButton(text="Бан", callback_data='bad[!!!]'+str(chat_id))
  421.             callback_send_story = types.InlineKeyboardButton(text="Рассылка", callback_data='sendtext[!!!]'+str(id))
  422.          
  423.             keyboard.add(callback_button,callback_bad,callback_send_story,callback_ban)
  424.            
  425.             bot.send_message(adminid,"Добавил: ["+str(chat_id)+"] "+text, reply_markup=keyboard)
  426.  
  427.          
  428.         else:
  429.              bot.reply_to(message, 'История должна быть не менее 20 символов и не более 1000')
  430.    except Exception as e:
  431.           bot.send_message(adminid,e )
  432. def process_banuser(message):
  433.         try:
  434.             global ex
  435.             chat_id = message.chat.id
  436.             text = message.text
  437.             with open(banfile, 'a') as f:
  438.                    f.write(str(text)+"\n")
  439.            
  440.             ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  441.        
  442.         except Exception as e:
  443.               bot.reply_to(message,e)
  444.  
  445.              
  446. def process_rating(message,text,ch):
  447.     try:
  448.        
  449.         rating = message.text
  450.         id=rating.replace('#', '')
  451.         id=id.replace(' ', '')
  452.         id = rating.split('\n')
  453.         print str(rating)
  454.         if (unicode(rating)== '\xF0\x9F\x98\x88 стыдно'):
  455.             con=lite.connect(bd)
  456.             cur=con.cursor()
  457.             cur.execute("""UPDATE story SET rating = rating + 1  WHERE id="""+str(text)+"""  """)
  458.             botan.track(botan_key, message.chat.id, message, 'История стыдно')
  459.             con.commit()
  460.             con.close
  461.             bot.send_message(ch,'\xF0\x9F\x98\x88')
  462.            
  463.         elif (rating== '\xF0\x9F\x98\x87 бывает'):
  464.             con=lite.connect(bd, timeout=10)
  465.             cur=con.cursor()
  466.             cur.execute("""UPDATE story SET be = be + 1  WHERE id="""+str(text)+"""  """)
  467.             botan.track(botan_key, message.chat.id, message, ',История бывает')
  468.             con.commit()
  469.             con.close
  470.             bot.send_message(ch,'\xF0\x9F\x98\x87', reply_markup=markup)
  471.         elif (rating== '\xF0\x9F\x98\xA1 фу!'):
  472.             con=lite.connect(bd, timeout=10)
  473.             cur=con.cursor()
  474.             cur.execute("""UPDATE story SET fu = fu + 1  WHERE id="""+str(text)+"""  """)
  475.             botan.track(botan_key, message.chat.id, message, 'История фуу')
  476.             con.commit()
  477.             con.close
  478.             bot.send_message(ch,'\xF0\x9F\x98\xA1')
  479.     except Exception as e:
  480.             bot.send_message(adminid,e )       
  481. def process_rating_p(message,text,ch):
  482.     try:
  483.        
  484.         rating = message.text
  485.         id=rating.replace('#', '')
  486.         id=id.replace(' ', '')
  487.         id = rating.split('\n')
  488.         print str(rating)
  489.         if (unicode(rating)== '\xF0\x9F\x98\x88 стыдно'):
  490.             con=lite.connect(bd)
  491.             cur=con.cursor()
  492.             cur.execute("""UPDATE photo SET rating = rating + 1  WHERE id="""+str(text)+"""  """)
  493.             botan.track(botan_key, message.chat.id, message, 'История стыдно')
  494.             con.commit()
  495.             con.close
  496.             bot.send_message(ch,'\xF0\x9F\x98\x88')
  497.            
  498.         elif (rating== '\xF0\x9F\x98\x87 бывает'):
  499.             con=lite.connect(bd, timeout=10)
  500.             cur=con.cursor()
  501.             cur.execute("""UPDATE photo SET be = be + 1  WHERE id="""+str(text)+"""  """)
  502.             botan.track(botan_key, message.chat.id, message, ',История бывает')
  503.             con.commit()
  504.             con.close
  505.             bot.send_message(ch,'\xF0\x9F\x98\x87')
  506.         elif (rating== '\xF0\x9F\x98\xA1 фу!'):
  507.             con=lite.connect(bd, timeout=10)
  508.             cur=con.cursor()
  509.             cur.execute("""UPDATE photo SET fu = fu + 1  WHERE id="""+str(text)+"""  """)
  510.             botan.track(botan_key, message.chat.id, message, 'История фуу')
  511.             con.commit()
  512.             con.close
  513.             bot.send_message(ch,'\xF0\x9F\x98\xA1')
  514.     except Exception as e:
  515.           bot.send_message(adminid,e )     
  516. def process_send(message):
  517.         try:
  518.            con=lite.connect(bd, timeout=10)
  519.            cur=con.cursor()
  520.            cur.execute('SELECT DISTINCT cid FROM story')
  521.            for row in cur:
  522.                
  523.                img = open('/mnt/files/bot/send/'+message.text, 'rb')
  524.                bot.send_photo(row[0], img)
  525.            con.close
  526.        
  527.         except Exception as e:
  528.               bot.reply_to(message, e)# Handle all other messages with content_type 'text' (content_types defaults to ['text'])
  529. def process_say(message):
  530.         try:
  531.             words = message.text.split(",")
  532.             bot.send_message(words[0], words[1])
  533.        
  534.         except Exception as e:
  535.               bot.reply_to(message, e)# Handle all other messages with content_type 'text' (content_types defaults to ['text'])
  536. @bot.message_handler(func=lambda message: True)
  537. def echo_message(message):
  538.  
  539.  try:
  540.     global ex
  541.  
  542.     global sub
  543.     chat_id=message.chat.id
  544.    
  545.     if (str(message.chat.id) in ex):
  546.        bot.reply_to(message, """Вы попали в бан ((  Потерпите немого""")
  547.        botan.track(botan_key, message.chat.id, message, 'Сообщение из бани')
  548.    
  549.      
  550.     else:
  551.         if (message.text in "Подписаться"):
  552.          sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  553.          if str(message.chat.id) not in sub:
  554.             with open(subfile, 'a') as f:
  555.                    f.write(str(message.chat.id)+"\n")
  556.        
  557.          bot.send_message(message.chat.id,"Подписка оформлена, для отключения воспользуйтесь коммандой /unsubscribe", reply_markup=markup_start)
  558.          botan.track(botan_key, message.chat.id, message, 'Подписка оформлена')
  559.          
  560.  
  561.      
  562.         elif (message.text in "Отписаться"):
  563.          os.system('sed -i "/'+str(message.chat.id)+'/d" '+subfile)
  564.          bot.send_message(message.chat.id,"Отменили подписку! (", reply_markup=markup_start_ne)
  565.          botan.track(botan_key, message.chat.id, message, 'Подписка остановлена')
  566.         elif (message.text in '\xF0\x9F\x93\x9D Рассказать')and (len(message.text)>4):
  567.           msg = bot.reply_to(message, """Расскажите что случилось?""", reply_markup=markup3)  
  568.           bot.register_next_step_handler(msg, process_add)
  569.         elif ((message.text in "\xF0\x9F\x94\x99 Назад")  and (len(message.text)>3)):
  570.            sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  571.            if str(message.chat.id) not in sub:  
  572.             bot.send_message(chat_id, '\xF0\x9F\x91\x87',reply_markup=markup_start_ne)
  573.            else:
  574.              bot.send_message(chat_id, '\xF0\x9F\x91\x87',reply_markup=markup_start)
  575.         elif (message.text== u'Отмена')
  576.             bot.reply_to(message, """Отменили""", reply_markup=markup_h)
  577.        
  578.  
  579.        
  580.        
  581.         elif ((message.text in  '\xF0\x9F\x8D\x80 История')  or (message.text in "/story")) and (len(message.text)>4):
  582.             bot.send_chat_action(message.chat.id, 'typing')
  583.             con=lite.connect(bd, timeout=10)
  584.             cur=con.cursor()
  585.             cur.execute('SELECT * FROM story ORDER BY RANDOM() LIMIT 1')
  586.             data = cur.fetchone()
  587.             if (str(chat_id)==adminid) :
  588.               admin="\n Пользователь:"+str(data[1])
  589.             else:
  590.                  admin=""      
  591.             m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5])
  592.             keyboard = types.InlineKeyboardMarkup(row_width=3)
  593.             callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='ls[!!!]'+str(data[0]))
  594.             callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='ns[!!!]'+str(data[0]))
  595.             callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='fs[!!!]'+str(data[0]))
  596.             keyboard.add(callback_shame,callback_nshame,callback_fuu)
  597.              
  598.             if  (data[0] % 15 ==0 ):
  599.               star = types.InlineKeyboardButton(text='\xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90', url='https://telegram.me/storebot?start=yourshamebot')
  600.               keyboard.add(star)
  601.             if  (data[0] % 5 ==0 ):
  602.               start = types.InlineKeyboardButton(text='Реклама: Типичный юмор', url='http://telegram.me/tyhumor')
  603.               keyboard.add(start)
  604.             bot.send_message(chat_id,m, reply_markup=keyboard)
  605.  
  606.             con.close
  607.             botan.track(botan_key, message.chat.id, message, 'История')
  608.            
  609.            
  610.         elif (message.text in "\xF0\x9F\x93\x9D Истории"):
  611.             bot.send_message(message.chat.id,'\xF0\x9F\x91\x87', reply_markup=markup_h)
  612.         elif (message.text in "\xF0\x9F\x8E\xA8 Фото"):
  613.             bot.send_message(message.chat.id,'\xF0\x9F\x91\x87', reply_markup=markup_f)
  614.         elif ((message.text in "\xF0\x9F\x8D\x80 Фото /photo foto fotka фото")  and (len(message.text)>3)):
  615.             bot.send_chat_action(message.chat.id, 'upload_photo')
  616.             con=lite.connect(bd, timeout=10)
  617.             cur=con.cursor()
  618.             cur.execute('SELECT * FROM photo ORDER BY RANDOM() LIMIT 1')
  619.             data = cur.fetchone()
  620.            
  621.          
  622.            
  623.             con.close
  624.             if (os.path.exists(data[2])):
  625.              img = open(data[2], 'rb')
  626.              m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]);
  627.              keyboard = types.InlineKeyboardMarkup(row_width=3)
  628.              callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='lf[!!!]'+str(data[0]))
  629.              callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='nf[!!!]'+str(data[0]))
  630.              callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='ff[!!!]'+str(data[0]))
  631.              keyboard.add(callback_shame,callback_nshame,callback_fuu)
  632.              
  633.              if  (data[0] % 15 ==0 ):
  634.               star = types.InlineKeyboardButton(text='\xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90', url='https://telegram.me/storebot?start=yourshamebot')
  635.               keyboard.add(star)
  636.              if  (data[0] % 5 ==0 ):
  637.               start = types.InlineKeyboardButton(text='Реклама: Типичный юмор', url='http://telegram.me/tyhumor')
  638.               keyboard.add(start)
  639.              msg =bot.send_photo(message.chat.id, img,'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]), reply_markup=keyboard)  
  640.              bot.register_next_step_handler(msg, lambda m: process_rating_p(m,data[0],message.chat.id))
  641.            
  642.              botan.track(botan_key, message.chat.id, message, 'Фото')
  643.             else:
  644.                  con=lite.connect(bd, timeout=10)
  645.                  cur=con.cursor()
  646.                  con.execute('DELETE from photo where ID="'+str(data[0])+'";')
  647.  
  648.                  con.commit()
  649.                  con.close
  650.                  bot.send_message(adminid, "Не найдено фотка! Удалена запись: "+str(con.total_changes))
  651.                  
  652.         elif (message.text in '\xF0\x9F\x93\x88 Статистика'):
  653.             con=lite.connect(bd, timeout=10)
  654.             cur=con.cursor()
  655.             cur2=con.cursor()
  656.             cur3=con.cursor()
  657.             cur4=con.cursor()
  658.             cur5=con.cursor()
  659.             cur6=con.cursor()
  660.             cur7=con.cursor()
  661.             cur8=con.cursor()
  662.             cur9=con.cursor()
  663.             cur10=con.cursor()
  664.             cur.execute('SELECT count(id) FROM story')
  665.             cur2.execute('SELECT count(id) FROM photo')
  666.             cur3.execute('SELECT count(id) FROM story where cid='+str(chat_id))
  667.             cur4.execute('SELECT count(id) FROM photo where cid='+str(chat_id))
  668.             cur5.execute('SELECT SUM(rating) FROM photo where cid='+str(chat_id))
  669.             cur6.execute('SELECT SUM(be) FROM photo where cid='+str(chat_id))
  670.             cur7.execute('SELECT SUM(fu) FROM photo where cid='+str(chat_id))
  671.             cur8.execute('SELECT SUM(rating) FROM story where cid='+str(chat_id))
  672.             cur9.execute('SELECT SUM(fu) FROM story where cid='+str(chat_id))
  673.             cur10.execute('SELECT SUM(fu) FROM story where cid='+str(chat_id))
  674.             story = cur.fetchall()
  675.             photo = cur2.fetchall()
  676.             mstory =cur3.fetchall()
  677.             mphoto =cur4.fetchall()
  678.             mpr =cur5.fetchall()
  679.             mpb =cur6.fetchall()
  680.             mpf =cur7.fetchall()
  681.             msr =cur8.fetchall()
  682.             msb =cur9.fetchall()
  683.             msf =cur10.fetchall()
  684.             con.close; 
  685.             m="Статистика: \n Всего историй: "+str(story[0][0])+"\n Всего фото: "+ str(photo[0][0])+"\n\n Мои истории: "+ str(mstory[0][0])+'\n \xF0\x9F\x98\x88 '+str(msr[0][0])+ ' \xF0\x9F\x98\x87 '+str(msb[0][0])+' \xF0\x9F\x98\xA1 '+str(msf[0][0])+  "   \n\n Мои фото:"+str(mphoto[0][0])+'\n \xF0\x9F\x98\x88 '+str(mpr[0][0])+ ' \xF0\x9F\x98\x87 '+str(mpb[0][0])+' \xF0\x9F\x98\xA1 '+str(mpf[0][0])
  686.             bot.send_message(chat_id,m)
  687.        
  688.         elif (message.text== u'b') and(str(chat_id)==adminid) :
  689.             msg = bot.reply_to(message, """Кто идет в бан? """)  
  690.             bot.register_next_step_handler(msg, process_banuser)     
  691.        
  692.         elif (message.text== u'fixphoto') and(str(chat_id)==adminid) :
  693.             msg = bot.reply_to(message, """Начинаем фиксить """)  
  694.             con=lite.connect(bd, timeout=10)
  695.             cur=con.cursor()
  696.             cur.execute('SELECT * FROM photo ORDER BY RANDOM()')
  697.            
  698.             for row in cur:
  699.                if (not os.path.exists(str(row[2]))):
  700.                 con.execute('DELETE from photo where ID="'+str(row[0])+'";')
  701.             con.commit()
  702.             con.close
  703.             bot.send_message(adminid, "Результат: "+str(con.total_changes))
  704.             ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  705.          
  706.        
  707.        
  708.         else:
  709.            if ((unicode(message.text)!= '\xF0\x9F\x98\x87 бывает') and (unicode(message.text)!= '\xF0\x9F\x98\x88 стыдно')and (unicode(message.text)!= '\xF0\x9F\x98\xA1 фу!')):
  710.              bot.send_message(adminid,str(message.chat.id)+": " +message.text )
  711.  except Exception as e:
  712.         bot.reply_to(message, e)      
  713. bot.polling(none_stop=True, interval=0, timeout=3)
  714. 1
  715. 2
  716. 3
  717. 4
  718. 5
  719. 6
  720. 7
  721. 8
  722. 9
  723. 10
  724. 11
  725. 12
  726. 13
  727. 14
  728. 15
  729. 16
  730. 17
  731. 18
  732. 19
  733. 20
  734. 21
  735. 22
  736. 23
  737. 24
  738. 25
  739. 26
  740. 27
  741. 28
  742. 29
  743. 30
  744. 31
  745. 32
  746. 33
  747. 34
  748. 35
  749. 36
  750. 37
  751. 38
  752. 39
  753. 40
  754. 41
  755. 42
  756. 43
  757. 44
  758. 45
  759. 46
  760. 47
  761. 48
  762. 49
  763. 50
  764. 51
  765. 52
  766. 53
  767. 54
  768. 55
  769. 56
  770. 57
  771. 58
  772. 59
  773. 60
  774. 61
  775. 62
  776. 63
  777. 64
  778. 65
  779. 66
  780. 67
  781. 68
  782. 69
  783. 70
  784. 71
  785. 72
  786. 73
  787. 74
  788. 75
  789. 76
  790. 77
  791. 78
  792. 79
  793. 80
  794. 81
  795. 82
  796. 83
  797. 84
  798. 85
  799. 86
  800. 87
  801. 88
  802. 89
  803. 90
  804. 91
  805. 92
  806. 93
  807. 94
  808. 95
  809. 96
  810. 97
  811. 98
  812. 99
  813. 100
  814. 101
  815. 102
  816. 103
  817. 104
  818. 105
  819. 106
  820. 107
  821. 108
  822. 109
  823. 110
  824. 111
  825. 112
  826. 113
  827. 114
  828. 115
  829. 116
  830. 117
  831. 118
  832. 119
  833. 120
  834. 121
  835. 122
  836. 123
  837. 124
  838. 125
  839. 126
  840. 127
  841. 128
  842. 129
  843. 130
  844. 131
  845. 132
  846. 133
  847. 134
  848. 135
  849. 136
  850. 137
  851. 138
  852. 139
  853. 140
  854. 141
  855. 142
  856. 143
  857. 144
  858. 145
  859. 146
  860. 147
  861. 148
  862. 149
  863. 150
  864. 151
  865. 152
  866. 153
  867. 154
  868. 155
  869. 156
  870. 157
  871. 158
  872. 159
  873. 160
  874. 161
  875. 162
  876. 163
  877. 164
  878. 165
  879. 166
  880. 167
  881. 168
  882. 169
  883. 170
  884. 171
  885. 172
  886. 173
  887. 174
  888. 175
  889. 176
  890. 177
  891. 178
  892. 179
  893. 180
  894. 181
  895. 182
  896. 183
  897. 184
  898. 185
  899. 186
  900. 187
  901. 188
  902. 189
  903. 190
  904. 191
  905. 192
  906. 193
  907. 194
  908. 195
  909. 196
  910. 197
  911. 198
  912. 199
  913. 200
  914. 201
  915. 202
  916. 203
  917. 204
  918. 205
  919. 206
  920. 207
  921. 208
  922. 209
  923. 210
  924. 211
  925. 212
  926. 213
  927. 214
  928. 215
  929. 216
  930. 217
  931. 218
  932. 219
  933. 220
  934. 221
  935. 222
  936. 223
  937. 224
  938. 225
  939. 226
  940. 227
  941. 228
  942. 229
  943. 230
  944. 231
  945. 232
  946. 233
  947. 234
  948. 235
  949. 236
  950. 237
  951. 238
  952. 239
  953. 240
  954. 241
  955. 242
  956. 243
  957. 244
  958. 245
  959. 246
  960. 247
  961. 248
  962. 249
  963. 250
  964. 251
  965. 252
  966. 253
  967. 254
  968. 255
  969. 256
  970. 257
  971. 258
  972. 259
  973. 260
  974. 261
  975. 262
  976. 263
  977. 264
  978. 265
  979. 266
  980. 267
  981. 268
  982. 269
  983. 270
  984. 271
  985. 272
  986. 273
  987. 274
  988. 275
  989. 276
  990. 277
  991. 278
  992. 279
  993. 280
  994. 281
  995. 282
  996. 283
  997. 284
  998. 285
  999. 286
  1000. 287
  1001. 288
  1002. 289
  1003. 290
  1004. 291
  1005. 292
  1006. 293
  1007. 294
  1008. 295
  1009. 296
  1010. 297
  1011. 298
  1012. 299
  1013. 300
  1014. 301
  1015. 302
  1016. 303
  1017. 304
  1018. 305
  1019. 306
  1020. 307
  1021. 308
  1022. 309
  1023. 310
  1024. 311
  1025. 312
  1026. 313
  1027. 314
  1028. 315
  1029. 316
  1030. 317
  1031. 318
  1032. 319
  1033. 320
  1034. 321
  1035. 322
  1036. 323
  1037. 324
  1038. 325
  1039. 326
  1040. 327
  1041. 328
  1042. 329
  1043. 330
  1044. 331
  1045. 332
  1046. 333
  1047. 334
  1048. 335
  1049. 336
  1050. 337
  1051. 338
  1052. 339
  1053. 340
  1054. 341
  1055. 342
  1056. 343
  1057. 344
  1058. 345
  1059. 346
  1060. 347
  1061. 348
  1062. 349
  1063. 350
  1064. 351
  1065. 352
  1066. 353
  1067. 354
  1068. 355
  1069. 356
  1070. 357
  1071. 358
  1072. 359
  1073. 360
  1074. 361
  1075. 362
  1076. 363
  1077. 364
  1078. 365
  1079. 366
  1080. 367
  1081. 368
  1082. 369
  1083. 370
  1084. 371
  1085. 372
  1086. 373
  1087. 374
  1088. 375
  1089. 376
  1090. 377
  1091. 378
  1092. 379
  1093. 380
  1094. 381
  1095. 382
  1096. 383
  1097. 384
  1098. 385
  1099. 386
  1100. 387
  1101. 388
  1102. 389
  1103. 390
  1104. 391
  1105. 392
  1106. 393
  1107. 394
  1108. 395
  1109. 396
  1110. 397
  1111. 398
  1112. 399
  1113. 400
  1114. 401
  1115. 402
  1116. 403
  1117. 404
  1118. 405
  1119. 406
  1120. 407
  1121. 408
  1122. 409
  1123. 410
  1124. 411
  1125. 412
  1126. 413
  1127. 414
  1128. 415
  1129. 416
  1130. 417
  1131. 418
  1132. 419
  1133. 420
  1134. 421
  1135. 422
  1136. 423
  1137. 424
  1138. 425
  1139. 426
  1140. 427
  1141. 428
  1142. 429
  1143. 430
  1144. 431
  1145. 432
  1146. 433
  1147. 434
  1148. 435
  1149. 436
  1150. 437
  1151. 438
  1152. 439
  1153. 440
  1154. 441
  1155. 442
  1156. 443
  1157. 444
  1158. 445
  1159. 446
  1160. 447
  1161. 448
  1162. 449
  1163. 450
  1164. 451
  1165. 452
  1166. 453
  1167. 454
  1168. 455
  1169. 456
  1170. 457
  1171. 458
  1172. 459
  1173. 460
  1174. 461
  1175. 462
  1176. 463
  1177. 464
  1178. 465
  1179. 466
  1180. 467
  1181. 468
  1182. 469
  1183. 470
  1184. 471
  1185. 472
  1186. 473
  1187. 474
  1188. 475
  1189. 476
  1190. 477
  1191. 478
  1192. 479
  1193. 480
  1194. 481
  1195. 482
  1196. 483
  1197. 484
  1198. 485
  1199. 486
  1200. 487
  1201. 488
  1202. 489
  1203. 490
  1204. 491
  1205. 492
  1206. 493
  1207. 494
  1208. 495
  1209. 496
  1210. 497
  1211. 498
  1212. 499
  1213. 500
  1214. 501
  1215. 502
  1216. 503
  1217. 504
  1218. 505
  1219. 506
  1220. 507
  1221. 508
  1222. 509
  1223. 510
  1224. 511
  1225. 512
  1226. 513
  1227. 514
  1228. 515
  1229. 516
  1230. 517
  1231. 518
  1232. 519
  1233. 520
  1234. 521
  1235. 522
  1236. 523
  1237. 524
  1238. 525
  1239. 526
  1240. 527
  1241. 528
  1242. 529
  1243. 530
  1244. 531
  1245. 532
  1246. 533
  1247. 534
  1248. 535
  1249. 536
  1250. 537
  1251. 538
  1252. 539
  1253. 540
  1254. 541
  1255. 542
  1256. 543
  1257. 544
  1258. 545
  1259. 546
  1260. 547
  1261. 548
  1262. 549
  1263. 550
  1264. 551
  1265. 552
  1266. 553
  1267. 554
  1268. 555
  1269. 556
  1270. 557
  1271. 558
  1272. 559
  1273. 560
  1274. 561
  1275. 562
  1276. 563
  1277. 564
  1278. 565
  1279. 566
  1280. 567
  1281. 568
  1282. 569
  1283. 570
  1284. 571
  1285. 572
  1286. 573
  1287. 574
  1288. 575
  1289. 576
  1290. 577
  1291. 578
  1292. 579
  1293. 580
  1294. 581
  1295. 582
  1296. 583
  1297. 584
  1298. 585
  1299. 586
  1300. 587
  1301. 588
  1302. 589
  1303. 590
  1304. 591
  1305. 592
  1306. 593
  1307. 594
  1308. 595
  1309. 596
  1310. 597
  1311. 598
  1312. 599
  1313. 600
  1314. 601
  1315. 602
  1316. 603
  1317. 604
  1318. 605
  1319. 606
  1320. 607
  1321. 608
  1322. 609
  1323. 610
  1324. 611
  1325. 612
  1326. 613
  1327. 614
  1328. 615
  1329. 616
  1330. 617
  1331. 618
  1332. 619
  1333. 620
  1334. 621
  1335. 622
  1336. 623
  1337. 624
  1338. 625
  1339. 626
  1340. 627
  1341. 628
  1342. 629
  1343. 630
  1344. 631
  1345. 632
  1346. 633
  1347. 634
  1348. 635
  1349. 636
  1350. 637
  1351. 638
  1352. 639
  1353. 640
  1354. 641
  1355. 642
  1356. 643
  1357. 644
  1358. 645
  1359. 646
  1360. 647
  1361. 648
  1362. 649
  1363. 650
  1364. 651
  1365. 652
  1366. 653
  1367. 654
  1368. 655
  1369. 656
  1370. 657
  1371. 658
  1372. 659
  1373. 660
  1374. 661
  1375. 662
  1376. 663
  1377. 664
  1378. 665
  1379. 666
  1380. 667
  1381. 668
  1382. 669
  1383. 670
  1384. 671
  1385. 672
  1386. 673
  1387. 674
  1388. 675
  1389. 676
  1390. 677
  1391. 678
  1392. 679
  1393. 680
  1394. 681
  1395. 682
  1396. 683
  1397. 684
  1398. 685
  1399. 686
  1400. 687
  1401. 688
  1402. 689
  1403. 690
  1404. 691
  1405. 692
  1406. 693
  1407. 694
  1408. 695
  1409. 696
  1410. 697
  1411. 698
  1412. 699
  1413. 700
  1414. 701
  1415. 702
  1416. 703
  1417. 704
  1418. 705
  1419. 706
  1420. 707
  1421. 708
  1422. 709
  1423. 710
  1424. 711
  1425. # -*- coding: utf-8 -*-
  1426. import telebot
  1427. import requests
  1428. import sqlite3 as lite
  1429. import sys
  1430. import logging
  1431. import time
  1432. import os
  1433. reload(sys)
  1434. import os.path
  1435. sys.setdefaultencoding('utf8')
  1436. from telebot import types
  1437. import botan
  1438. from datetime import datetime, timedelta, date, time as dt_time
  1439.  
  1440. subfile='/mnt/files/s_sub.txt';
  1441. banfile='/mnt/files/shameban.txt'
  1442. ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  1443.  
  1444. sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1445. adminid='ваш ид!'
  1446. bd='/mnt/files/test.db'
  1447. API_TOKEN = ''
  1448. botan_key = ''
  1449. bot = telebot.TeleBot(API_TOKEN)
  1450. bot.send_message(adminid,"Я запустился" )
  1451. logger = telebot.logger
  1452. telebot.logger.setLevel(logging.DEBUG)
  1453.  
  1454.  
  1455. markup = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  1456. markup2 = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  1457. markup3 = types.ReplyKeyboardMarkup(row_width=2,resize_keyboard=True)
  1458. markup_h = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  1459. markup_h.add('','','','','\xF0\x9F\x8D\x80 История','', '\xF0\x9F\x93\x9D Рассказать','\xF0\x9F\x94\x99 Назад' )
  1460. markup_f = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  1461. markup_f.add('','','','','\xF0\x9F\x8D\x80 Фото','', '','\xF0\x9F\x94\x99 Назад' )
  1462. markup2.add('\xE2\x9D\xA4 топ 5 фото','\xE2\x9D\xA4 топ 5 историй','','', '\xF0\x9F\x93\x9D Рассказать')
  1463. markup3.add('Отмена')
  1464. markup_start = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  1465. markup_start.add('\xF0\x9F\x8E\xA8 Фото','\xF0\x9F\x93\x9D Истории','','Отписаться','\xF0\x9F\x93\x88 Статистика')
  1466. markup_start_ne = types.ReplyKeyboardMarkup(row_width=3,resize_keyboard=True)
  1467. markup_start_ne.add('\xF0\x9F\x8E\xA8 Фото','\xF0\x9F\x93\x9D Истории','','Подписаться','\xF0\x9F\x93\x88 Статистика')
  1468.  
  1469.  
  1470.  
  1471.  
  1472. @bot.message_handler(commands=['unsubscribe','Stop','stop','off','OFF','Off'])
  1473. def send_welcome(message):
  1474.      os.system('sed -i "/'+str(message.chat.id)+'/d" "/mnt/files/s_sub.txt"')
  1475.      bot.send_message(message.chat.id,"Отменили подписку! (", reply_markup=markup)
  1476.      botan.track(botan_key, message.chat.id, message, 'Подписка остановлена', reply_markup=markup_start_ne)
  1477.      
  1478.      
  1479.      
  1480. @bot.message_handler(commands=['subscribe'])
  1481. def send_welcome(message):
  1482.    
  1483.    
  1484.     global sub
  1485.     sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1486.     if str(message.chat.id) not in sub:
  1487.        
  1488.          with open(subfile, 'a') as f:
  1489.                    f.write(str(message.chat.id)+"\n")
  1490.          sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1491.          bot.send_message(message.chat.id,"Подписка оформлена, для отключения воспользуйтесь коммандой /unsubscribe", reply_markup=markup_start)
  1492.          botan.track(botan_key, message.chat.id, message, 'Подписка оформлена')
  1493.          bot.send_message(adminid,"Подписка оформлена")
  1494.     else:
  1495.         bot.send_message(message.chat.id,"Подписка уже оформлена. для отключения воспользуйтесь коммандой /unsubscribe", reply_markup=markup_start)
  1496.  
  1497.        
  1498. @bot.message_handler(commands=['help', 'start'])
  1499. def send_welcome(message):
  1500.     global sub
  1501.     sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1502.    
  1503.    
  1504.     if str(message.chat.id) not in sub:
  1505.        
  1506.           bot.send_message(message.chat.id,"Добро пожаловать в мир постыдных историй! Расскажи свою  историю анонимно! \n Добавляйте фото, ставьте оценки!\n список команд: \n /photo - Случайное фото \n /story - Случайная история \n  \n  /subscribe - подписка на истории и фото!!! \n /help - помощь   \nДля отключения рекламы - добавьте фото или историю!!!  \n Для связи с админом просто напишите сообщение в чат.", reply_markup=markup_start_ne)
  1507.     else:
  1508.       bot.send_message(message.chat.id,"Добро пожаловать в мир постыдных историй! Расскажи свою  историю анонимно! \n Добавляйте фото, ставьте оценки!\n список команд: \n /photo - Случайное фото \n /story - Случайная история \n  \n  /subscribe - подписка на истории и фото!!! \n /help - помощь   \nДля отключения рекламы - добавьте фото или историю!!!  \n Для связи с админом просто напишите сообщение в чат.", reply_markup=markup_start)
  1509.    
  1510.     botan.track(botan_key, message.chat.id, message, 'Добро пожаловать!')
  1511. @bot.message_handler(commands=['off', 'stop','Stop','Off','OFF'])
  1512. def send_off(message):
  1513.    
  1514.  
  1515.      os.system('sed -i "/'+str(message.chat.id)+'/d" '+subfile)
  1516.      bot.send_message(message.chat.id,"Отменили подписку! (", reply_markup=markup_start_ne)
  1517.      botan.track(botan_key, message.chat.id, message, 'Подписка остановлена')
  1518.      
  1519.    
  1520.  
  1521. @bot.message_handler(content_types=['photo'])
  1522. def handle_docs_photo(message):
  1523.    try:
  1524.        global ex
  1525.      
  1526.        chat_id = message.chat.id
  1527.        keyboard = types.InlineKeyboardMarkup(row_width=4)
  1528.        if str(message.chat.id) not in ex:
  1529.         file_info = bot.get_file(message.photo[len(message.photo)-1].file_id)
  1530.         downloaded_file = bot.download_file(file_info.file_path)
  1531.      
  1532.         pa='/mnt/files/bot/'+str(file_info.file_path);
  1533.         with open(pa, 'wb') as new_file:
  1534.            new_file.write(downloaded_file)
  1535.        
  1536.        
  1537.    
  1538.         con=lite.connect(bd, timeout=10)
  1539.         cur=con.cursor()
  1540.         cur.execute('INSERT INTO photo (id, cid, text,rating,be,fu) VALUES(NULL, "'+str(message.chat.id)+'","'+pa+'","0","0","0")')
  1541.         con.commit()
  1542.         id=cur.lastrowid;
  1543.         con.close
  1544.        
  1545.        
  1546.         bot.reply_to(message, "Спасибо :)")
  1547.      
  1548.         img = open(pa, 'rb')
  1549.         callback_bad = types.InlineKeyboardButton(text="Удалить", callback_data=pa)
  1550.         callback_button = types.InlineKeyboardButton(text="Отстой", callback_data='bad[!!!]'+str(chat_id))
  1551.         callback_ban = types.InlineKeyboardButton(text="Бан", callback_data='ban[!!!]'+str(chat_id))
  1552.         callback_send_story = types.InlineKeyboardButton(text="Рассылка", callback_data='sendphoto[!!!]'+str(id))
  1553.          
  1554.         keyboard.add(callback_button,callback_bad,callback_send_story,callback_ban)
  1555.            
  1556.        
  1557.         bot.send_photo(adminid, img,reply_markup=keyboard)
  1558.    
  1559.    except Exception as e:
  1560.         bot.send_message(adminid,e )
  1561.  
  1562.  
  1563.        
  1564. @bot.callback_query_handler(func=lambda call: True)
  1565. def callback_inline(call):
  1566.     global ex
  1567.     if call.message:
  1568.         print(call.message)
  1569.         if '/mnt/files/bot/photo/' in call.data:
  1570.          
  1571.            try:
  1572.            
  1573.             os.remove(call.data)
  1574.             con=lite.connect(bd, timeout=10)
  1575.             cur=con.cursor()
  1576.             con.execute('DELETE from photo where text="'+call.data+'";')
  1577.  
  1578.             con.commit()
  1579.             con.close
  1580.             bot.answer_callback_query(callback_query_id=call.id, show_alert=False, text=" удалено:"+str(con.total_changes))
  1581.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="Удалил")
  1582.            
  1583.            except Exception as e:
  1584.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1585.         elif 'lf[!!!]' in call.data:
  1586.            
  1587.            try:
  1588.             words = call.data.split("[!!!]")
  1589.            
  1590.            
  1591.             con=lite.connect(bd, timeout=10)
  1592.             cur=con.cursor()
  1593.             cur.execute("""UPDATE photo SET rating = rating + 1  WHERE id="""+str(words[1])+"""  """)
  1594.          
  1595.             con.commit()
  1596.             con.close
  1597.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="\xF0\x9F\x98\x88")
  1598.            
  1599.            
  1600.            
  1601.            except Exception as e:
  1602.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1603.         elif 'nf[!!!]' in call.data:
  1604.            
  1605.            try:
  1606.             words = call.data.split("[!!!]")
  1607.            
  1608.            
  1609.             con=lite.connect(bd, timeout=10)
  1610.             cur=con.cursor()
  1611.             cur.execute("""UPDATE photo SET be = be + 1  WHERE id="""+str(words[1])+"""  """)
  1612.          
  1613.             con.commit()
  1614.             con.close
  1615.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="\xF0\x9F\x98\x87")
  1616.            
  1617.            
  1618.            
  1619.            except Exception as e:
  1620.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1621.         elif 'ff[!!!]' in call.data:
  1622.            
  1623.            try:
  1624.             words = call.data.split("[!!!]")
  1625.            
  1626.            
  1627.             con=lite.connect(bd, timeout=10)
  1628.             cur=con.cursor()
  1629.             cur.execute("""UPDATE photo SET fu = fu + 1  WHERE id="""+str(words[1])+"""  """)
  1630.          
  1631.             con.commit()
  1632.             con.close
  1633.             bot.edit_message_caption(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="\xF0\x9F\x98\xA1")
  1634.            
  1635.            
  1636.            
  1637.            except Exception as e:
  1638.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1639.         elif 'ls[!!!]' in call.data:
  1640.            
  1641.            try:
  1642.             words = call.data.split("[!!!]")
  1643.            
  1644.            
  1645.             con=lite.connect(bd, timeout=10)
  1646.             cur=con.cursor()
  1647.             cur.execute("""UPDATE story SET rating = rating + 1  WHERE id="""+str(words[1])+"""  """)
  1648.          
  1649.             con.commit()
  1650.             con.close
  1651.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=call.message.text+" +\xF0\x9F\x98\x88")
  1652.            
  1653.            
  1654.            
  1655.            except Exception as e:
  1656.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1657.         elif 'ns[!!!]' in call.data:
  1658.            
  1659.            try:
  1660.             words = call.data.split("[!!!]")
  1661.            
  1662.            
  1663.             con=lite.connect(bd, timeout=10)
  1664.             cur=con.cursor()
  1665.             cur.execute("""UPDATE story SET be = be + 1  WHERE id="""+str(words[1])+"""  """)
  1666.          
  1667.             con.commit()
  1668.             con.close
  1669.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=call.message.text+" +\xF0\x9F\x98\x87")
  1670.            
  1671.            
  1672.            
  1673.            except Exception as e:
  1674.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1675.         elif 'fs[!!!]' in call.data:
  1676.            
  1677.            try:
  1678.             words = call.data.split("[!!!]")
  1679.            
  1680.            
  1681.             con=lite.connect(bd, timeout=10)
  1682.             cur=con.cursor()
  1683.             cur.execute("""UPDATE story SET fu = fu + 1  WHERE id="""+str(words[1])+"""  """)
  1684.          
  1685.             con.commit()
  1686.             con.close
  1687.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=call.message.text+" +\xF0\x9F\x98\xA1")
  1688.            
  1689.            
  1690.            
  1691.            except Exception as e:
  1692.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1693.         elif 'story[!!!]' in call.data:
  1694.          
  1695.            try:
  1696.             words = call.data.split("[!!!]")
  1697.             con=lite.connect(bd, timeout=10)
  1698.             cur=con.cursor()
  1699.             con.execute('DELETE from story where id="'+words[1]+'";')
  1700.  
  1701.             con.commit()
  1702.             con.close
  1703.             bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text="Удалено:"+str(con.total_changes))
  1704.             bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, caption="Удалил")
  1705.            except Exception as e:
  1706.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1707.         elif 'bad[!!!]' in call.data:
  1708.            
  1709.            try:
  1710.             img = open('/mnt/files/bot/bad.jpeg', 'rb')
  1711.             words = call.data.split("[!!!]")
  1712.             bot.send_photo(words[1], img,"", reply_markup=markup_h)
  1713.          
  1714.          
  1715.            except Exception as e:
  1716.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1717.         elif 'ban[!!!]' in call.data:
  1718.            
  1719.            try:
  1720.             words = call.data.split("[!!!]")
  1721.            
  1722.            
  1723.             with open(banfile, 'a') as f:
  1724.                    f.write(str(words[1])+"\n")
  1725.            
  1726.             ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  1727.             bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text="Забанили пользователя: ["+str(words[1])+"]")
  1728.            except Exception as e:
  1729.              bot.answer_callback_query(callback_query_id=call.id, show_alert=True, text=e)
  1730.         elif 'sendtext[!!!]' in call.data:
  1731.            i=0;
  1732.            try:
  1733.            
  1734.             words = call.data.split("[!!!]")
  1735.             con=lite.connect(bd, timeout=10)
  1736.             cur=con.cursor()
  1737.             cur.execute('SELECT * FROM story where id='+words[1]+' ORDER BY RANDOM() LIMIT 1')
  1738.             data = cur.fetchone()
  1739.          
  1740.                
  1741.          
  1742.             con.close
  1743.             sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1744.             keyboard = types.InlineKeyboardMarkup(row_width=3)
  1745.             callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='ls[!!!]'+str(data[0]))
  1746.             callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='ns[!!!]'+str(data[0]))
  1747.             callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='fs[!!!]'+str(data[0]))  
  1748.             keyboard.add(callback_shame,callback_nshame,callback_fuu)  
  1749.            
  1750.             for line in sub:
  1751.              
  1752.              try:
  1753.               i=i+1;
  1754.               if  (i % 10 ==0 ):
  1755.                time.sleep(1)
  1756.               m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]);
  1757.               msg = bot.send_message(line,m, reply_markup=keyboard)  
  1758.               bot.register_next_step_handler(msg, lambda m: process_rating(m,data[0],line))
  1759.              
  1760.              except Exception as e:
  1761.              
  1762.               pass
  1763.              
  1764.            
  1765.            
  1766.            
  1767.            
  1768.            except Exception as e:
  1769.              pass
  1770.         elif 'sendphoto[!!!]' in call.data:
  1771.            i=0
  1772.            try:
  1773.            
  1774.             words = call.data.split("[!!!]")
  1775.             con=lite.connect(bd, timeout=10)
  1776.             cur=con.cursor()
  1777.             cur.execute('SELECT * FROM photo where id='+words[1]+' ORDER BY RANDOM() LIMIT 1')
  1778.             data = cur.fetchone()
  1779.          
  1780.                
  1781.                
  1782.             con.close
  1783.             sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1784.              
  1785.             keyboard = types.InlineKeyboardMarkup(row_width=3)
  1786.             callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='lf[!!!]'+str(data[0]))
  1787.             callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='nf[!!!]'+str(data[0]))
  1788.             callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='ff[!!!]'+str(data[0]))
  1789.             keyboard.add(callback_shame,callback_nshame,callback_fuu)
  1790.             for line in sub:
  1791.            
  1792.              try:
  1793.                i=i+1
  1794.                if  (i % 10 ==0 ):
  1795.                  time.sleep(1)
  1796.                img = open(data[2], 'rb')
  1797.                m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5])
  1798.                msg =bot.send_photo(line, img,'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]), reply_markup=keyboard)  
  1799.                bot.register_next_step_handler(msg, lambda m: process_rating_p(m,data[0],line))
  1800.              except Exception as e:
  1801.                pass
  1802.              
  1803.            
  1804.            
  1805.            
  1806.            
  1807.            except Exception as e:
  1808.              pass
  1809. def process_add(message):
  1810.    try:
  1811.        global ex
  1812.        
  1813.        chat_id = message.chat.id
  1814.        text = message.text
  1815.  
  1816.        if (text in "Отмена"):
  1817.         bot.reply_to(message,"Может в следующий раз )", reply_markup=markup_h)
  1818.         return
  1819.        if str(message.chat.id) not in ex:
  1820.         if len(text)>30 and (len(text)<1001):
  1821.             text=text.replace('\"', ' ')
  1822.             text=text.replace('\'', ' ')
  1823.             text=text.replace('.http://', ' ')
  1824.             text=text.replace('.www', ' ')
  1825.             text=text.replace('.ru', ' ')
  1826.             text=text.replace('.com', ' ')
  1827.             text=text.replace('.org', ' ')
  1828.             text=text.replace('.org', ' ')
  1829.             con=lite.connect(bd, timeout=10)
  1830.             cur=con.cursor()
  1831.             cur.execute('INSERT INTO story (id, cid, text,rating,be,fu) VALUES(NULL, "'+str(chat_id)+'","'+text+'","0","0","0")')
  1832.             con.commit()
  1833.             id=cur.lastrowid;
  1834.             con.close
  1835.            
  1836.            
  1837.             bot.reply_to(message, "Спасибо :)")
  1838.            
  1839.             keyboard = types.InlineKeyboardMarkup(row_width=4)
  1840.             callback_bad = types.InlineKeyboardButton(text="Удалить", callback_data='story[!!!]'+str(id))
  1841.             callback_button = types.InlineKeyboardButton(text="Отстой", callback_data='bad[!!!]'+str(chat_id))
  1842.             callback_ban = types.InlineKeyboardButton(text="Бан", callback_data='bad[!!!]'+str(chat_id))
  1843.             callback_send_story = types.InlineKeyboardButton(text="Рассылка", callback_data='sendtext[!!!]'+str(id))
  1844.          
  1845.             keyboard.add(callback_button,callback_bad,callback_send_story,callback_ban)
  1846.            
  1847.             bot.send_message(adminid,"Добавил: ["+str(chat_id)+"] "+text, reply_markup=keyboard)
  1848.  
  1849.          
  1850.         else:
  1851.              bot.reply_to(message, 'История должна быть не менее 20 символов и не более 1000')
  1852.    except Exception as e:
  1853.           bot.send_message(adminid,e )
  1854. def process_banuser(message):
  1855.         try:
  1856.             global ex
  1857.             chat_id = message.chat.id
  1858.             text = message.text
  1859.             with open(banfile, 'a') as f:
  1860.                    f.write(str(text)+"\n")
  1861.            
  1862.             ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  1863.        
  1864.         except Exception as e:
  1865.               bot.reply_to(message,e)
  1866.  
  1867.              
  1868. def process_rating(message,text,ch):
  1869.     try:
  1870.        
  1871.         rating = message.text
  1872.         id=rating.replace('#', '')
  1873.         id=id.replace(' ', '')
  1874.         id = rating.split('\n')
  1875.         print str(rating)
  1876.         if (unicode(rating)== '\xF0\x9F\x98\x88 стыдно'):
  1877.             con=lite.connect(bd)
  1878.             cur=con.cursor()
  1879.             cur.execute("""UPDATE story SET rating = rating + 1  WHERE id="""+str(text)+"""  """)
  1880.             botan.track(botan_key, message.chat.id, message, 'История стыдно')
  1881.             con.commit()
  1882.             con.close
  1883.             bot.send_message(ch,'\xF0\x9F\x98\x88')
  1884.            
  1885.         elif (rating== '\xF0\x9F\x98\x87 бывает'):
  1886.             con=lite.connect(bd, timeout=10)
  1887.             cur=con.cursor()
  1888.             cur.execute("""UPDATE story SET be = be + 1  WHERE id="""+str(text)+"""  """)
  1889.             botan.track(botan_key, message.chat.id, message, ',История бывает')
  1890.             con.commit()
  1891.             con.close
  1892.             bot.send_message(ch,'\xF0\x9F\x98\x87', reply_markup=markup)
  1893.         elif (rating== '\xF0\x9F\x98\xA1 фу!'):
  1894.             con=lite.connect(bd, timeout=10)
  1895.             cur=con.cursor()
  1896.             cur.execute("""UPDATE story SET fu = fu + 1  WHERE id="""+str(text)+"""  """)
  1897.             botan.track(botan_key, message.chat.id, message, 'История фуу')
  1898.             con.commit()
  1899.             con.close
  1900.             bot.send_message(ch,'\xF0\x9F\x98\xA1')
  1901.     except Exception as e:
  1902.             bot.send_message(adminid,e )       
  1903. def process_rating_p(message,text,ch):
  1904.     try:
  1905.        
  1906.         rating = message.text
  1907.         id=rating.replace('#', '')
  1908.         id=id.replace(' ', '')
  1909.         id = rating.split('\n')
  1910.         print str(rating)
  1911.         if (unicode(rating)== '\xF0\x9F\x98\x88 стыдно'):
  1912.             con=lite.connect(bd)
  1913.             cur=con.cursor()
  1914.             cur.execute("""UPDATE photo SET rating = rating + 1  WHERE id="""+str(text)+"""  """)
  1915.             botan.track(botan_key, message.chat.id, message, 'История стыдно')
  1916.             con.commit()
  1917.             con.close
  1918.             bot.send_message(ch,'\xF0\x9F\x98\x88')
  1919.            
  1920.         elif (rating== '\xF0\x9F\x98\x87 бывает'):
  1921.             con=lite.connect(bd, timeout=10)
  1922.             cur=con.cursor()
  1923.             cur.execute("""UPDATE photo SET be = be + 1  WHERE id="""+str(text)+"""  """)
  1924.             botan.track(botan_key, message.chat.id, message, ',История бывает')
  1925.             con.commit()
  1926.             con.close
  1927.             bot.send_message(ch,'\xF0\x9F\x98\x87')
  1928.         elif (rating== '\xF0\x9F\x98\xA1 фу!'):
  1929.             con=lite.connect(bd, timeout=10)
  1930.             cur=con.cursor()
  1931.             cur.execute("""UPDATE photo SET fu = fu + 1  WHERE id="""+str(text)+"""  """)
  1932.             botan.track(botan_key, message.chat.id, message, 'История фуу')
  1933.             con.commit()
  1934.             con.close
  1935.             bot.send_message(ch,'\xF0\x9F\x98\xA1')
  1936.     except Exception as e:
  1937.           bot.send_message(adminid,e )     
  1938. def process_send(message):
  1939.         try:
  1940.            con=lite.connect(bd, timeout=10)
  1941.            cur=con.cursor()
  1942.            cur.execute('SELECT DISTINCT cid FROM story')
  1943.            for row in cur:
  1944.                
  1945.                img = open('/mnt/files/bot/send/'+message.text, 'rb')
  1946.                bot.send_photo(row[0], img)
  1947.            con.close
  1948.        
  1949.         except Exception as e:
  1950.               bot.reply_to(message, e)# Handle all other messages with content_type 'text' (content_types defaults to ['text'])
  1951. def process_say(message):
  1952.         try:
  1953.             words = message.text.split(",")
  1954.             bot.send_message(words[0], words[1])
  1955.        
  1956.         except Exception as e:
  1957.               bot.reply_to(message, e)# Handle all other messages with content_type 'text' (content_types defaults to ['text'])
  1958. @bot.message_handler(func=lambda message: True)
  1959. def echo_message(message):
  1960.  
  1961.  try:
  1962.     global ex
  1963.  
  1964.     global sub
  1965.     chat_id=message.chat.id
  1966.    
  1967.     if (str(message.chat.id) in ex):
  1968.        bot.reply_to(message, """Вы попали в бан ((  Потерпите немого""")
  1969.        botan.track(botan_key, message.chat.id, message, 'Сообщение из бани')
  1970.    
  1971.      
  1972.     else:
  1973.         if (message.text in "Подписаться"):
  1974.          sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1975.          if str(message.chat.id) not in sub:
  1976.             with open(subfile, 'a') as f:
  1977.                    f.write(str(message.chat.id)+"\n")
  1978.        
  1979.          bot.send_message(message.chat.id,"Подписка оформлена, для отключения воспользуйтесь коммандой /unsubscribe", reply_markup=markup_start)
  1980.          botan.track(botan_key, message.chat.id, message, 'Подписка оформлена')
  1981.          
  1982.  
  1983.      
  1984.         elif (message.text in "Отписаться"):
  1985.          os.system('sed -i "/'+str(message.chat.id)+'/d" '+subfile)
  1986.          bot.send_message(message.chat.id,"Отменили подписку! (", reply_markup=markup_start_ne)
  1987.          botan.track(botan_key, message.chat.id, message, 'Подписка остановлена')
  1988.         elif (message.text in '\xF0\x9F\x93\x9D Рассказать')and (len(message.text)>4):
  1989.           msg = bot.reply_to(message, """Расскажите что случилось?""", reply_markup=markup3)  
  1990.           bot.register_next_step_handler(msg, process_add)
  1991.         elif ((message.text in "\xF0\x9F\x94\x99 Назад")  and (len(message.text)>3)):
  1992.            sub = [line.rstrip('\n') for line in open(subfile,'rt')]
  1993.            if str(message.chat.id) not in sub:  
  1994.             bot.send_message(chat_id, '\xF0\x9F\x91\x87',reply_markup=markup_start_ne)
  1995.            else:
  1996.              bot.send_message(chat_id, '\xF0\x9F\x91\x87',reply_markup=markup_start)
  1997.         elif (message.text== u'Отмена')
  1998.             bot.reply_to(message, """Отменили""", reply_markup=markup_h)
  1999.        
  2000.  
  2001.        
  2002.        
  2003.         elif ((message.text in  '\xF0\x9F\x8D\x80 История')  or (message.text in "/story")) and (len(message.text)>4):
  2004.             bot.send_chat_action(message.chat.id, 'typing')
  2005.             con=lite.connect(bd, timeout=10)
  2006.             cur=con.cursor()
  2007.             cur.execute('SELECT * FROM story ORDER BY RANDOM() LIMIT 1')
  2008.             data = cur.fetchone()
  2009.             if (str(chat_id)==adminid) :
  2010.               admin="\n Пользователь:"+str(data[1])
  2011.             else:
  2012.                  admin=""      
  2013.             m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5])
  2014.             keyboard = types.InlineKeyboardMarkup(row_width=3)
  2015.             callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='ls[!!!]'+str(data[0]))
  2016.             callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='ns[!!!]'+str(data[0]))
  2017.             callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='fs[!!!]'+str(data[0]))
  2018.             keyboard.add(callback_shame,callback_nshame,callback_fuu)
  2019.              
  2020.             if  (data[0] % 15 ==0 ):
  2021.               star = types.InlineKeyboardButton(text='\xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90', url='https://telegram.me/storebot?start=yourshamebot')
  2022.               keyboard.add(star)
  2023.             if  (data[0] % 5 ==0 ):
  2024.               start = types.InlineKeyboardButton(text='Реклама: Типичный юмор', url='http://telegram.me/tyhumor')
  2025.               keyboard.add(start)
  2026.             bot.send_message(chat_id,m, reply_markup=keyboard)
  2027.  
  2028.             con.close
  2029.             botan.track(botan_key, message.chat.id, message, 'История')
  2030.            
  2031.            
  2032.         elif (message.text in "\xF0\x9F\x93\x9D Истории"):
  2033.             bot.send_message(message.chat.id,'\xF0\x9F\x91\x87', reply_markup=markup_h)
  2034.         elif (message.text in "\xF0\x9F\x8E\xA8 Фото"):
  2035.             bot.send_message(message.chat.id,'\xF0\x9F\x91\x87', reply_markup=markup_f)
  2036.         elif ((message.text in "\xF0\x9F\x8D\x80 Фото /photo foto fotka фото")  and (len(message.text)>3)):
  2037.             bot.send_chat_action(message.chat.id, 'upload_photo')
  2038.             con=lite.connect(bd, timeout=10)
  2039.             cur=con.cursor()
  2040.             cur.execute('SELECT * FROM photo ORDER BY RANDOM() LIMIT 1')
  2041.             data = cur.fetchone()
  2042.            
  2043.          
  2044.            
  2045.             con.close
  2046.             if (os.path.exists(data[2])):
  2047.              img = open(data[2], 'rb')
  2048.              m="#"+str(data[0])+"\n"+data[2]+"\n\n"+'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]);
  2049.              keyboard = types.InlineKeyboardMarkup(row_width=3)
  2050.              callback_shame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x88 стыдно', callback_data='lf[!!!]'+str(data[0]))
  2051.              callback_nshame = types.InlineKeyboardButton(text='\xF0\x9F\x98\x87 бывает', callback_data='nf[!!!]'+str(data[0]))
  2052.              callback_fuu = types.InlineKeyboardButton(text='\xF0\x9F\x98\xA1 фу!', callback_data='ff[!!!]'+str(data[0]))
  2053.              keyboard.add(callback_shame,callback_nshame,callback_fuu)
  2054.              
  2055.              if  (data[0] % 15 ==0 ):
  2056.               star = types.InlineKeyboardButton(text='\xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90 \xE2\xAD\x90', url='https://telegram.me/storebot?start=yourshamebot')
  2057.               keyboard.add(star)
  2058.              if  (data[0] % 5 ==0 ):
  2059.               start = types.InlineKeyboardButton(text='Реклама: Типичный юмор', url='http://telegram.me/tyhumor')
  2060.               keyboard.add(start)
  2061.              msg =bot.send_photo(message.chat.id, img,'\xF0\x9F\x98\x88 '+str(data[3])+ ' \xF0\x9F\x98\x87 '+str(data[4])+' \xF0\x9F\x98\xA1 '+str(data[5]), reply_markup=keyboard)  
  2062.              bot.register_next_step_handler(msg, lambda m: process_rating_p(m,data[0],message.chat.id))
  2063.            
  2064.              botan.track(botan_key, message.chat.id, message, 'Фото')
  2065.             else:
  2066.                  con=lite.connect(bd, timeout=10)
  2067.                  cur=con.cursor()
  2068.                  con.execute('DELETE from photo where ID="'+str(data[0])+'";')
  2069.  
  2070.                  con.commit()
  2071.                  con.close
  2072.                  bot.send_message(adminid, "Не найдено фотка! Удалена запись: "+str(con.total_changes))
  2073.                  
  2074.         elif (message.text in '\xF0\x9F\x93\x88 Статистика'):
  2075.             con=lite.connect(bd, timeout=10)
  2076.             cur=con.cursor()
  2077.             cur2=con.cursor()
  2078.             cur3=con.cursor()
  2079.             cur4=con.cursor()
  2080.             cur5=con.cursor()
  2081.             cur6=con.cursor()
  2082.             cur7=con.cursor()
  2083.             cur8=con.cursor()
  2084.             cur9=con.cursor()
  2085.             cur10=con.cursor()
  2086.             cur.execute('SELECT count(id) FROM story')
  2087.             cur2.execute('SELECT count(id) FROM photo')
  2088.             cur3.execute('SELECT count(id) FROM story where cid='+str(chat_id))
  2089.             cur4.execute('SELECT count(id) FROM photo where cid='+str(chat_id))
  2090.             cur5.execute('SELECT SUM(rating) FROM photo where cid='+str(chat_id))
  2091.             cur6.execute('SELECT SUM(be) FROM photo where cid='+str(chat_id))
  2092.             cur7.execute('SELECT SUM(fu) FROM photo where cid='+str(chat_id))
  2093.             cur8.execute('SELECT SUM(rating) FROM story where cid='+str(chat_id))
  2094.             cur9.execute('SELECT SUM(fu) FROM story where cid='+str(chat_id))
  2095.             cur10.execute('SELECT SUM(fu) FROM story where cid='+str(chat_id))
  2096.             story = cur.fetchall()
  2097.             photo = cur2.fetchall()
  2098.             mstory =cur3.fetchall()
  2099.             mphoto =cur4.fetchall()
  2100.             mpr =cur5.fetchall()
  2101.             mpb =cur6.fetchall()
  2102.             mpf =cur7.fetchall()
  2103.             msr =cur8.fetchall()
  2104.             msb =cur9.fetchall()
  2105.             msf =cur10.fetchall()
  2106.             con.close; 
  2107.             m="Статистика: \n Всего историй: "+str(story[0][0])+"\n Всего фото: "+ str(photo[0][0])+"\n\n Мои истории: "+ str(mstory[0][0])+'\n \xF0\x9F\x98\x88 '+str(msr[0][0])+ ' \xF0\x9F\x98\x87 '+str(msb[0][0])+' \xF0\x9F\x98\xA1 '+str(msf[0][0])+  "   \n\n Мои фото:"+str(mphoto[0][0])+'\n \xF0\x9F\x98\x88 '+str(mpr[0][0])+ ' \xF0\x9F\x98\x87 '+str(mpb[0][0])+' \xF0\x9F\x98\xA1 '+str(mpf[0][0])
  2108.             bot.send_message(chat_id,m)
  2109.        
  2110.         elif (message.text== u'b') and(str(chat_id)==adminid) :
  2111.             msg = bot.reply_to(message, """Кто идет в бан? """)  
  2112.             bot.register_next_step_handler(msg, process_banuser)     
  2113.        
  2114.         elif (message.text== u'fixphoto') and(str(chat_id)==adminid) :
  2115.             msg = bot.reply_to(message, """Начинаем фиксить """)  
  2116.             con=lite.connect(bd, timeout=10)
  2117.             cur=con.cursor()
  2118.             cur.execute('SELECT * FROM photo ORDER BY RANDOM()')
  2119.            
  2120.             for row in cur:
  2121.                if (not os.path.exists(str(row[2]))):
  2122.                 con.execute('DELETE from photo where ID="'+str(row[0])+'";')
  2123.             con.commit()
  2124.             con.close
  2125.             bot.send_message(adminid, "Результат: "+str(con.total_changes))
  2126.             ex = [line.rstrip('\n') for line in open(banfile,'rt')]
  2127.          
  2128.        
  2129.        
  2130.         else:
  2131.            if ((unicode(message.text)!= '\xF0\x9F\x98\x87 бывает') and (unicode(message.text)!= '\xF0\x9F\x98\x88 стыдно')and (unicode(message.text)!= '\xF0\x9F\x98\xA1 фу!')):
  2132.              bot.send_message(adminid,str(message.chat.id)+": " +message.text )
  2133.  except Exception as e:
  2134.         bot.reply_to(message, e)      
  2135. bot.polling(none_stop=True, interval=0, timeout=3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement