-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpm_logger.py
89 lines (74 loc) · 2.95 KB
/
pm_logger.py
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
import asyncio
import logging
import os
import sys
from asyncio import sleep
from telethon import events
from . import *
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.WARN
)
NO_PM_LOG_USERS = []
lg_id = Config.PM_LOG_ID
@bot.on(d3vil_cmd(pattern=r"save(?: |$)([\s\S]*)", outgoing=True))
async def log(log_text):
if lg_id is not None:
if log_text.reply_to_msg_id:
reply_msg = await log_text.get_reply_message()
await reply_msg.forward_to(lg_id)
elif log_text.pattern_match.group(1):
user = f"#LOG / Chat ID: {log_text.chat_id}\n\n"
textx = user + log_text.pattern_match.group(1)
await bot.send_message(lg_id, textx)
else:
await eod(log_text, "`What am I supposed to save?`")
return
await eod(log_text, "`Saved Successfully`")
else:
await eod(log_text, "`This feature requires Logging to be enabled!`")
@bot.on(events.NewMessage(incoming=True, func=lambda e: e.is_private))
async def monito_p_m_s(event):
if lg_id is None:
return
sender = await event.get_sender()
if lg_id and not sender.bot:
chat = await event.get_chat()
if chat.id not in NO_PM_LOG_USERS and chat.id != bot.uid:
try:
e = await bot.get_entity(int(Config.PM_LOG_ID))
fwd_message = await bot.forward_messages(e, event.message, silent=True)
except Exception as e:
# logger.warn(str(e))
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
print(e)
@bot.on(d3vil_cmd(pattern="elog ?(.*)"))
async def set_no_log_p_m(event):
if Config.PM_LOG_ID is not None:
event.pattern_match.group(1)
chat = await event.get_chat()
if event.is_private:
if chat.id in NO_PM_LOG_USERS:
NO_PM_LOG_USERS.remove(chat.id)
await event.edit("Will Log Messages from this chat")
await asyncio.sleep(3)
await event.delete()
@bot.on(d3vil_cmd(pattern="nlog ?(.*)"))
async def set_no_log_p_m(event):
if Config.PM_LOG_ID is not None:
event.pattern_match.group(1)
chat = await event.get_chat()
if event.is_private:
if chat.id not in NO_PM_LOG_USERS:
NO_PM_LOG_USERS.append(chat.id)
await event.edit("Won't Log Messages from this chat")
await asyncio.sleep(3)
await event.delete()
CmdHelp("pm_logger").add_command(
"save", "<reply>", "Saves the replied message to your pm logger group/channel"
).add_command(
"elog", "<chat>", "Enables logging pm messages from the selected chat."
).add_command(
"nlog", "<chat>", "Disables logging pm messages from the selected chat. Use .elog to enable it again."
).add()