@@ -2,6 +2,7 @@ class TrainedMessage < ApplicationRecord
2
2
enum :message_type , { spam : 0 , ham : 1 , untrained : 2 , maybe_spam : 3 , maybe_ham : 4 }
3
3
# New enum for what is being trained
4
4
enum :training_target , { message_content : 0 , user_name : 1 }
5
+ enum :source , { chat : 0 , feedspam_command : 1 , import : 2 }
5
6
module MessageType
6
7
SPAM = "spam"
7
8
HAM = "ham"
@@ -14,6 +15,11 @@ module TrainingTarget
14
15
MESSAGE_CONTENT = "message_content"
15
16
USER_NAME = "user_name"
16
17
end
18
+ module Source
19
+ CHAT = "chat"
20
+ FEEDSPAM_COMMAND = "feedspam_command"
21
+ IMPORT = "import"
22
+ end
17
23
GLOBAL_SHARED_MESSAGE = 0
18
24
19
25
scope :shared , -> { where ( group_id : GLOBAL_SHARED_MESSAGE ) }
@@ -45,7 +51,7 @@ def should_ban_user
45
51
end
46
52
47
53
spam_ban_threshold = Rails . application . config . spam_ban_threshold
48
- spam_count = TrainedMessage . where ( group_id : self . group_id , sender_chat_id : self . sender_chat_id , message_type : :spam ) . count
54
+ spam_count = TrainedMessage . where ( group_id : self . group_id , sender_chat_id : self . sender_chat_id , message_type : :spam , source : :chat ) . count
49
55
chat_member = TelegramMemberFetcher . get_bot_chat_member ( self . group_id )
50
56
can_ban_user = [ "administrator" , "creator" ] . include? ( chat_member &.status ) && chat_member &.can_restrict_members
51
57
if spam_count >= spam_ban_threshold && can_ban_user
0 commit comments