async def EVENTER(event): event.original_update = event.original_update if type(event.original_update) is not UpdateShortMessage: if hasattr(event.original_update.message, 'reply_markup') and type( event.original_update.message.reply_markup ) is ReplyInlineMarkup: RQForm = MUFilter( event.original_update.message.reply_markup) if RQForm is not None: if MUFilterT(event.original_update.message.reply_markup ) is None: if RFORMER2(RQForm).find('/vc/') > 0: await event.message.click(2) else: print(num + "..rewarding\r") #ScreenMessage(Fore.GREEN+' Requesting reward') UravxBuCwNMpYWTzKhcy = 20 CompteurSUC = 0 while True: (RQCode, RQText) = RFORMER(RQForm) MFINDER = BeautifulSoup( RQText, 'html.parser') cc = MFINDER.find('div', {'class': 'g-recaptcha'}) tt = MFINDER.find('div', {'id': 'headbar'}) if RQCode == 302: print(num + "..ok\r") #sys.stdout.write(Fore.MAGENTA+'[%s] STATUS: %s (%d)\r'%(datetime.datetime.now().strftime("%H:%M:%S"),'FALSE' if cc is not None else 'TRUE',CompteurSUC)) break elif RQCode == 200 and cc is None and tt is not None: TTCode = tt.get('data-code') TTime = tt.get('data-timer') TToken = tt.get('data-token') await event.message.click(2) #requests.post('http://bch.dogeclick.com/reward',data={'code':TTCode,'token':TToken},headers=BROWSER,allow_redirects=False) break elif RQCode == 200 and cc is not None: await event.message.click(2) time.sleep(10) print(num + "..ok\r") #sys.stdout.write(Fore.MAGENTA+'[%s] STATUS: %s (%d)\r'%(datetime.datetime.now().strftime("%H:%M:%S"),'FALSE' if cc is not None else 'TRUE',CompteurSUC)) CompteurSUC += 1 time.sleep(3) elif MUFilterT(event.original_update.message. reply_markup) is True: print(num) if RFORMER2(RQForm).find('/jc/') > 0: await event.message.click(3) else: username = RFORMER2(RQForm).replace( 'https://telegram.me/', '') try: papa = await event.client( ResolveUsernameRequest(username)) except FloodWaitError as e: await PROFILER.send_message( 'BCH_clickbot', '/visit') return time.sleep(3) #VWate(e.seconds,num) except UsernameNotOccupiedError: await event.message.click(3) except UsernameInvalidError: await event.message.click(3) #papa = await event.client(ResolveUsernameRequest(username)) #ScreenMessage(Fore.BLUE+username) #sys.stdout.write(Fore.GREEN+'[%s]: %s (%s)\r'%(datetime.datetime.now().strftime("%H:%M:%S"),'Wait joining Channel', username)) try: await event.client( JoinChannelRequest( InputPeerChannel( papa.chats[0].id, papa.chats[0].access_hash))) except FloodWaitError as e: await PROFILER.send_message( 'BCH_clickbot', '/visit') #VWate(e.seconds,num) #await event.client(JoinChannelRequest(InputPeerChannel(papa.chats[0].id, papa.chats[0].access_hash))) except ChannelsTooMuchError as c: await main() try: await event.client( JoinChannelRequest( InputPeerChannel( papa.chats[0].id, papa.chats[0].access_hash)) ) except ChannelsTooMuchError: await PROFILER.send_message( 'BCH_clickbot', '/visit') except ChannelPrivateError: await event.message.click(1) await event.message.click(1) time.sleep(2) elif MUFilterT(event.original_update.message. reply_markup) is False: try: print(num + "..ok\r") #print(RFORMER2(RQForm)) await boter(RFORMER2(RQForm)) except UsernameNotOccupiedError: await event.message.click(2) except ChatWriteForbiddenError: await event.message.click(2) except StartParamInvalidError: await event.message.click(2) except ValueError: await event.message.click(2) time.sleep(2)
def resolve_username(self, username): result = self.invoke(ResolveUsernameRequest(username)) if result: return result else: return "Cannot resolve given username. Ensure provided username is valid."
def _getChannel(self): """ Returns telethon.tl.types.Channel object resolved from chat_name at Telegram server """ name = self.settings.chat_name # For private channуls try to resolve channel peer object from its invitation link # Note: it will only work if the login user has already joined the private channel. # Otherwise, get_entity will throw ValueError if name.startswith(JOIN_CHAT_PREFIX_URL): self.logger.debug('Trying to resolve as invite url.') try: peer = self.get_entity(name) if peer: sprint('Invitation link "{}" resolved into channel id={}'. format(name, peer.id)) return peer except ValueError as ex: self.logger.debug( 'Failed to resolve "%s" as an invitation link. %s', self.settings.chat_name, ex, exc_info=self.logger.level > logging.INFO) if name.startswith('@'): name = name[1:] self.logger.debug('Trying ResolveUsernameRequest().') try: peer = self(ResolveUsernameRequest(name)) if peer.chats is not None and peer.chats: sprint('Chat name "{}" resolved into channel id={}'.format( name, peer.chats[0].id)) return peer.chats[0] if peer.users is not None and peer.users: sprint('User name "{}" resolved into channel id={}'.format( name, peer.users[0].id)) return peer.users[0] except (UsernameNotOccupiedError, UsernameInvalidError) as ex: self.logger.debug('Failed to resolve "%s" as @-chat-name. %s', self.settings.chat_name, ex, exc_info=self.logger.level > logging.INFO) # Search in dialogs first, this way we will find private groups and # channels. self.logger.debug('Fetch loggedin user`s dialogs') dialogs_count = self.get_dialogs(0).total self.logger.info('%s user`s dialogs found', dialogs_count) dialogs = self.get_dialogs(limit=None) self.logger.debug('%s dialogs fetched.', len(dialogs)) for dialog in dialogs: if dialog.name == name: sprint('Dialog title "{}" resolved into channel id={}'.format( name, dialog.entity.id)) return dialog.entity if hasattr(dialog.entity, 'username') and dialog.entity.username == name: sprint( 'Dialog username "{}" resolved into channel id={}'.format( name, dialog.entity.id)) return dialog.entity if name.startswith('@') and dialog.entity.username == name[1:]: sprint( 'Dialog username "{}" resolved into channel id={}'.format( name, dialog.entity.id)) return dialog.entity self.logger.debug('Specified chat name was not found among dialogs.') raise ValueError( 'Failed to resolve dialogue/chat name "{}".'.format(name))
sys.exit(1) print(total) print(len(messages)) print(len(senders)) for i, m in enumerate(messages): print(m.stringify()) print(senders[i].stringify()) print(m.id) break # sys.exit(1) from telethon.tl.functions.contacts import ResolveUsernameRequest result = client(ResolveUsernameRequest('mp3downloads1')) print(result.stringify()) found_chats = result.chats found_users = result.users #print(found_chats) #print(found_users) # from telethon.tl.functions.messages import GetDialogsRequest # from telethon.tl.types import InputPeerEmpty # from time import sleep # dialogs = [] # users = [] # chats = []
async def EVENTER(event): event.original_update = event.original_update if type(event.original_update) is not UpdateShortMessage: if (hasattr(event.original_update.message, 'reply_markup') and type(event.original_update.message.reply_markup) is ReplyInlineMarkup): RQForm = MUFilter( event.original_update.message.reply_markup) if RQForm is not None: if (MUFilterT( event.original_update.message.reply_markup) is None): ScreenMessage(Fore.GREEN + ' Requesting reward') UravxBuCwNMpYWTzKhcy = 20 CompteurSUC = 0 while True: (RQCode, RQText) = RFORMER(RQForm) MFINDER = BeautifulSoup(RQText, 'html.parser') cc = MFINDER.find('div', {'class': 'g-recaptcha'}) tt = MFINDER.find('div', {'id': 'headbar'}) if RQCode == 302: sys.stdout.write( Fore.MAGENTA + '[%s] STATUS: %s (%d)\r' % ( datetime.datetime.now().strftime( "%H:%M:%S"), 'FALSE' if cc is not None else 'TRUE', CompteurSUC, )) break elif RQCode == 200 and cc is None and tt is not None: TTCode = tt.get('data-code') TTime = tt.get('data-timer') TToken = tt.get('data-token') await event.message.click(2) break elif RQCode == 200 and cc is not None: await event.message.click(2) time.sleep(10) sys.stdout.write( Fore.MAGENTA + '[%s] STATUS: %s (%d)\r' % ( datetime.datetime.now().strftime( "%H:%M:%S"), 'FALSE' if cc is not None else 'TRUE', CompteurSUC, )) CompteurSUC += 1 time.sleep(3) elif (MUFilterT( event.original_update.message.reply_markup) is True): username = RQForm.replace('https://t.me/', '') papa = await event.client( ResolveUsernameRequest(username)) ScreenMessage(Fore.BLUE + username) sys.stdout.write(Fore.GREEN + '[%s]: %s (%s)\r' % ( datetime.datetime.now().strftime("%H:%M:%S"), 'Wait joining Channel', username, )) try: await event.client( JoinChannelRequest( InputPeerChannel( papa.chats[0].id, papa.chats[0].access_hash))) except FloodWaitError as e: VWate(e.seconds) await event.client( JoinChannelRequest( InputPeerChannel( papa.chats[0].id, papa.chats[0].access_hash))) except ChannelsTooMuchError as c: await main() await event.client( JoinChannelRequest( InputPeerChannel( papa.chats[0].id, papa.chats[0].access_hash))) except ChannelPrivateError: await event.message.click(1) await event.message.click(1) time.sleep(2) elif (MUFilterT( event.original_update.message.reply_markup) is False): try: await boter() except UsernameNotOccupiedError: await event.message.click(2) except ChatWriteForbiddenError: await event.message.click(2) except StartParamInvalidError: await event.message.click(2) except ValueError: await event.message.click(2) time.sleep(2)
def get_channel_users(channel_name): result = [] offset = 0 limit = 100 channel = client(ResolveUsernameRequest(channel_name)) while True: participants = client( GetParticipantsRequest(channel, ChannelParticipantsSearch(''), offset, limit, hash=0)) if not participants.users: break for _user in participants.users: if type(_user.status) is UserStatusOffline: result.append({ 'id': _user.id, 'bot': _user.bot, 'status': _user.status.was_online.isoformat() }) elif type(_user.status) is UserStatusLastWeek: result.append({ 'id': _user.id, 'bot': _user.bot, 'status': 'week' }) elif type(_user.status) is UserStatusLastMonth: result.append({ 'id': _user.id, 'bot': _user.bot, 'status': 'month' }) elif type(_user.status) is UserStatusOffline: result.append({ 'id': _user.id, 'bot': _user.bot, 'status': 'offline' }) elif type(_user.status) is UserStatusOnline: result.append({ 'id': _user.id, 'bot': _user.bot, 'status': 'online' }) elif type(_user.status) is UserStatusRecently: result.append({ 'id': _user.id, 'bot': _user.bot, 'status': 'recently' }) else: result.append({ 'id': _user.id, 'bot': _user.bot, 'status': 'empty' }) offset += len(participants.users) return result
def join_channel(channel_name): channel = client(ResolveUsernameRequest(channel_name)) client(JoinChannelRequest(channel)) return 0
from telethon import TelegramClient from telethon.tl.functions.contacts import ResolveUsernameRequest #this fields should be provided from my.telgram.com api_id = api_hash = client = TelegramClient('session_name', api_id, api_hash) client.start() print('started') # print(client.get_me().stringify()) dictionary = {} channel_list = ['ebookonline', 'YarAmoozan', 'eng_books', 'bestsellers_book', 'dl_ketab', 'ketabkhanichanel'] for channel_name in channel_list: response = client.invoke(ResolveUsernameRequest(channel_name)) messages = client.get_messages(response.peer, limit=3000) # print(messages[0].stringify()) for message in messages: this_url = 't.me/' + channel_name + '/' + str(message.id) try: splitted = re.split(r"[\W']+", str(message.message)) for word in splitted: if word.lower() in dictionary: dictionary[word.lower()].append(this_url) else: dictionary[word.lower()] = this_url.split() except AttributeError: pass
from telethon.tl.types import ChannelAdminLogEventsFilter from telethon.tl.types import InputUserSelf from telethon.tl.types import InputUser api_id = 1135557 api_hash = 'b00c96e8406d2d404d353394cd90f05a' phone = '+918299446752' client = TelegramClient(phone, api_id, api_hash) client.session.report_errors = False client.connect() if not client.is_user_authorized(): client.send_code_request(phone_number) client.sign_in(phone_number, input('Enter the code: ')) channel = client(ResolveUsernameRequest('MY_CHANNEL')) # Your channel username user = client( ResolveUsernameRequest('Username')) # Your channel admin username admins = [ InputUserSelf(), InputUser(user.users[0].id, user.users[0].access_hash) ] # admins admins = [] # No need admins for join and leave and invite filters filter = None # All events filter = ChannelAdminLogEventsFilter(True, False, False, False, True, True, True, True, True, True, True, True, True, True) cont = 0 list = [0, 100, 200, 300]
api_hash = '48ae9fbdf79edda291e1fa5796fc4665' #phone_number = '+528132341246' ################################################ channel = '@pruebastienda' offset = 0 limit = 100 all_participants = [] usernames = [] client = TelegramClient( 'sessionname', api_id, api_hash) # feel free to edit %sessionname% as you want client.connect() # logining and connecting to Telegram servers channel_use = client( ResolveUsernameRequest('pruebastienda')) # Your channel username #print(channel_use) #admins = [InputUserSelf(), InputUser(user.users[0].id, user.users[0].access_hash)] # admins admins = [] # No need admins for join and leave and invite filters ##print(result) #result = client(GetFullChannelRequest(channel)) #print(result) # Then we need a loop to work with loop = asyncio.get_event_loop() # We also need something to run async def main(): #for char in 'Hello, world!\n': #print(char, end='', flush=False)
from telethon.tl.types import ChannelAdminLogEventsFilter from telethon.tl.types import InputUserSelf from telethon.tl.types import InputUser from telethon.tl.functions.channels import GetParticipantsRequest from telethon.tl.functions.channels import GetFullChannelRequest from telethon.tl.functions.contacts import ResolveUsernameRequest from telethon.tl.functions.messages import GetFullChatRequest from telethon.tl.types import InputChannel from telethon.tl.types import InputPeerEmpty from telethon.tl.types import ChannelParticipantsKicked # import type to use as filter from telethon.tl.types import ChannelParticipantsRecent from telethon.tl.types import ChannelAdminLogEventActionParticipantJoin from telethon.tl.types import ChannelParticipantsSearch api_id = 3409046 api_hash = '48ae9fbdf79edda291e1fa5796fc4665' phone_number = '+528132341246' channel = '@pruebastienda' ################################################ offset = 0 limit = 100 all_participants = [] users = [] # These example values won't work. You must get your own api_id and # api_hash from https://my.telegram.org, under API Development. client = TelegramClient("session", api_id, api_hash) client.session.report_errors = False client.start() channel = client(ResolveUsernameRequest('@pruebastienda')) # Your channel username user = client(ResolveUsernameRequest('jcolvera1991')) # Your channel admin username
async def EVENTER(event): event.original_update=event.original_update if type(event.original_update)is not UpdateShortMessage: if hasattr(event.original_update.message,'reply_markup')and type(event.original_update.message.reply_markup)is ReplyInlineMarkup: RQForm=MUFilter(event.original_update.message.reply_markup) if RQForm is not None: if MUFilterT(event.original_update.message.reply_markup) is None: print('working ') UravxBuCwNMpYWTzKhcy=20 CompteurSUC=0 while True: (RQCode,RQText)=RFORMER(RQForm) MFINDER=BeautifulSoup(RQText,'html.parser') cc=MFINDER.find('div',{'class':'g-recaptcha'}) tt=MFINDER.find('div',{'id':'headbar'}) if RQCode==302: print('working ') break elif RQCode==200 and cc is None and tt is not None: TTCode=tt.get('data-code') TTime=tt.get('data-timer') TToken=tt.get('data-token') await event.message.click(2) #requests.post('http://bch.dogeclick.com/reward',data={'code':TTCode,'token':TToken},headers=BROWSER,allow_redirects=False) break elif RQCode==200 and cc is not None: await event.message.click(2) time.sleep(10) print('working ') CompteurSUC+=1 time.sleep(3) elif MUFilterT(event.original_update.message.reply_markup) is True: username = RQForm.replace('https://t.me/', '') papa = await event.client(ResolveUsernameRequest(username)) print('working ') time.sleep(1) print('working ') try: await event.client(JoinChannelRequest(InputPeerChannel(papa.chats[0].id, papa.chats[0].access_hash))) except FloodWaitError as e: VWate(e.seconds) await event.client(JoinChannelRequest(InputPeerChannel(papa.chats[0].id, papa.chats[0].access_hash))) except ChannelsTooMuchError as c: await main() await event.client(JoinChannelRequest(InputPeerChannel(papa.chats[0].id, papa.chats[0].access_hash))) except ChannelPrivateError: await event.message.click(1) await event.message.click(1) time.sleep(2) elif MUFilterT(event.original_update.message.reply_markup) is False: try: await boter() except UsernameNotOccupiedError: await event.message.click(2) except ChatWriteForbiddenError: await event.message.click(2) except StartParamInvalidError: await event.message.click(2) except ValueError: await event.message.click(2) time.sleep(2)
api_hash = '48ae9fbdf79edda291e1fa5796fc4665' #phone_number = '+528132341246' ################################################ channel = '@poolpruebas' offset = 0 limit = 100 all_participants = [] usernames = [] client = TelegramClient( 'sessionname', api_id, api_hash) # feel free to edit %sessionname% as you want client.connect() # logining and connecting to Telegram servers channel_use = client( ResolveUsernameRequest('poolpruebas')) # Your channel username @events.register(events.ChatAction(func=lambda e: e.action_message is None)) async def chat_action_empty(event: events.ChatAction.Event): print(event.stringify()) @client.on(events.ChatAction("@poolpruebas")) async def handler(event): # Welcome every new user print(event) if event.user_joined: await event.reply('Welcome to the group!')
from telethon.tl.functions.users import GetUsersRequest from telethon.tl.functions.channels import GetFullChannelRequest from telethon.utils import get_input_peer from telethon.tl.types.channels import ChannelParticipants from telethon.tl.functions.messages import SendMessageRequest import sys import urllib import time api_id = ****** # api_hash = '*******' phone_number = '****8' client = TelegramClient('%sweessionname%', api_id, api_hash) client.connect() # logining and connecting to Telegram servers if not client.is_user_authorized(): # authorization (if there is no .session file created before) client.send_code_request(phone_number) client.sign_in(phone_number, input('Enter the code: ')) result = client(ResolveUsernameRequest('___NODEVIEWCOPY___33___NODEVIEWCOPY___')) found_chats = result.chats found_users = result.users r = client(GetParticipantsRequest(result.chats[0], filter=ChannelParticipantsRecent(), # List of filters https://lonamiwebs.github.io/Telethon/types/channel_participants_filter.html offset=___NODEVIEWCOPY___34___NODEVIEWCOPY___, # getting info from 0th user limit=5000) # limiting number of users in a request ) fusers=r.users
"""JSON serializer for objects not serializable by default json code""" if isinstance(obj, (datetime, date)): return obj.isoformat() raise TypeError("Type %s not serializable" % type(obj)) LIMIT = 100 client = TelegramClient('fetcher-session', config.api_id, config.api_hash) client.connect() client.sign_in(phone=config.phone) me = client.sign_in(code=int(input('Enter code: '))) channel = client(ResolveUsernameRequest(config.channel)).chats[0] offset = 0 output = [] while True: participants = client(GetParticipantsRequest( channel, ChannelParticipantsSearch(''), offset, LIMIT, hash=0)) if not participants.users: break for user in participants.users: output.append(user.to_dict()) offset += len(participants.users) print('Fetched %s users' % len(output)) output_file = '%s-%s.json' % (config.channel, len(output)) with open(output_file, 'w') as f:
from telethon import TelegramClient from telethon.tl.functions.contacts import ResolveUsernameRequest from telethon.tl.functions.channels import GetFullChannelRequest from telethon.tl.functions.messages import GetFullChatRequest from telethon.tl.types import InputChannel from telethon.tl.types import InputPeerEmpty api_id = 3409046 api_hash = '48ae9fbdf79edda291e1fa5796fc4665' #phone_number = '+528132341246' ################################################ channel = '@pruebastienda' offset = 0 limit = 100 all_participants = [] usernames = [] # Create the client and connect client = TelegramClient('sessionname', api_id, api_hash) # feel free to edit %sessionname% as you want client.connect result = client(ResolveUsernameRequest('@pruebastienda')) #found_chats = result.chats #found_users = result.users #r = client(GetFullChannelRequest(result.chats[0]))