2023-02-23 11:08:34 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# frozen_string_literal: true
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-03-14 16:03:50 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								module DiscourseAi
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-23 11:08:34 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  module NSFW
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    class EntryPoint
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-23 15:50:10 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      def load_files
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-24 13:25:02 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        require_relative "nsfw_classification"
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-24 07:53:43 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        require_relative "jobs/regular/evaluate_post_uploads"
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-23 15:50:10 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-23 11:08:34 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-23 15:50:10 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      def inject_into(plugin)
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-24 07:53:43 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nsfw_detection_cb =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          Proc.new do |post|
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-24 13:25:02 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if SiteSetting.ai_nsfw_detection_enabled &&
							 | 
						
					
						
							
								
									
										
										
										
											2023-03-14 16:03:50 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 DiscourseAi::NSFW::NSFWClassification.new.can_classify?(post)
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-24 07:53:43 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              Jobs.enqueue(:evaluate_post_uploads, post_id: post.id)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        plugin.on(:post_created, &nsfw_detection_cb)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        plugin.on(:post_edited, &nsfw_detection_cb)
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-23 11:08:34 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 |