callback.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. -- This file is licensed under the terms of the BSD 2-clause license.
  2. -- See LICENSE.txt for details.
  3. minetest.register_on_joinplayer(function(player)
  4. local name = player:get_player_name()
  5. if irc.connected and irc.config.send_join_part then
  6. irc.say("*** "..name.." joined the game")
  7. end
  8. end)
  9. minetest.register_on_leaveplayer(function(player, timed_out)
  10. local name = player:get_player_name()
  11. if irc.connected and irc.config.send_join_part then
  12. irc.say("*** "..name.." left the game"..
  13. (timed_out and " (Timed out)" or ""))
  14. end
  15. end)
  16. minetest.register_on_chat_message(function(name, message)
  17. if not irc.connected
  18. or message:sub(1, 1) == "/"
  19. or message:sub(1, 5) == "[off]"
  20. or not irc.joined_players[name]
  21. or (not minetest.check_player_privs(name, {shout=true})) then
  22. return
  23. end
  24. local nl = message:find("\n", 1, true)
  25. if nl then
  26. message = message:sub(1, nl - 1)
  27. end
  28. irc.say(irc.playerMessage(name, core.strip_colors(message)))
  29. end)
  30. minetest.register_on_shutdown(function()
  31. irc.disconnect("Game shutting down.")
  32. end)