forked from Lucifer-00007/conflux-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (31 loc) · 1.55 KB
/
main.py
File metadata and controls
39 lines (31 loc) · 1.55 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
from telethon import TelegramClient, events
from settings import TELEGRAM_API_ID, TELEGRAM_API_HASH, COMBINATIONS
client = TelegramClient('session', api_id=TELEGRAM_API_ID, api_hash=TELEGRAM_API_HASH)
# create a new function to receive NewMessage events
@client.on(events.NewMessage)
async def handle_new_message(event):
# check if message is received form specific sender
sender_chat_id = event.sender_id
if sender_chat_id in list(COMBINATIONS.keys()):
msg_text = event.raw_text
# check if message has any blacklisted word
contains_blacklisted_word = False
blacklisted_words = COMBINATIONS.get(sender_chat_id).get("blacklists")
for word in blacklisted_words:
if word in msg_text:
contains_blacklisted_word = True
# check if message has any whitelisted word
contains_whitelisted_word = False
whitelisted_words = COMBINATIONS.get(sender_chat_id).get("whitelists")
for word in whitelisted_words:
if word in msg_text:
contains_whitelisted_word = True
# and process the message only if there is no blacklisted word and
# have at least 1 whitelisted word
if not contains_blacklisted_word and contains_whitelisted_word:
# send the message to destination chat
destination_chat_ids = COMBINATIONS.get(sender_chat_id).get("destinations")
for chat_id in destination_chat_ids:
await client.send_message(chat_id, event.raw_text)
client.start()
client.run_until_disconnected()