Advertisement
PseudoPerson

Scam Interceptor Source Code

Dec 6th, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. --  // Parent: Workspace or ServerScriptService
  2. --  // Class: Script
  3.  
  4. --  // FileName: ScamInterceptorLoader.lua
  5. --  // Written by: PseudoPerson (Dec. 2020)
  6. --  // Description: Sets up ScamInterceptor module script.
  7.  
  8.  
  9.  
  10. -- Services --
  11. local Chat = game:GetService("Chat")
  12. local ServerScriptService = game:GetService("ServerScriptService")
  13.  
  14. -- Instances --
  15. local ChatModules = Chat:WaitForChild("ChatModules")
  16. local ScamInterceptor = script.ScamInterceptor
  17.  
  18. -- Code --
  19. if ScamInterceptor.Parent.Name ~= "ChatModules" then
  20.     ScamInterceptor.Parent = ChatModules
  21. end
  22.  
  23. ---------------------------------------------------------------------
  24.  
  25. --  // Parent: ScamInterceptorLoader
  26. --  // Class: ModuleScript
  27.  
  28. --  // FileName: ScamInterceptor.lua
  29. --  // Written by: PseudoPerson (Dec. 2020)
  30. --  // Description: Filters messages based on sets of keywords.
  31.  
  32.  
  33.  
  34. -- Keywords are divied into sets. If a message reaches over 1.0 weight in any one set then it is filtered.
  35. local keywordSets = {
  36.     -- Example set for scamming
  37.     ["scamming"] = {
  38.         -- Example set:
  39.         ["blox%.page"] = 1;
  40.         ["blox%.army"] = 1;
  41.         ["robux"] = 0.6;
  42.         --Each "word" is a Lua pattern. "%" is an escape character for some characters used for other things. (Ex: "." is used to represent ANY character)
  43.         ["r%$"] = 0.6;
  44.         ["blox"] = 0.2;
  45.         ["page"] = 0.2;
  46.         ["free"] = 0.6;
  47.         ["gamepasses"] = 0.2;
  48.     };
  49.     -- You can also make sets for things like bullying
  50. }
  51.  
  52. local functionId = "ScamInterceptor"
  53.  
  54. -- Level 3 --
  55. local function messageSus(message)
  56.     --converts the message to lowercase
  57.     local lowerMessage = string.lower(message)
  58.     --loops through sets
  59.     for setName, set in pairs(keywordSets) do
  60.         --the weight a message has in each set
  61.         local currentWeight = 0
  62.         --loops through keywords in sets
  63.         for filterString, weight in pairs(set) do
  64.             --if the message has the keyword
  65.             if string.match(lowerMessage, string.lower(filterString)) then
  66.                 --adds that message's weight to the total set weight
  67.                 currentWeight = currentWeight + weight
  68.             end
  69.         end
  70.         --if the total weight the message has in the current set is greater than 1 it returns true, removing the message from the chat.
  71.         if currentWeight >= 1 then
  72.             return setName
  73.         end
  74.     end
  75.     return false
  76. end
  77.  
  78.  
  79. -- Level 2 --
  80. local function filter(speakerName, message)
  81.     --gets the reason. reason will equal nil if there isn't one.
  82.     local reason = messageSus(message)
  83.     if reason then
  84.         --Tells chat service the message is a cmd. This removes the message and runs code below (but above the "return true" line).
  85.        
  86.         --[OPTIONAL] ADD YOUR CODE HERE (code here will run if a player with Name speakerName says a message that fails your filter)
  87.         print(speakerName.."'s message (\""..message.."\") was removed because it was classifed as "..reason.."!")
  88.        
  89.         return true
  90.     end
  91.     return false
  92. end
  93.  
  94.  
  95. -- Level 1 --
  96. local function runChatModule(ChatService)
  97.     ChatService:RegisterProcessCommandsFunction(functionId, filter)
  98. end
  99.  
  100. return runChatModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement