Advertisement
osmarks

PotatOS Chat Monitor

Apr 10th, 2020
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.21 KB | None | 0 0
  1. if not process.info "chatd" and _G.switchcraft then
  2.     process.spawn(chatbox.run, "chatd")
  3. end
  4. local server = settings.get "server"
  5. if _G.switchcraft then server = "switchcraft" end
  6. local chatbox = _G.chatbox or peripheral.find "chat_box"
  7.  
  8. local data = persistence "pcm"
  9. if not data.blasphemy_counts then data.blasphemy_counts = {} end
  10.  
  11. local potatOS_supporters = {
  12.     gollark = true,
  13.     ["6_4"] = true
  14. }
  15.  
  16. local clause_separators = {".", ",", '"', "'", "`", "and", "!", "?", ":", ";", "-"}
  17.  
  18. local negative_words_list = "abysmal awful appalling atrocious bad boring belligerent banal broken callous crazy cruel corrosive corrupt criminal contradictory confused damaging dismal dreadful deprived deplorable dishonest disease detrimental dishonorable dreary evil enrage fail foul faulty filthy frightful fight gross ghastly grim guilty grotesque grimace haggard harmful horrendous hostile hate horrible hideous icky immature infernal insane inane insidious insipid inelegant junk lousy malicious malware messy monstrous menacing missing nasty negative nonsense naughty odious offensive oppressive objectionable petty poor poisonous questionable reject reptilian rotten repugnant repulsive ruthless scary shocking sad sickening stupid spiteful stormy smelly suspicious shoddy sinister substandard severe stuck threatening terrifying tense ugly unwanted unsatisfactory unwieldy unsightly unwelcome unfair unhealthy unpleasant untoward vile villainous vindictive vicious wicked worthless insecure bug virus sucks dodecahedr worse" .. " sh" .. "it " .. "cr" .. "ap"
  19. local negative_words = negative_words_list / " "
  20. local ignore_if_present_words = "greenhouse not garden these support bounty debug antivirus n't" / " "
  21.  
  22. function _G.is_blasphemous(message)
  23.     local clauses = {message:lower()}
  24.     for _, sep in pairs(clause_separators) do
  25.         local out = {}
  26.         for _, x in pairs(clauses) do
  27.             for _, y in pairs(string.split(x, sep)) do
  28.                 table.insert(out, y)
  29.             end
  30.         end
  31.         clauses = out
  32.     end
  33.     for _, clause in pairs(clauses) do
  34.         for _, word in pairs(negative_words) do
  35.             if clause:match(word) and clause:match "potatos" then
  36.                 for _, iword in pairs(ignore_if_present_words) do
  37.                     if clause:match(iword) then return false, iword, clause end
  38.                 end
  39.                 return true, word, clause
  40.             end
  41.         end
  42.     end
  43.     return false
  44. end
  45.  
  46. while true do
  47.     local ev, user, message, mdata = os.pullEvent()
  48.     if ev == "chat" or ev == "chat_discord" then
  49.         local blasphemous, word, clause = is_blasphemous(message)
  50.         if blasphemous then
  51.             if mdata then
  52.                 mdata.renderedText = nil
  53.             end
  54.             data.blasphemy_counts[user] = (data.blasphemy_counts[user] or 0) + 1
  55.             data.save()
  56.             print("BLASPHEMY from", user, "-", message, word, clause)
  57.             potatOS.report_incident(("blasphemy from %s"):format(user), {"blasphemy"}, {
  58.                 disable_host_data = true,
  59.                 ID = os.getComputerID(),
  60.                 extra_meta = {
  61.                     message_data = mdata,
  62.                     user = user,
  63.                     message = message,
  64.                     server = server,
  65.                     blasphemy_count = data.blasphemy_counts[user]
  66.                 }
  67.             })
  68.         end
  69.     elseif ev == "command" and message == "blasphemy_count" then
  70.         print(user, "requested count")
  71.         chatbox.tell(user, ("Blasphemy count: %d"):format(data.blasphemy_counts[user] or 0), "PCM")
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement