2021-11-25 06:42:59 +01:00
|
|
|
#!/usr/bin/python3
|
2021-11-26 02:29:41 +01:00
|
|
|
from telethon import TelegramClient, events, functions, types
|
2021-11-25 06:42:59 +01:00
|
|
|
from config import *
|
|
|
|
|
|
|
|
client = TelegramClient('telelog', api_id, api_hash)
|
|
|
|
|
|
|
|
@client.on(events.NewMessage)
|
2021-11-29 14:02:23 +01:00
|
|
|
|
|
|
|
async def edit(event):
|
|
|
|
msg = event.raw_text
|
|
|
|
if event.sender_id != myid:
|
|
|
|
return
|
|
|
|
|
|
|
|
if msg.startswith('.tl.alive'):
|
|
|
|
rpl = "Telelog alive and well!"
|
|
|
|
await event.edit(rpl)
|
|
|
|
|
|
|
|
if msg.startswith('.tl.log'):
|
|
|
|
chat = str(msg.split()[1])
|
|
|
|
f = open(chat)
|
|
|
|
await event.edit(f.read())
|
|
|
|
|
2021-11-25 06:42:59 +01:00
|
|
|
async def log(event):
|
|
|
|
if event.is_private:
|
|
|
|
if event.sender_id != myid:
|
|
|
|
#Incoming message
|
2021-11-26 02:29:41 +01:00
|
|
|
try:
|
|
|
|
f = open(str(event.chat_id))
|
|
|
|
except IOError:
|
|
|
|
chat = await event.get_input_chat()
|
|
|
|
rpl = "This account does not accept private messages. "
|
|
|
|
rpl += "My userbot will block you now. "
|
|
|
|
rpl += "Please reach out to me in a common group if applicable. "
|
|
|
|
await event.respond(rpl)
|
|
|
|
await client(functions.contacts.BlockRequest(chat))
|
|
|
|
f = open(str(event.chat_id), "a")
|
2021-11-25 06:42:59 +01:00
|
|
|
f.write(str(event.id) + ": " + str(event.chat_id) + " => " + str(myid) + "\n")
|
|
|
|
else:
|
|
|
|
#Outgoing message
|
2021-11-26 02:29:41 +01:00
|
|
|
f = open(str(event.chat_id), "a")
|
2021-11-25 06:42:59 +01:00
|
|
|
f.write(str(event.id) + ": " + str(event.sender_id) + " => " + str(event.chat_id) + "\n")
|
|
|
|
f.write(event.raw_text + "\n")
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
client.start()
|
|
|
|
client.run_until_disconnected()
|