@@ -793,7 +793,13 @@ def should_filter(self, user: User, data: bytes):
793
793
- Throws PostRejected if the message should be rejected (and rejection passed back to the
794
794
user).
795
795
"""
796
- msg = Post (raw = data )
796
+ msg_ = None
797
+
798
+ def msg ():
799
+ nonlocal msg_
800
+ if msg_ is None :
801
+ msg_ = Post (raw = data )
802
+ return msg_
797
803
798
804
if not config .FILTER_MODS and self .check_moderator (user ):
799
805
return None
@@ -807,7 +813,7 @@ def should_filter(self, user: User, data: bytes):
807
813
if lang not in alphabets :
808
814
continue
809
815
810
- if not pattern .search (msg .text ):
816
+ if not pattern .search (msg () .text ):
811
817
continue
812
818
813
819
# Filter it!
@@ -817,7 +823,7 @@ def should_filter(self, user: User, data: bytes):
817
823
if not filter_type and filt ['profanity_filter' ]:
818
824
import better_profanity
819
825
820
- for part in (msg .text , msg .username ):
826
+ for part in (msg () .text , msg () .username ):
821
827
if better_profanity .profanity .contains_profanity (part ):
822
828
filter_type = 'profanity'
823
829
break
@@ -831,7 +837,7 @@ def should_filter(self, user: User, data: bytes):
831
837
if msg_fmt :
832
838
pbmsg = protobuf .Content ()
833
839
body = msg_fmt .format (
834
- profile_name = (user .session_id if msg .username is None else msg .username ),
840
+ profile_name = (user .session_id if msg () .username is None else msg () .username ),
835
841
profile_at = "@" + user .session_id ,
836
842
room_name = self .name ,
837
843
room_token = self .token ,
0 commit comments