forked from minetest-mods/irc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.lua
51 lines (42 loc) · 1.21 KB
/
callback.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- This file is licensed under the terms of the BSD 2-clause license.
-- See LICENSE.txt for details.
minetest.register_on_joinplayer(function(player)
local name = "unknown-net-error"
if not player then
name = "unknown-net-error"
else
name = player:get_player_name()
end
if irc.connected and irc.config.send_join_part then
irc.say("*** "..name.." joined the game")
end
end)
minetest.register_on_leaveplayer(function(player, timed_out)
local name = "unknown-net-error"
if not player then
name = "unknown-net-error"
else
name = player:get_player_name()
end
if irc.connected and irc.config.send_join_part then
irc.say("*** "..name.." left the game"..
(timed_out and " (Timed out)" or ""))
end
end)
minetest.register_on_chat_message(function(name, message)
if not irc.connected
or message:sub(1, 1) == "/"
or message:sub(1, 5) == "[off]"
or not irc.joined_players[name]
or (not minetest.check_player_privs(name, {shout=true})) then
return
end
local nl = message:find("\n", 1, true)
if nl then
message = message:sub(1, nl - 1)
end
irc.say(irc.playerMessage(name, minetest.strip_colors(message)))
end)
minetest.register_on_shutdown(function()
irc.disconnect("Game shutting down.")
end)