-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathChatBackuper.py
More file actions
102 lines (89 loc) · 3.28 KB
/
ChatBackuper.py
File metadata and controls
102 lines (89 loc) · 3.28 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import requests
from pyrogram import Client, filters
from pyrogram.types import Message
import os
TOKEN=os.getenv("BOT_TOKEN")
session=os.getenv("SESSION")
api_id = int(os.getenv("API_ID"))
api_hash = os.getenv("API_HASH")
log_channel=os.getenv("LOG_CHANNEL")
myuserid=os.getenv("OWNER_UNAME")
BOT_url='https://api.telegram.org/bot'+TOKEN
app=Client('CharindithBAckupBot', api_id,api_hash,session_string=session)
async def dirup(message,pat,tgapi,otherr):
pat=pat[:-1]
tes =tgapi+'?caption='+otherr+ str(message.chat.username)+" "+str(message.chat.first_name) +"\n"+str(message.caption)+"\n"+str((message.date))
arr = os.listdir(pat)
for files in arr:
pathh=pat+"/"+str(files)
file_size=os.stat(pathh).st_size
if file_size<52428800 :
botSend(pathh,tes,pat)
os.remove(pathh)
else:
print('file size is too big')
await message.forward(log_channel)
def botSend(fileName, tes ,pat):
files = {pat: (fileName, open(fileName,'rb'))}
r = requests.post(BOT_url+tes+'&chat_id='+str(log_channel), files=files)
@app.on_message(filters.text & filters.private & ~filters.bot)
async def msg_text(client: Client, message: Message):
print('text recived')
if message.from_user.username == myuserid:
tes ="From @"+myuserid+" to @"+ str(message.chat.username)+" "+str(message.chat.first_name) +"\n"+str(message.text)+"\n"+str((message.date))
else:
tes ="@"+ str(message.from_user.username)+" "+str(message.chat.first_name) +"\n"+str(message.text)+"\n"+str((message.date))
g=requests.post(BOT_url+'/sendmessage' , json={"chat_id":log_channel,"text":tes})
print(tes)
@app.on_message(filters.photo & filters.private & ~filters.bot)
async def msg_photo(client: Client, message: Message):
print('photo recived')
pat='photo/'
tgapi='/sendPhoto'
if message.from_user.username == myuserid:
otherr='From @'+myuserid+' to @'
else:
otherr=''
await app.download_media(message,file_name=pat)
await dirup(message,pat,tgapi,otherr)
@app.on_message(filters.video & filters.private & ~filters.bot)
async def msg_video(client: Client, message: Message):
print('video recived')
pat='video/'
tgapi='/sendVideo'
if message.video.file_size>50428800:
await message.forward(log_channel)
else:
if message.from_user.username == myuserid:
otherr='From @'+myuserid+' to @'
else:
otherr=''
await app.download_media(message,file_name=pat)
await dirup(message,pat,tgapi,otherr)
@app.on_message(filters.audio & filters.private & ~filters.bot)
async def msg_audio(client: Client, message: Message):
print('audio recived')
pat='audio/'
tgapi='/sendAudio'
if message.from_user.username == myuserid:
otherr='From @'+myuserid+' to @'
else:
otherr=''
await app.download_media(message,file_name=pat)
await dirup(message,pat,tgapi,otherr)
@app.on_message(filters.media & filters.private & ~filters.bot & ~filters.photo & ~filters.video & ~filters.audio & ~filters.poll)
async def msg_document(client: Client, message: Message):
print('document recived')
pat='document/'
tgapi='/sendDocument'
if message.document.file_size>50428800:
await message.forward(log_channel)
else:
if message.from_user.username == myuserid:
otherr='From @'+myuserid+' to @'
else:
otherr=''
await app.download_media(message,file_name=pat)
await dirup(message,pat,tgapi,otherr)
print('bot started\nBy @charindith')
app.run()