Advertisement
Okorosso

Untitled

Oct 20th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.40 KB | None | 0 0
  1. import telebot
  2. from telebot import types
  3. from random import randint
  4. import datetime
  5. import schedule
  6. import time
  7. import psycopg2
  8. import os
  9. DATABASE_URL = os.environ['DATABASE_URL']
  10.  
  11. conn = psycopg2.connect(DATABASE_URL, sslmode='require')
  12. #test
  13. #bot = telebot.TeleBot('')
  14.  
  15. # main
  16. bot = telebot.TeleBot('')
  17.  
  18. # какое-та гавно
  19. # bot = telebot.TeleBot('')
  20. print('bot started')
  21.  
  22.  
  23. def send_CW_time():
  24.     print("sended CW msg at", get_now_time())
  25.     id = bot.send_message(def_chats, "Через один час ЧВ").message_id
  26.     bot.pin_chat_message(def_chats, id, False)
  27.  
  28.  
  29. def edit_pinned_message_id(mes_id):
  30.     pinned_message_idi = 0
  31.     pinned_message_idi = mes_id
  32.     return pinned_message_idi
  33.  
  34.  
  35. roman = 374085219
  36. def_chats = -1001412560727
  37. # write_id_chat = 0
  38. pinned_message_id = 0
  39.  
  40.  
  41. def find_message_id(pined_message):
  42.     idi = str()
  43.     i = 39
  44.     while pined_message[i] != ',':
  45.         idi = idi + pined_message[i]
  46.         i += 1
  47.     return idi
  48.  
  49.  
  50. def get_now_time():
  51.     now = datetime.datetime.now()
  52.     timee = now.strftime("%H:%M")
  53.     return timee
  54.  
  55. chats = ['-1001387587541', '-1001253655452', '-1001484947987']
  56. user_trigger = "@"
  57. send_messages_trigger = '/send_message_'
  58. command_trigger_group = "/group_join"
  59. command_trigger_auction = 'Список выставленных предметов на аукцион'
  60. command_trigger_pin2 = '.пин '
  61. command_trigger_pin3 = '.Пин '
  62. command_send_message_to = 'Отправь '
  63. command_trigger_exp_to_lvl = "Раса:"
  64. grace_trigger = '🎉🎉🎉Ты получил '
  65. allow_users_to_send_messages_by_bot = str(
  66.     'Ugadai_s_3_raz Denhom Ltataspb SixPathsOfMax MaxBratunin NeverAndFear alex_actionman Solijonov_Sh')
  67. allow_ids_to_send_messages_by_bot = str("")
  68. send_pin_messages_trigger = '/send_pin_message_'
  69.  
  70. # adding_in_list(user_list)
  71. @bot.message_handler(commands=['start'])
  72. def send_welcome_message(message):
  73.     print('@' + str(message.from_user.username), '/start')
  74.     bot.reply_to(message, "pls, use /help to get more info about me")
  75.  
  76.  
  77. @bot.message_handler(commands=['ping_all'])
  78. def ping_all(message):
  79.     new_msg = ''
  80.     for i in range(len('/ping_all'), len(str(message.text))):
  81.         new_msg += str(message.text)[i]
  82.     if message.chat.id == -1001484947987:
  83.         list_of_ping = '@Ugadai_s_3_raz @MaxBratunin @Solijonov_Sh @NeverAndFear @alex_actionman @SixPathsOfMax'
  84.         bot.send_message(message.chat.id, new_msg + ' ' + list_of_ping)
  85.  
  86.  
  87. @bot.message_handler(commands=['help'])
  88. def send_welcome_message(message):
  89.     print('@' + str(message.from_user.username), '/help')
  90.     bot.reply_to(message, "I cant do anything! Kill me pls")
  91.     bot.reply_to(message, "U can find more info")
  92.  
  93.  
  94. @bot.message_handler(commands=['nowtime'])
  95. def send_welcome_message(message):
  96.     time = str(get_now_time())
  97.     print('@' + str(message.from_user.username), '/nowtime at', time)
  98.     bot.reply_to(message, time)
  99.  
  100.  
  101. @bot.message_handler(commands=['F'.lower()])
  102. def send_welcome_message(message):
  103.     time = str(get_now_time())
  104.     print('@' + str(message.from_user.username), '/f', time)
  105.     bot.send_message(message.chat.id, '/F')
  106.  
  107. # answer on /group_join
  108. @bot.message_handler(content_types=['text'])
  109. def send_messages(message):
  110.     print(message.from_user.id)
  111.     print(message.chat.id)
  112.     print(message.from_user.username)
  113.     global chat_ida
  114.     global pinned_user_message_id
  115.     global message_bot_sent_id
  116.     pined_message = message
  117.     a = str(message.text)
  118.     if message.text == 'Сала Україні' or message.text == 'Сала Украине':
  119.         print('heroi by @' + str(message.from_user.id))
  120.         bot.reply_to(message, 'Героям сала!')
  121.     if message.text == 'Бот извинись' or message.text == 'Бот, извинись':
  122.         print('Извинения', '@' + str(message.from_user.username))
  123.         sorry = str('Извините, ')
  124.         sorry = sorry + '@' + str(message.from_user.username)
  125.         bot.send_message(message.chat.id, sorry)
  126.     if message.text == 'Бот заспам Максима Кадыровича':
  127.         print('spam', str(message.from_user.username))
  128.         loh = str(message.from_user.username)
  129.         for i in range(2):
  130.             bot.send_message(message.chat.id, '@' + loh + '\n')
  131.     if message.text == 'Бот спокойной ночи' or message.text == 'Bot bb' or message.text == 'Бот, спокойной ночи':
  132.         print('@' + str(message.from_user.username), 'good night')
  133.         bot.reply_to(message, 'И тебе @' + message.from_user.username)
  134.     if message.text == 'Бот, команды' or message.text == '/commands' or str(
  135.             message.text).lower() == '/commands@Consta_bot'.lower():
  136.         print('@' + str(message.from_user.username), 'commands')
  137.         bot.reply_to(message,
  138.                      'Бот, спокойной ночи' + '\n' + '/help' + '\n' + '/start' + '\n' + "Бот принимает сообщения с выставленными предметами на аукционе и возвращает ссылки для покупки" + '\n' + '.Пин + <any>' + '\n' + 'Отправка профиля из игры форвардом - вернет сообщение с оставшимся опытом')
  139.     if message.chat.id == -1001387587541 or message.chat.id == -1001253655452 or message.chat.id == -1001484947987 or message.from_user.username == 'denhom' or message.from_user.username == 'Ugadai_s_3_raz' or message.from_user.id == 374085219 or message.from_user.username == 'Zhutkij_Tip' or message.from_user.id == 435794350 or message.chat.id == 304634959:
  140.         if (a.find(command_trigger_group) != -1) and message.chat.pinned_message != message.text and message.chat.id == -1001484947987:
  141.             print('@' + str(message.from_user.username), 'pin message', message.text)
  142.             pined_message = str(pined_message)
  143.             mess_id = find_message_id(pined_message)
  144.             bot.pin_chat_message(message.chat.id, mess_id, False)
  145.             bot.send_message(message.chat.id,
  146.                              "@Ugadai_s_3_raz @MaxBratunin @Solijonov_Sh @NeverAndFear @alex_actionman @SixPathsOfMax Народ, тут данж!")
  147.  
  148.         replacing_message = str(message.text)
  149.         send_message = 'Держи и пользуйся! \n Список выставленных предметов на аукцион. Чтобы купить предмет, перешли в @rf_telegram_bot и кликни на команду напротив нужного лота. \n'
  150.         if replacing_message.find(command_trigger_auction) != -1:
  151.             print('replace auction ', '@' + str(message.from_user.username))
  152.             into = []
  153.             intro = str(replacing_message)
  154.             for i in range(len(intro)):
  155.                 into.append(intro[i])
  156.             check = str('return')
  157.             count = 0
  158.             while (int(intro.find(check)) != -1):
  159.                 place = int(intro.find(check))
  160.                 # print(*intro)
  161.  
  162.                 if count > 0:
  163.                     place1 = place - 3 * count
  164.                 else:
  165.                     place1 = place
  166.                 for _ in range(6):
  167.                     intro = intro.replace(intro[place + _], 'Q', 1)
  168.                     del into[place1]
  169.                 into.insert(place1, 'b')
  170.                 into.insert(place1 + 1, 'u')
  171.                 into.insert(place1 + 2, 'y')
  172.                 count += 1
  173.             for l in range(105, len(into)):
  174.                 send_message = send_message + into[l]
  175.             bot.reply_to(message, send_message)
  176.         # print(message)
  177.         if a.find(command_trigger_pin2, 0, len(command_trigger_pin2)) != -1 or a.find(command_trigger_pin3, 0,
  178.                                                                                       len(command_trigger_pin3)) != -1:
  179.  
  180.             pinned_user_message_idi = message.message_id
  181.             pinned_message_id = edit_pinned_message_id(message.message_id)
  182.             pinned_user_message_id = message.message_id
  183.             chat_ida = message.chat.id
  184.             print(pinned_user_message_idi)
  185.             print('@' + str(message.from_user.username), 'pin "', message.text, '"')
  186.             bot_message = ''
  187.             for z in range(len(command_trigger_pin2), len(a)):
  188.                 if z == len(command_trigger_pin2):
  189.                     bot_message += a[z].upper()
  190.                 else:
  191.                     bot_message += a[z]
  192.             useless = str(bot.send_message(message.chat.id, bot_message).message_id)
  193.             message_bot_sent_id = useless
  194.             bot.pin_chat_message(message.chat.id, useless, False)
  195.         if message.text == 'Кинь гифку' or message.text == '/gif' or str(
  196.                 message.text).lower() == '/gif@Consta_bot'.lower():
  197.             num_of_gif = randint(1, 5)
  198.             # num_of_gif = 1
  199.             if num_of_gif == 1:
  200.                 bot.send_document(message.chat.id, 'https://media.giphy.com/media/XCm1DuH04vZ6KXIXh8/giphy.gif')
  201.             if num_of_gif == 2:
  202.                 bot.send_document(message.chat.id, 'https://media.giphy.com/media/M8zyReUTgWeitlQI1G/giphy.gif')
  203.             if num_of_gif == 3:
  204.                 bot.send_document(message.chat.id, 'https://media.giphy.com/media/kaHm4fBiIynYIkwwbD/giphy.gif')
  205.             if num_of_gif == 4:
  206.                 bot.send_document(message.chat.id, 'https://media.giphy.com/media/jTBS0JwtWAeusllqiQ/giphy.gif')
  207.             if num_of_gif == 5:
  208.                 bot.send_document(message.chat.id, 'https://media.giphy.com/media/TGLAvE48ERAJwFJMMh/giphy.gif')
  209.         msg = str(message.text)
  210.         if msg.find(command_trigger_exp_to_lvl, 0, len(command_trigger_exp_to_lvl) + 1) != -1 and message.forward_from != None:
  211.  
  212.             print(message.date,' ', message.forward_date, ' ', message.date - 60*5)
  213.             if message.forward_from.id == 577009581:
  214.                 if message.date - 60*5 <= message.forward_date:
  215.                     print('Check exp by @' + str(message.from_user.username))
  216.                     place_exp = str(message.text).find("Опыт: ") + len("Опыт: ")
  217.                     end_exp = msg.find('🏵Аден:') - 2
  218.                     exp_mid = msg.find('/', place_exp, end_exp)
  219.                     now_exp = ''
  220.                     need_exp = ''
  221.                     for i in range(place_exp, exp_mid):
  222.                         now_exp = now_exp + msg[i]
  223.                     for j in range(exp_mid + 1, end_exp + 1):
  224.                         need_exp = need_exp + msg[j]
  225.                     print(need_exp, now_exp)
  226.                     need_exp = float(need_exp)
  227.                     now_exp = float(now_exp)
  228.                     now_exp = int(now_exp)
  229.                     exp = int(need_exp - now_exp)
  230.                     person = "@" + str(message.from_user.username)
  231.  
  232.                     exp = str(exp)
  233.                     exp = exp[::-1]
  234.                     exp2 = ''
  235.                     print(exp)
  236.                     _ = 0
  237.                     while _ < len(exp):
  238.                         ii = _
  239.                         while ii < _ + 3 and ii != len(exp):
  240.                             exp2 = exp2 + exp[ii]
  241.                             ii += 1
  242.                         exp2 = exp2 + ' '
  243.                         _ += 3
  244.                     exp2 = exp2[::-1]
  245.                     print(exp2)
  246.  
  247.                     msg_text = person + ' Тебе осталось' + str(exp2) + " 🌕опыта"
  248.                     bot.delete_message(message.chat.id, message.message_id)
  249.                     bot.send_message(message.chat.id, msg_text)
  250.                 else:
  251.                     bot.reply_to(message, 'Профиль не должен быть старше более 5 мин')
  252.         if message.text.find(grace_trigger) != -1 and message.forward_from != None:
  253.             if message.forward_from.id == 577009581:
  254.                 bot.reply_to(message, 'Грац!')
  255.         if message.text.find(send_messages_trigger, 0, len(send_messages_trigger)) != -1:
  256.             pos = len(send_messages_trigger)
  257.             text = message.text
  258.             send_text = text[pos+2::+1]
  259.             print(*send_text, '\n', *text, '\n', text[pos])
  260.             print(chats[2])
  261.             if text[pos] == '1':
  262.                 bot.send_message(chats[0], send_text)
  263.             if text[pos] == '2':
  264.                 bot.send_message(chats[1], send_text)
  265.             if text[pos] == '3' and message.from_user.id == 374085219:
  266.                 bot.send_message(chats[2], send_text)
  267.         if message.text.find(send_pin_messages_trigger, 0, len(send_messages_trigger)) != -1:
  268.             pos = len(send_pin_messages_trigger)
  269.             text = message.text
  270.             send_text = text[pos + 2::+1]
  271.             if text[pos] == '1':
  272.                 a = bot.send_message(chats[0], send_text).message_id
  273.                 bot.pin_chat_message(chats[0], a)
  274.             if text[pos] == '2':
  275.                 a = bot.send_message(chats[1], send_text).message_id
  276.                 bot.pin_chat_message(chats[1], a)
  277.             if text[pos] == '3' and message.from_user.id == 374085219:
  278.                 a = bot.send_message(chats[2], send_text).message_id
  279.                 bot.pin_chat_message(chats[2], a)
  280.     else:
  281.         bot.reply_to(message,
  282.                      'У Вас недостаточно прав, обратитесь к @ugadai_s_3_raz или отправляйте сообщения в чаты АМг и АМГнг')
  283.         print('fckn pidor @{} want to use bot'.format(str(message.from_user.username)))
  284.         bot.send_message(374085219,
  285.                          '@{0} рвется юзать бота {1} UTC +0 в чате {2} "{3}" \n "{4}"'.format(str(message.from_user.username),
  286.                                                                                      time.strftime('%H:%M:%S'),
  287.                                                                                      message.chat.id,
  288.                                                                                      message.chat.title, message.text))
  289.  
  290.  
  291. # new chat member
  292. @bot.message_handler(content_types=['new_chat_members'])
  293. def greeting(message):
  294.     bot.reply_to(message, "Приветствую, путник, проверь, стоит ли у тебя этот стикер пак?")
  295.     bot.send_message(message.chat.id, "https://t.me/addstickers/BellatoOneLove")
  296.     bot.send_sticker(message.chat.id, 'CAADAgADHQADYxZMFqbW_Sujed_7FgQ')
  297.  
  298.  
  299. # @bot.message_handler(commands = ['help', 'start'])
  300. # def answer_to_command(message):
  301. @bot.edited_message_handler(content_types=['text'])
  302. def edit_message(message):
  303.     print('someone edit msg', '@' + str(message.from_user.username))
  304.     edited_message = message.text
  305.     # print('message.message_id', message.message_id, 'pinned_user_message_id', pinned_user_message_id)
  306.  
  307.     if str(message.text).find(command_trigger_pin3, 0, len(command_trigger_pin3)) != -1 or str(message.text).find(
  308.             command_trigger_pin2, 0,
  309.             len(command_trigger_pin2)) != -1:
  310.         new_text = ''
  311.         got_message = str(message.text)
  312.         for i in range(4, len(got_message)):
  313.             new_text = new_text + got_message[i]
  314.         bot.edit_message_text(new_text, chat_ida, message_bot_sent_id)
  315.  
  316.  
  317. # schedule.every().day.at("8:00").do(send_CW_time)
  318. # schedule.every().day.at("13:00").do(send_CW_time)
  319. # schedule.every().day.at("18:00").do(send_CW_time)
  320.  
  321.  
  322. bot.polling(none_stop=True, interval=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement