Page 1 of 1

[Help Needed] Spam blocker

PostPosted: Fri Aug 10, 2012 21:23
by rubenwardy
I want to make a server side mod that will read users posts and see if it contains any banned words or is too long (over 1 line)

If it is the player will either recieve a caution or will have shout priv removed.

What i need to do:

1) Register chat send (is there a function for this?)

2) Check if the string contains/contains excessivly ammounts of keywords (strfind (str, substr, [init, [end]])?)

3) Deal punishment accordingly. (something like server.banprivs(player,"shout");)

PostPosted: Fri Aug 10, 2012 21:27
by sfan5
1) yes
3) you mean revoking shout privs

PostPosted: Sat Aug 11, 2012 10:33
by PilzAdam
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_chat_message(function(name, message)
  local bool = false
  for _,str in ipairs(unalowed_strings) do
    if string.find(message, str) then
      bool = true
      break
    end
  end
  if bool then
    local privs = minetest.get_player_privs(name)
    privs.shout = false
    minetest.set_player_privs(name, privs)
  end
end)

You only have to define a table like this (over the function):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local unalowed_strings = {"Minecraft", "shit"}


Warning: This code is untested.

PostPosted: Sat Aug 11, 2012 10:38
by Topywo
PilzAdam wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local unalowed_strings = {"Minecraft", "shit"}


Lol

PostPosted: Mon Aug 13, 2012 16:33
by rubenwardy
Thank you.

Is there a way to cancel the chat message?

PostPosted: Mon Aug 13, 2012 17:19
by rubenwardy
Here is the code:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local unalowed_strings = {"Minecraft", "shit"}

minetest.register_on_chat_message(function(name, message)
    local count = 0
    for _,str in ipairs(unalowed_strings) do
        if string.find(message, str) then
            count = count +1
            print("SpamBlocker: Banned word found")
        end
    end

    print(string.len(message))

     if string.len(message)>100 then
        print("SpamBlocker: Bigger than allowed")
           count=100
    end

    if count > 2 then
        local privs = minetest.get_player_privs(name)
        privs.shout = false
        minetest.set_player_privs(name, privs)
        print("SpamBlocker: Players privs taken away")
    end
end)