player_part.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- This file is licensed under the terms of the BSD 2-clause license.
  2. -- See LICENSE.txt for details.
  3. function irc.player_part(name)
  4. if not irc.joined_players[name] then
  5. return false, "You are not in the channel"
  6. end
  7. irc.joined_players[name] = nil
  8. return true, "You left the channel"
  9. end
  10. function irc.player_join(name)
  11. if irc.joined_players[name] then
  12. return false, "You are already in the channel"
  13. end
  14. irc.joined_players[name] = true
  15. return true, "You joined the channel"
  16. end
  17. minetest.register_chatcommand("join", {
  18. description = "Join the IRC channel",
  19. privs = {shout=true},
  20. func = function(name)
  21. return irc.player_join(name)
  22. end
  23. })
  24. minetest.register_chatcommand("part", {
  25. description = "Part the IRC channel",
  26. privs = {shout=true},
  27. func = function(name)
  28. return irc.player_part(name)
  29. end
  30. })
  31. minetest.register_chatcommand("who", {
  32. description = "Tell who is currently on the channel",
  33. privs = {},
  34. func = function()
  35. local out, n = { }, 0
  36. for plname in pairs(irc.joined_players) do
  37. n = n + 1
  38. out[n] = plname
  39. end
  40. table.sort(out)
  41. return true, "Players in channel: "..table.concat(out, ", ")
  42. end
  43. })
  44. minetest.register_on_joinplayer(function(player)
  45. local name = player:get_player_name()
  46. irc.joined_players[name] = irc.config.auto_join
  47. end)
  48. minetest.register_on_leaveplayer(function(player)
  49. local name = player:get_player_name()
  50. irc.joined_players[name] = nil
  51. end)
  52. function irc.sendLocal(message)
  53. for name, _ in pairs(irc.joined_players) do
  54. minetest.chat_send_player(name, message)
  55. end
  56. irc.logChat(message)
  57. end