Implement the logging and blocking features
This commit is contained in:
14
log.py
14
log.py
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from telethon import TelegramClient, events
|
from telethon import TelegramClient, events, functions, types
|
||||||
from config import *
|
from config import *
|
||||||
|
|
||||||
client = TelegramClient('telelog', api_id, api_hash)
|
client = TelegramClient('telelog', api_id, api_hash)
|
||||||
@@ -7,12 +7,22 @@ client = TelegramClient('telelog', api_id, api_hash)
|
|||||||
@client.on(events.NewMessage)
|
@client.on(events.NewMessage)
|
||||||
async def log(event):
|
async def log(event):
|
||||||
if event.is_private:
|
if event.is_private:
|
||||||
f = open(str(event.chat_id), "a")
|
|
||||||
if event.sender_id != myid:
|
if event.sender_id != myid:
|
||||||
#Incoming message
|
#Incoming message
|
||||||
|
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")
|
||||||
f.write(str(event.id) + ": " + str(event.chat_id) + " => " + str(myid) + "\n")
|
f.write(str(event.id) + ": " + str(event.chat_id) + " => " + str(myid) + "\n")
|
||||||
else:
|
else:
|
||||||
#Outgoing message
|
#Outgoing message
|
||||||
|
f = open(str(event.chat_id), "a")
|
||||||
f.write(str(event.id) + ": " + str(event.sender_id) + " => " + str(event.chat_id) + "\n")
|
f.write(str(event.id) + ": " + str(event.sender_id) + " => " + str(event.chat_id) + "\n")
|
||||||
f.write(event.raw_text + "\n")
|
f.write(event.raw_text + "\n")
|
||||||
f.close()
|
f.close()
|
||||||
|
Reference in New Issue
Block a user