Advertisement
miekokawakami

Hexchat irchighway ebooks chat filter

Feb 11th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | Source Code | 0 0
  1. local name = "ebookspam.lua"
  2. local desc = "mitigate chat spam in #ebooks on IRCHighWay"
  3. local version = "0.5"
  4.  
  5. hexchat.register(name, version, desc)
  6.  
  7. -- grey color and also the token used to identify filtered text
  8. local c0 = "\00323"
  9.  
  10. -- search patterns
  11. local pat_searchook = "^@[Ss]earchook"
  12. local pat_find = "^@[Ff]ind"
  13. local pat_search = "^@[Ss]earch"
  14.  
  15. local function cm_print(args)
  16.     hexchat.emit_print("Channel Message", args[1], args[2], args[3], args[4])
  17. end
  18.  
  19. local function cm_print_grey(args)
  20.     args[2] = c0 .. args[2]
  21.     cm_print(args)
  22. end
  23.  
  24. local function cm_print_stripped(args)
  25.     args[2] = c0 .. hexchat.strip(args[2])
  26.     cm_print(args)
  27. end
  28.  
  29. -- highlight search terms, change c1 to modify highlight color
  30. local function cm_print_search(args)
  31.     local c1 = "\00324"
  32.     args[2] = hexchat.strip(args[2])
  33.     if args[2]:find(pat_searchook) then
  34.         args[2] = args[2]:gsub(pat_searchook, "@searchook" .. c1)
  35.     elseif args[2]:find(pat_find) then
  36.         args[2] = args[2]:gsub(pat_find, "@find" .. c1)
  37.     else
  38.         args[2] = args[2]:gsub(pat_search, "@search" .. c1)
  39.     end
  40.     args[2] = c0 .. args[2]
  41.     cm_print(args)
  42. end
  43.  
  44. local function cm_cbk(args)
  45.     if args[2]:find("^" .. c0) then
  46.         return hexchat.EAT_NONE
  47.     elseif args[2]:find(pat_search) or args[2]:find(pat_find) then  -- search syntax
  48.         cm_print_search(args)
  49.         return hexchat.EAT_ALL
  50.     elseif args[2]:find("^@") or args[2]:find("^!") then  -- misc spam and download requests
  51.         cm_print_grey(args)
  52.         return hexchat.EAT_ALL
  53.     elseif args[2]:find("[Tt]ype.*@") or args[2]:find("dlFilter") then  -- bot spam
  54.         cm_print_stripped(args)
  55.         return hexchat.EAT_ALL
  56.     end
  57.     return hexchat.EAT_NONE
  58. end
  59.  
  60. local function ctcp_print(args)
  61.     args[1] = hexchat.strip(args[1])
  62.     args[1] = c0 .. args[1]
  63.     hexchat.emit_print("CTCP Generic to Channel", args[1], args[2], args[3])
  64. end
  65.  
  66. local function ctcp_cbk(args)
  67.     if args[1]:find("^" .. c0) then
  68.         return hexchat.EAT_NONE
  69.     elseif args[1]:find("OmenServe") or args[1]:find("FWServer") then
  70.         ctcp_print(args)
  71.         return hexchat.EAT_ALL
  72.     end
  73.     return hexchat.EAT_NONE
  74. end
  75.  
  76. local help = ""
  77.  
  78. hexchat.hook_print("Channel Message", cm_cbk)
  79. hexchat.hook_print("CTCP Generic to Channel", ctcp_cbk)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement