-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathOldTelethon.py
More file actions
66 lines (63 loc) · 2.44 KB
/
OldTelethon.py
File metadata and controls
66 lines (63 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#code by Jaindu Charindith
#t.me/charindith
from telethon import TelegramClient, events
from telethon.sessions import StringSession
from time import sleep
from requests import post
import pytz,os
TG_API='https://api.telegram.org/bot'
api_id = int(os.getenv("API_ID"))
api_hash = os.getenv("API_HASH")
TOKEN=os.getenv("BOT_TOKEN")
BOT_url=TG_API + TOKEN
log_users=[os.getenv("LOG_CHANNEL")]
ownerunam=os.getenv("OWNER_UNAME")
session=os.getenv("SESSION")
client = TelegramClient(StringSession(session), api_id, api_hash)
def botSend(fileName, tes ,pat):
files = {pat: (fileName, open(fileName,'rb'))}
for log_user in log_users:
r = post(BOT_url+tes+'&chat_id='+log_user, files=files)
def utc_to_time(naive, timezone="Asia/Kolkata"):
return naive.replace(tzinfo=pytz.utc).astimezone(pytz.timezone(timezone))
def dirup(event,sender,pat,tgapi):
tes =tgapi+'?caption=@'+ str(sender.username)+"\n"+str(event.text)+"\n"+str(utc_to_time(event.date))
arr = os.listdir(pat)
for files in arr:
path=pat+"/"+str(files)
botSend(path,tes,pat)
sleep(1)
os.remove(path)
@client.on(events.Album)
async def handler(event):
if event.is_private:
await event.forward_to(log_users[0])
@client.on(events.NewMessage)
async def my_event_handler(event):
sender = await event.get_sender()
if event.is_private:
if event.photo or event.video or event.document or event.audio:
if event.photo:
pat='photo'
tgapi='/sendPhoto'
elif event.video:
pat='video'
tgapi='/sendvideo'
else:
pat='document'
tgapi='/sendDocument'
await event.download_media(file=pat)
sleep(2)
await dirup(event,sender,pat,tgapi)
else:
tes ="@"+ str(sender.username)+"\n"+str(event.text)+"\n"+str(utc_to_time(event.date))
eentity = await client.get_entity(event.original_update.user_id)
print(eentity.username)
if sender.username==ownerunam:
tes ="@"+ownerunam+" to @"+ str(eentity.username)+"\n"+str(event.text)+"\n"+str(utc_to_time(event.date))
for log_user in log_users:
g=post(BOT_url+'/sendmessage' , json={"chat_id":log_user,"text":tes})
print(g.text)
print('bot started\nBY CHARINDITH(t.me/charindith)')
client.start()
client.run_until_disconnected()