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