Carson1

Untitled

Dec 2nd, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.26 KB | None | 0 0
  1. import telethon
  2. from telethon import TelegramClient, sync, functions
  3. from telethon.tl.functions.messages import GetHistoryRequest
  4. from telethon.tl.functions.channels import JoinChannelRequest
  5. import gspread
  6. from oauth2client.service_account import ServiceAccountCredentials
  7. import socks
  8.  
  9. import glob
  10. import time
  11. import sys
  12. import random
  13.  
  14. class Channel:
  15.     def __init__(self, channel_name, begining, ending):
  16.         self.channel_name = channel_name
  17.         self.begining = begining
  18.         self.ending = ending
  19.         self.last_message_id = None
  20.  
  21. def find_new_post_id(channel, session_name):
  22.     tg_client = TelegramClient(session_name, api_id, api_hash)
  23.     tg_client.start()
  24.     tg_client(JoinChannelRequest(channel.channel_name))
  25.     entity = tg_client.get_entity(channel.channel_name)
  26.     peer = telethon.utils.get_input_peer(entity)
  27.     posts = tg_client(GetHistoryRequest(
  28.         peer=entity,
  29.         limit=1,
  30.         offset_date=None,
  31.         offset_id=0,
  32.         max_id=0,
  33.         min_id=0,
  34.         add_offset=0,
  35.         hash=0))
  36.     tg_client.disconnect()
  37.     if channel.last_message_id != posts.messages[0].id:
  38.         post_id = posts.messages[0].id
  39.         channel.last_message_id = posts.messages[0].id
  40.  
  41.         return post_id
  42.  
  43.  
  44.  
  45. scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
  46. creds = ServiceAccountCredentials.from_json_keyfile_name("CHeatproject-890ddda2e266.json", scope)
  47. client = gspread.authorize(creds)
  48.  
  49. sheet = client.open("cheat").sheet1
  50.  
  51. api_id = open('app_id_and_hash.dat').read().splitlines()[0]
  52. api_hash = open('app_id_and_hash.dat').read().splitlines()[1]
  53.  
  54. channels = {}
  55.  
  56.  
  57. for i in range(sheet.row_count):
  58.     if sheet.cell(i + 1, 1).value != '':
  59.         c = Channel(sheet.cell(i + 1, 1).value, sheet.cell(i + 1, 2).value, sheet.cell(i + 1, 3).value)
  60.         find_new_post_id(c, 'sessions/+7 985 073 64 71.session')
  61.         channels[sheet.cell(i + 1, 1).value] = c
  62.     else:
  63.         break
  64.  
  65. print("Successfully started", file=sys.stderr)
  66.  
  67. while True:
  68.     post_id = None
  69.     for i in glob.glob("sessions/*.session"):
  70.         for channel in channels.values():
  71.             post_id = find_new_post_id(channel, i)
  72.             if post_id != None:
  73.                 result = [0]
  74.                 time.sleep(30)
  75.                 for i in range(random.randint(int(channel.begining), int(channel.ending))):
  76.                     tg_client = TelegramClient(glob.glob("sessions/*.session")[i], api_id, api_hash)
  77.                     tg_client.start()
  78.                     entity = tg_client.get_entity(channel.channel_name)
  79.                     peer = telethon.utils.get_input_peer(entity)
  80.                     posts = tg_client(GetHistoryRequest(
  81.                         peer=entity,
  82.                         limit=1,
  83.                         offset_date=None,
  84.                         offset_id=0,
  85.                         max_id=0,
  86.                         min_id=0,
  87.                         add_offset=0,
  88.                         hash=0))
  89.                     result = tg_client(functions.messages.GetMessagesViewsRequest(
  90.                         peer=peer,
  91.                         id=[post_id],
  92.                         increment=True))
  93.                     tg_client.disconnect()
  94.  
  95.         time.sleep(3)
Advertisement
Add Comment
Please, Sign In to add comment