-
Notifications
You must be signed in to change notification settings - Fork 0
/
pm.lua
65 lines (58 loc) · 2.22 KB
/
pm.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local C = minetest.colorize
local player_last_messaged = {}
core.register_chatcommand("msg",
{
params = "<name> <message>",
description = "Send a direct message to a player",
privs = {shout=true},
func = function(name, param)
local sendto, message = param:match("^(%S+)%s(.+)$")
if not sendto then
return false, "Invalid usage, see /help msg."
end
local sendto_obj = core.get_player_by_name(sendto)
if not sendto_obj then
return false, "The player " .. sendto .. " is not online."
end
sendto = sendto_obj:get_player_name()
player_last_messaged[name] = sendto
player_last_messaged[sendto] = player_last_messaged[sendto] or name
local color_from = civchat.get_player_name_color(name) or "#f0f"
local color_sendto = civchat.get_player_name_color(sendto) or "#f0f"
core.chat_send_player(
sendto,
C("#f0f", "From ") .. C(color_from, name)
.. C("#f0f", ": " .. message)
)
return true, C("#f0f", "To ") .. C(color_sendto, sendto)
.. C("#f0f", ": " .. message)
end,
})
core.register_chatcommand("r",
{
params = "<message>",
description = "Send a direct message to the last player messaged",
privs = {shout=true},
func = function(name, param)
local message = param
local sendto = player_last_messaged[name]
if not sendto then
return false, "You have not messaged someone."
end
if not message or message == "" then
return false, "Cannot send an empty message."
end
if not core.get_player_by_name(sendto) then
return false, "The player " .. sendto .. " is not online."
end
local color_from = civchat.get_player_name_color(name) or "#f0f"
local color_sendto = civchat.get_player_name_color(sendto) or "#f0f"
core.chat_send_player(
sendto,
C("#f0f", "From ") .. C(color_from, name)
.. C("#f0f", ": " .. message)
)
return true, C("#f0f", "To ") .. C(color_sendto, sendto)
.. C("#f0f", ": " .. message)
end,
})