Skip to content

Instantly share code, notes, and snippets.

@SmartManoj
Last active October 9, 2020 11:50
Show Gist options
  • Save SmartManoj/aceee7302d5fcbe0721814d26e3f7d01 to your computer and use it in GitHub Desktop.
Save SmartManoj/aceee7302d5fcbe0721814d26e3f7d01 to your computer and use it in GitHub Desktop.
Save Contact or Find importers
import os
from telethon import TelegramClient, events
from telethon.tl.types import InputPhoneContact
from telethon import functions, types
from config import *
import random
from tthon import *
sn = 'Temp'
sn += f'' if not os.getenv('username') else 'L'
tclient = None
from telegram.utils.helpers import escape_markdown, mention_html
async def create_contact(event=None,
chat=None, phone_number='', first_name=' ', last_name=' - From SARA'):
try:
# print(client2)
result = (
'BEGIN:VCARD\n'
'VERSION:4.0\n'
'N:{f};{l};;;\n'
'FN:{f} {l}\n'
'TEL;TYPE=cell;VALUE=uri:tel:+{p}\n'
'END:VCARD\n'
).format(f=first_name, l=last_name, p=phone_number)
contact = InputPhoneContact(random.randint(
0, 9999), phone_number, first_name, last_name)
contacts = await tclient(functions.contacts.ImportContactsRequest([contact]))
cd = (contacts.to_dict())
yu1 = 'https://jayxt.github.io/MessengerComparison/en/', 'Y should I?'
ai = alink('https://telegra.ph/Invite-07-13',
'Auto Invite Your Whatsapp Friends')
# yu=alink(*yu1)
if cd.get('users'):
a1 = cd['users'][0].get('username')
a2 = cd['users'][0]['phone']
a3 = cd['users'][0]['id']
if a1 == 'None' or a1 is None:
a1 = 'Username'
a12 = '@' + str(a1)
try:
a = cd['users'][0]['status']
rt = '- Account will be deleted automatically'
vb = {
'UserStatusLastMonth': 'with in a month' + rt,
'UserStatusLastWeek': 'with in a week',
'UserStatusRecently': 'Recently',
}
b = rt
if a:
a1 = a.get('was_online')
if a1:
a1 = (a1 + timedelta(hours=5, minutes=30)).replace(tzinfo=None)
b = (humanize.naturaltime(a1))
if ((today_ - a1).days) > 10:
b += rt
elif a.get('expires'):
b = 'Online'
else:
b = vb[a.get('_')]
except Exception as e:
exception(e)
b = '--'
if event == None:
a12 = alink(f'https://t.me/{a12[1:]}', a12)
m = f'''^{chat} -
`USERNAME :` {((a12 or "None"))}
`PHONE :` +{a2}
`ID :` {mention_html(int(a3),'link')}
`LAST SEEN :` {b}
{ai}
'''
if 1:
await tclient.send_file('SmartManoj', types.MessageMediaContact(phone_number, first_name, last_name, result, a3))
if event:
m = codere(m)
await event.respond(m)
for i in range(2):
try:
pass
await tclient.send_file(tidSara, types.MessageMediaContact(phone_number, first_name, last_name, result, a3))
break
except Exception as e:
exception(e)
exception(e)
tclient.get_dialogs(1)
else:
m = m.replace('`', '')
else:
tc = 1
if cd['popular_invites']:
tc = cd['popular_invites'][0]['importers']
m1 = f" {tc} friends on Telegram.\n"
n = first_name + ' ' + last_name
n3 = 'You have'
n2 = n.strip() or n3
if n2 != n3:
n2 += ' has'
m = f"{'+'+phone_number if event else n2 }{m1}"
# t=f"Connect @ https://telegra.ph/TG-07-06 ! {' - '.join(yu1)}"
t = 'j.mp/ClickToFindYourFriends'
m += f"{api_wa(str(phone_number),'Hi, You'+m1+t,'Invite them!',resolve=0)}\n{t}"
if event:
await event.respond(m)
return pre(m)
except Exception as e:
exception(e)
traceback.print_exc()
async def handler2(event):
try:
pass
tid = (event.chat_id)
t = event.raw_text.lower()
if tid == 777000:
print(tid, t)
if tid == tidSara and re.match('\d{9}.*', t):
await create_contact(event, *t.splitlines()[0].split('.', 4))
except Exception as e:
print(e)
traceback.print_exc()
import traceback
if not wherey:
tclient = TelegramClient(sn, api_id, api_hash)
tclient.add_event_handler(handler2, events.NewMessage)
tclient.start()
client = tclient
# create
if __name__ == '__main__':
# from config import *
# asyncio.run(create())
print(233)
for i in [
''
]:
pass
f, l = 'Kaviarasu', 'Arunagiri'
a = gloop.run_until_complete(create_contact(
phone_number=rpn(str(i)), first_name=f, last_name=l))
# gloop.run_until_complete(client2.send_message(tidme,'hi'))
# gloop.run_until_complete(client3.send_message(tidme,'hi2'))
print(a, '2')
send_message(a, chat_id=tidme, opt='dwpp')
print(a, '22')
# break
# asyncio.run(main())
print('2')
# print(client2)
# client2.add_event_handler(handler2, events.NewMessage)
print('22')
# tidSara=tidme
# print(slink('x','Invite them!'))
# (tclient.run_until_disconnected())
# asyncio.run_until_disconnected()
# sleep(60*10)
exit()
# from quart import Quart, websocket,render_template,request
# import asyncio
# app = Quart(__name__)
# # loop = asyncio.get_event_loop()
# # loop.create_task(background2())
# app.run(debug=1,loop=loop)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment