irc2/player_part.lua

70 lines
1.6 KiB
Lua
Raw Normal View History

2013-04-29 15:07:44 -07:00
-- This file is licensed under the terms of the BSD 2-clause license.
-- See LICENSE.txt for details.
2019-07-24 18:53:22 -07:00
function irc2.player_part(name)
if not irc2.joined_players[name] then
return false, "You are not in the channel"
2013-04-29 15:07:44 -07:00
end
2019-07-24 18:53:22 -07:00
irc2.joined_players[name] = nil
return true, "You left the channel"
2013-04-29 15:07:44 -07:00
end
2017-02-15 21:36:04 -08:00
2019-07-24 18:53:22 -07:00
function irc2.player_join(name)
if irc2.joined_players[name] then
return false, "You are already in the channel"
2013-04-29 15:07:44 -07:00
end
2019-07-24 18:53:22 -07:00
irc2.joined_players[name] = true
return true, "You joined the channel"
2013-04-29 15:07:44 -07:00
end
minetest.register_chatcommand("join", {
description = "Join the IRC channel",
privs = {shout=true},
func = function(name)
2019-07-24 18:53:22 -07:00
return irc2.player_join(name)
2013-04-29 15:07:44 -07:00
end
})
2017-02-15 21:36:04 -08:00
2013-04-29 15:07:44 -07:00
minetest.register_chatcommand("part", {
description = "Part the IRC channel",
privs = {shout=true},
func = function(name)
2019-07-24 18:53:22 -07:00
return irc2.player_part(name)
2013-04-29 15:07:44 -07:00
end
})
2017-02-15 21:36:04 -08:00
2013-04-29 15:07:44 -07:00
minetest.register_chatcommand("who", {
description = "Tell who is currently on the channel",
privs = {},
func = function()
local out, n = { }, 0
2019-07-24 18:53:22 -07:00
for plname in pairs(irc2.joined_players) do
n = n + 1
2017-02-15 21:36:04 -08:00
out[n] = plname
2013-04-29 15:07:44 -07:00
end
table.sort(out)
return true, n.." player(s) in channel: "..table.concat(out, ", ")
2013-04-29 15:07:44 -07:00
end
})
2017-02-15 21:36:04 -08:00
2013-04-29 15:07:44 -07:00
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
2019-07-24 18:53:22 -07:00
irc2.joined_players[name] = irc2.config.auto_join
2013-04-29 15:07:44 -07:00
end)
2017-02-15 21:36:04 -08:00
2013-04-29 15:07:44 -07:00
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
2019-07-24 18:53:22 -07:00
irc2.joined_players[name] = nil
2013-04-29 15:07:44 -07:00
end)
2019-07-24 18:53:22 -07:00
function irc2.sendLocal(message)
for name, _ in pairs(irc2.joined_players) do
2019-07-24 18:42:23 -07:00
minetest.chat_send_player(name, message)
2013-04-29 15:07:44 -07:00
end
2019-07-24 18:53:22 -07:00
irc2.logChat(message)
2013-04-29 15:07:44 -07:00
end