Advertisement
Icesythe7

ChatBlock by Icesythe7/Genericmage

May 18th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. ChatBlockDB = {}
  2.  
  3. local function Say(msg)
  4.     DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8300ChatBlock:|r".." ".."|cFF25DCE0"..msg.."|r")
  5. end
  6.  
  7. function table.contains(table, word)
  8.     for k, v in pairs(table) do
  9.         if v == word then
  10.             return true
  11.         end
  12.     end
  13.     return false
  14. end
  15.  
  16. function table.wipe(table)
  17.     for k, v in pairs(table) do
  18.         (table)[k] = nil
  19.     end
  20. end
  21.  
  22. function HideIt(message)
  23.     if message ~= nil then
  24.         local msgLower = string.lower(message)
  25.         for k, v in pairs(ChatBlockDB) do
  26.             if msgLower:match(v) then
  27.                 return true
  28.             end
  29.         end
  30.     end
  31. end
  32.  
  33. ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", HideIt)
  34.  
  35. SLASH_CB1 = "/cb"
  36. SlashCmdList["CB"] = function(msg, editbox)
  37.     local command, rest = msg:match("^(%S*)%s*(.-)$")
  38.     if command == "add" and rest ~= "" then
  39.         if table.contains(ChatBlockDB, rest) then
  40.             Say('The word "' ..rest.. '" already exists in the DataBase!')
  41.         else
  42.             table.insert(ChatBlockDB, rest)
  43.             Say('The word "' ..rest.. '" has been added to the DataBase!')
  44.         end
  45.     elseif command == "remove" and rest ~= "" then
  46.         if table.contains(ChatBlockDB, rest) then
  47.             for k, v in pairs(ChatBlockDB) do
  48.                 if v == rest then
  49.                     table.remove(ChatBlockDB, k)
  50.                     Say('The word "' ..rest.. '" has been removed from the DataBase!')
  51.                 end
  52.             end
  53.         else
  54.             Say('The word "' ..rest.. '" does not exist in the DataBase!')
  55.         end
  56.     elseif command == "list" and rest == "" then
  57.         if #ChatBlockDB > 0 then
  58.             for k, v in pairs(ChatBlockDB) do
  59.                 Say(v)
  60.             end
  61.         else
  62.             Say('No words have been added to the DataBase yet!')
  63.         end
  64.     elseif command == "wipe" and rest == "" then
  65.         if #ChatBlockDB > 0 then
  66.             table.wipe(ChatBlockDB)
  67.             Say('The DataBase has been cleared!')
  68.         else
  69.             Say('No words have been added to the DataBase yet!')
  70.         end
  71.     elseif command == "help" and rest == "" then
  72.         Say('Syntax: /cb add/remove "word" (add/removes a word from the list.)')
  73.         Say('Syntax: /cb list (Shows a list of currently blocked words.)')
  74.         Say('Syntax: /cb wipe (Removes all words from the DataBase.)')
  75.     else
  76.         Say('Syntax: /cb help (For a list of options.)')
  77.     end
  78. end
  79.  
  80. Say('by "Genericmage" loaded!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement