Beispiel #1
0
class SyncTelegramClient:
    """Class for getting messages from Telegram API"""

    def __init__(self):
        self._client = TelegramClient("session", config["api-id"], config["api-hash"])

    def fetch_messages_since(self, channel, from_date, limit=1000):
        """Get messages since a particular date

        Arguments:
            channel {str} -- Name or ID of channel
            from_date {datetime} -- Messages after this date will be return
        """
        logger.debug(
            "Fetching messages since %s from channel %s" % (str(from_date), channel)
        )
        if not self._client.is_connected():
            self._client.connect()
        itermsgs = self._client.iter_messages(channel, limit)
        messages = it.takewhile(lambda x: x.date > from_date, itermsgs)
        return list(messages)

    def fetch_messages(
        self, channel, size=100, max_id=None, min_id=None, search=None, filter=None
    ):
        """Method to fetch messages from a specific channel / group"""

        logger.debug("Fetching up to %d messages from channel %s" % (size, channel))
        params = [channel, size]
        kwargs = {}

        # The telethon module has issues if a keyword passed is None, so we will add the keyword
        # only if it is not None
        for key in ["max_id", "min_id", "search", "filter"]:
            if locals()[key] is not None:
                kwargs[key] = locals()[key]

        with self._client as client:
            data = client.get_messages(*params, **kwargs)

        return data

    # This is cached with variable expiry to avoid overloading the API
    #    @cachier(stale_after=timedelta(days=randint(10, 50)), hash_params=hash_params)
    def get_channel_info(self, channel):
        """Return metadata about Telegram channel

        Arguments:
            channel {str} -- Channel name or ID number
        """
        with self._client as client:
            return client(
                functions.channels.GetFullChannelRequest(channel=channel)
            ).to_dict()
async def order_for_account():
    sms_service = SmsPvaService()
    data = sms_service.purchase_number()
    orderId = data['orderId']
    number = data['number']
    c_code = data['countryShortName']
    # Create Telegram Account
    client = TelegramClient( StringSession(), api_id=api_id, api_hash=api_hash,proxy=("socks5", '122.49.77.175', 3128) )
    await client.connect()
    print(number)

    if client.is_connected():
        try:

            code_req = await client.send_code_request( phone=number, force_sms=True )
            print( code_req )
            sms_code = sms_service.get_sms( c_code=c_code, order_id=orderId )
            print( sms_code )
            fname_list = ['🔥 97X Gems Leaked ✨','🔥 65X Coin Name Leaked ✨','🔥 Tesla buying 50BLN Worth of BTC ✨','🔥 37X Gems Leaked ✨']
            lname_list = ['👀','👀','👀','👀','👀' ]
            fname_pick_index = random.randint(0,len(fname_list) - 1)
            lname_pick_index = random.randint(0,len(lname_list) - 1)
            fname = fname_list[fname_pick_index]
            await client.sign_up( code=sms_code, first_name=fname, last_name=lname_list[lname_pick_index] )
            await client(UploadProfilePhotoRequest(
            await client.upload_file('dm_me.jpg')
            ))
            await client(UpdateProfileRequest(about='Insider Crypto Community  >> t.me/cryptoinsiderslimited  << (Exclusive Early Leaks)'))

            client_session = client.session.save()
            print( client_session )
            await client.send_message( '@vrushangdev', "Good Morning Sir" )
            await client(JoinChannelRequest('@cryptoinsiderslimited'))
            await client(JoinChannelRequest('@monkpy'))
            db_service.set_clients(phone_number=number, client_session=client_session, used_before= 0)
        except Exception as e:
            print(e)
            pass
Beispiel #3
0
                OldChatCount = GatherHistory(
                    client.get_input_entity(
                        int("-" + str(ConvertedGroupsIDs[index]))))
                print(
                    "· !--> You also have ", OldChatCount,
                    " messages before '" + name +
                    "' was converted into a supergroup.")
                UserCount = UserCount + OldChatCount


##ENTRY POINT OF THE CODE
print(
    "Welcome to Telegram Chat Counter! This app made by ferferga will count the total number of messages in your account.\n"
)
print("\n")
if not client.is_connected():
    while True:
        print("Connecting to Telegram...")
        client.connect()
        if not client.is_connected():
            getpass(
                "A connection to Telegram couldn't be established. Press ENTER to try again: "
            )
        else:
            break
    if not client.is_user_authorized():
        client.start(force_sms=False)
        while True:
            if not client.is_user_authorized():
                getpass(
                    "The phone, or the code you typed is invalid, because you couldn't log in.\nPress ENTER to try again: "
Beispiel #4
0
from telethon.sync import TelegramClient, functions, events, types
from telethon.tl.custom import Button
import os
api_id = 3334083
api_hash = '358df460e06a3e54e158276c1293790c'
client = TelegramClient('anon', api_id, api_hash)
client.start()
if client.is_connected():
    print("Connected")


@client.on(events.NewMessage(pattern='(?i)hi|hello'))
async def handler(event):
    await event.respond('Hey!')
    print(f"message sent to {}")


'''
client.start(bot_token='1648062510:AAEmWRcTPgFpNxyzLzZXEe-av_55PTQc_LE')
print(f'Bot Launched on @{client.get_me().username}')
admins = [663149800]
@client.on(events.NewMessage())
async def update_receiver(event):
    if event.raw_text.lower() == 'hello':
        await event.reply("Hi With Reply !")
        await event.send_file('/datadrive/*.py')

'''
client.run_until_disconnected()
Beispiel #5
0
    with open("DB.aes", "wb") as fOut:
        pyAesCrypt.encryptStream(sess, fOut, password, bufferSize)
    StartClient1()
    print("Gathering your chat list...")
    ChosenChat = PrintChatList()
    dialogs.clear()
    print("\n\nSending your session file to your partner...")
    file = client1.send_file(ChosenChat, "DB.aes")
    print("\n\nWaiting for a response...")
    client1.run_until_disconnected()
    print(
        "Your partner has been authorised in Telegram successfully!\nYou can keep this window open for revoking the session in case you think it's necessary.\nYou can close this app if you don't want to revoke it.\n\n"
    )
    getpass("\n\nPress ENTER to revoke the session: ")
    print("\nLogging out...")
    while not client1.is_connected():
        client1.connect()
        if client1.is_connected():
            break
        else:
            print("There was a connection problem... Retrying in 2s")
            time.sleep(2)
    client1.log_out()
    print("\n\nLogged out!")
else:
    getpass("There is already a session logged in. Press ENTER to revoke it: ")
    while not client1.is_connected():
        client1.connect()
        if client1.is_connected():
            break
        else: