irc_modpack/irc/player_part.lua

73 lines
1.7 KiB
Lua
Raw Normal View History

2015-09-17 20:51:25 +02:00
-- This file is licensed under the terms of the BSD 2-clause license.
-- See LICENSE.txt for details.
function irc.player_part(name)
if not irc.joined_players[name] then
return false, "You are not in the channel"
2015-09-17 20:51:25 +02:00
end
irc.joined_players[name] = nil
return true, "You left the channel"
2015-09-17 20:51:25 +02:00
end
2015-09-23 20:54:57 +02:00
function irc.player_join(name)
if irc.joined_players[name] then
return false, "You are already in the channel"
elseif not minetest.get_player_by_name(name) then
return false, "You need to be in-game to join the channel"
2015-09-17 20:51:25 +02:00
end
irc.joined_players[name] = true
return true, "You joined the channel"
2015-09-17 20:51:25 +02:00
end
minetest.register_chatcommand("join", {
description = "Join the IRC channel",
privs = {shout=true},
func = function(name)
return irc.player_join(name)
2015-09-17 20:51:25 +02:00
end
})
2015-09-23 20:54:57 +02:00
2015-09-17 20:51:25 +02:00
minetest.register_chatcommand("part", {
description = "Part the IRC channel",
privs = {shout=true},
func = function(name)
return irc.player_part(name)
2015-09-17 20:51:25 +02:00
end
})
2015-09-23 20:54:57 +02:00
2015-09-17 20:51:25 +02:00
minetest.register_chatcommand("who", {
description = "Tell who is currently on the channel",
privs = {},
func = function()
local out, n = { }, 0
for plname in pairs(irc.joined_players) do
n = n + 1
out[n] = plname
2015-09-17 20:51:25 +02:00
end
table.sort(out)
return true, "Players in channel: "..table.concat(out, ", ")
2015-09-17 20:51:25 +02:00
end
})
2015-09-23 20:54:57 +02:00
2015-09-17 20:51:25 +02:00
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
irc.joined_players[name] = irc.config.auto_join
end)
2015-09-23 20:54:57 +02:00
2015-09-17 20:51:25 +02:00
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
irc.joined_players[name] = nil
end)
function irc.sendLocal(message)
for name, _ in pairs(irc.joined_players) do
minetest.chat_send_player(name,
minetest.colorize(irc.config.chat_color, message))
2015-09-17 20:51:25 +02:00
end
irc.logChat(message)
2015-09-17 20:51:25 +02:00
end