Advertisement
SpookyPastes

Chat spy

Oct 23rd, 2022 (edited)
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.20 KB | None | 0 0
  1. -- // Initialise
  2. --if (getgenv().ChatSpy) then return getgenv().ChatSpy; end;
  3. repeat wait() until game:GetService("ContentProvider").RequestQueueSize == 0;
  4. repeat wait() until game:IsLoaded();
  5.  
  6. -- // Vars
  7. local Players = game:GetService("Players");
  8. local StarterGui = game:GetService("StarterGui");
  9. local ReplicatedStorage = game:GetService("ReplicatedStorage");
  10. local LocalPlayer = Players.LocalPlayer;
  11. local PlayerGui = LocalPlayer:WaitForChild("PlayerGui");
  12. local DefaultChatSystemChatEvents = ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents");
  13. local SayMessageRequest = DefaultChatSystemChatEvents:WaitForChild("SayMessageRequest");
  14. local OnMessageDoneFiltering = DefaultChatSystemChatEvents:WaitForChild("OnMessageDoneFiltering");
  15. getgenv().ChatSpy = {
  16.     Enabled = true,
  17.     SpyOnSelf = false,
  18.     Public = false,
  19.     Chat = {
  20.         Colour  = Color3.fromRGB(255, 0, 0),
  21.         Font = Enum.Font.SourceSans,
  22.         TextSize = 18,
  23.         Text = "",
  24.     },
  25.     IgnoreList = {
  26.         {Message = ":part/1/1/1", ExactMatch = true},
  27.         {Message = ":part/10/10/10", ExactMatch = true},
  28.         {Message = "A?????????", ExactMatch = false},
  29.         {Message = ":colorshifttop 10000 0 0", ExactMatch = true},
  30.         {Message = ":colorshiftbottom 10000 0 0", ExactMatch = true},
  31.         {Message = ":colorshifttop 0 10000 0", ExactMatch = true},
  32.         {Message = ":colorshiftbottom 0 10000 0", ExactMatch = true},
  33.         {Message = ":colorshifttop 0 0 10000", ExactMatch = true},
  34.         {Message = ":colorshiftbottom 0 0 10000", ExactMatch = true},
  35.     },
  36. };
  37.  
  38. -- // Function
  39. function ChatSpy.checkIgnored(message)
  40.     for i = 1, #ChatSpy.IgnoreList do
  41.         local v = ChatSpy.IgnoreList[i];
  42.         if (v.ExactMatch and message == v.Message) or (not v.ExactMatch and string.match(v.Message, message)) then
  43.             return true;
  44.         end;
  45.     end;
  46.     return false;
  47. end;
  48.  
  49. function ChatSpy.onChatted(targetPlayer, message)
  50.     if (targetPlayer == LocalPlayer and string.lower(message):sub(1, 4) == "/spy") then
  51.         ChatSpy.Enabled = not ChatSpy.Enabled; wait(0.3);
  52.         ChatSpy.Chat.Text = "[SPY] - "..(ChatSpy.Enabled and "Enabled." or "Disabled.");
  53.  
  54.         StarterGui:SetCore("ChatMakeSystemMessage", ChatSpy.Chat);
  55.     elseif (ChatSpy.Enabled and (ChatSpy.SpyOnSelf or targetPlayer ~= LocalPlayer)) then
  56.         local message = message:gsub("[\n\r]",''):gsub("\t",' '):gsub("[ ]+",' ');
  57.  
  58.         local Hidden = true;
  59.         local Connection = OnMessageDoneFiltering.OnClientEvent:Connect(function(packet, channel)
  60.             if (packet.SpeakerUserId == targetPlayer.UserId and packet.Message == message:sub(#message - #packet.Message + 1) and (channel == "All" or (channel == "Team" and not ChatSpy.Public and Players[packet.FromSpeaker].Team == LocalPlayer.Team))) then
  61.                 Hidden = false;
  62.             end;
  63.         end);
  64.  
  65.         wait(1);
  66.         Connection:Disconnect();
  67.  
  68.         if (Hidden and ChatSpy.Enabled and not ChatSpy.checkIgnored(message)) then
  69.             if (#message > 1200) then
  70.                 message = message:sub(1200) .. "...";
  71.             end;
  72.             ChatSpy.Chat.Text = "[SPY] - ["..targetPlayer.Name.."]: " .. message;
  73.             if (ChatSpy.Public) then SayMessageRequest:FireServer(ChatSpy.Chat.Text, "All"); else StarterGui:SetCore("ChatMakeSystemMessage", ChatSpy.Chat); end;
  74.         end;
  75.     end;
  76. end;
  77.  
  78. -- // Handling Chats
  79. local AllPlayers = Players:GetPlayers();
  80. for i = 1, #AllPlayers do
  81.     local player = AllPlayers[i];
  82.     player.Chatted:Connect(function(message)
  83.         ChatSpy.onChatted(player, message);
  84.     end);
  85. end;
  86.  
  87. Players.PlayerAdded:Connect(function(player)
  88.     player.Chatted:Connect(function(message)
  89.         ChatSpy.onChatted(player, message);
  90.     end);
  91. end);
  92.  
  93. -- // Initialise Text
  94. ChatSpy.Chat.Text = "[SPY] - "..(ChatSpy.Enabled and "Enabled." or "Disabled.");
  95. StarterGui:SetCore("ChatMakeSystemMessage", ChatSpy.Chat);
  96.  
  97. -- // Update Chat Frame
  98. local chatFrame = LocalPlayer.PlayerGui.Chat.Frame;
  99. chatFrame.ChatChannelParentFrame.Visible = true;
  100. chatFrame.ChatBarParentFrame.Position = chatFrame.ChatChannelParentFrame.Position + UDim2.new(UDim.new(), chatFrame.ChatChannelParentFrame.Size.Y);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement