-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForwardRule.py
More file actions
60 lines (48 loc) · 1.96 KB
/
ForwardRule.py
File metadata and controls
60 lines (48 loc) · 1.96 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
from pytg.sender import Sender
from utilities import info
class ForwardRule:
# RULES
def __init__(self, from_chat, to_chat, msg_contains=""):
self._from_chat = from_chat
self._to_chat = to_chat
self._msg_contains = msg_contains
def evaluate(self, telegram_msg):
if 'text' in telegram_msg:
if self._msg_contains in telegram_msg['text'] or self._msg_contains == "":
# print("msg match")
pass
else:
# print("not msg match")
return False
if 'receiver' in telegram_msg and 'id' in telegram_msg['receiver'] and telegram_msg['receiver'][
'id'] == self._from_chat:
return True
return False
def execute(self, telegram_msg):
if self.evaluate(telegram_msg=telegram_msg):
print("FORWARDED " + self.__repr__())
# print(telegram_msg)
if "text" in telegram_msg:
sender.msg(self._to_chat, telegram_msg['text'])
elif "media" in telegram_msg:
sender.fwd_media(self._to_chat, telegram_msg['id'])
if telegram_msg['media']['caption']:
sender.msg(self._to_chat, telegram_msg['media']['caption'])
else:
sender.fwd(self._to_chat, telegram_msg['id'])
def __str__(self):
from_info = info(self._from_chat)
to_info = info(self._to_chat)
# print(from_info)
# print(to_info)
return from_info["print_name"] + " " + to_info["print_name"]
def __repr__(self):
from_info = info(self._from_chat)
to_info = info(self._to_chat)
# print(from_info)
# print(to_info)
return "De " + from_info["print_name"] + " a " + to_info["print_name"]
def __eq__(self, other):
return self._to_chat == other._to_chat and self._from_chat == other._from_chat
sender = Sender(host="localhost", port=4458)
admin = sender.get_self()