]> git.lizzy.rs Git - minetest.git/blob - builtin/client/chatcommands.lua
[CSM] Allow escaping chatcommands and add missing calls to gettext. (#5565)
[minetest.git] / builtin / client / chatcommands.lua
1 -- Minetest: builtin/client/chatcommands.lua
2
3
4 core.register_on_sending_chat_messages(function(message)
5         if message:sub(1,2) == ".." then
6                 return false
7         end
8
9         local first_char = message:sub(1,1)
10         if first_char == "/" or first_char == "." then
11                 core.display_chat_message(core.gettext("issued command: ") .. message)
12         end
13
14         if first_char ~= "." then
15                 return false
16         end
17
18         local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
19         param = param or ""
20
21         if not cmd then
22                 core.display_chat_message(core.gettext("-!- Empty command"))
23                 return true
24         end
25
26         local cmd_def = core.registered_chatcommands[cmd]
27         if cmd_def then
28                 core.set_last_run_mod(cmd_def.mod_origin)
29                 local _, message = cmd_def.func(param)
30                 if message then
31                         core.display_chat_message(message)
32                 end
33         else
34                 core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
35         end
36
37         return true
38 end)
39
40 core.register_chatcommand("list_players", {
41         description = core.gettext("List online players"),
42         func = function(param)
43                 local players = table.concat(core.get_player_names(), ", ")
44                 core.display_chat_message(core.gettext("Online players: ") .. players)
45         end
46 })
47
48 core.register_chatcommand("disconnect", {
49         description = core.gettext("Exit to main menu"),
50         func = function(param)
51                 core.disconnect()
52         end,
53 })