]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/client/chatcommands.lua
Translate builtin (#10693)
[dragonfireclient.git] / builtin / client / chatcommands.lua
1 -- Minetest: builtin/client/chatcommands.lua
2
3 core.register_on_sending_chat_message(function(message)
4         if message:sub(1,2) == ".." then
5                 return false
6         end
7
8         local first_char = message:sub(1,1)
9         if first_char == "/" or first_char == "." then
10                 core.display_chat_message(core.gettext("Issued command: ") .. message)
11         end
12
13         if first_char ~= "." then
14                 return false
15         end
16
17         local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
18         param = param or ""
19
20         if not cmd then
21                 core.display_chat_message("-!- " .. core.gettext("Empty command."))
22                 return true
23         end
24
25         -- Run core.registered_on_chatcommand callbacks.
26         if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
27                 return true
28         end
29
30         local cmd_def = core.registered_chatcommands[cmd]
31         if cmd_def then
32                 core.set_last_run_mod(cmd_def.mod_origin)
33                 local _, result = cmd_def.func(param)
34                 if result then
35                         core.display_chat_message(result)
36                 end
37         else
38                 core.display_chat_message("-!- " .. core.gettext("Invalid command: ") .. cmd)
39         end
40
41         return true
42 end)
43
44 core.register_chatcommand("list_players", {
45         description = core.gettext("List online players"),
46         func = function(param)
47                 local player_names = core.get_player_names()
48                 if not player_names then
49                         return false, core.gettext("This command is disabled by server.")
50                 end
51
52                 local players = table.concat(player_names, ", ")
53                 return true, core.gettext("Online players: ") .. players
54         end
55 })
56
57 core.register_chatcommand("disconnect", {
58         description = core.gettext("Exit to main menu"),
59         func = function(param)
60                 core.disconnect()
61         end,
62 })
63
64 core.register_chatcommand("clear_chat_queue", {
65         description = core.gettext("Clear the out chat queue"),
66         func = function(param)
67                 core.clear_out_chat_queue()
68                 return true, core.gettext("The out chat queue is now empty.")
69         end,
70 })
71
72 function core.run_server_chatcommand(cmd, param)
73         core.send_chat_message("/" .. cmd .. " " .. param)
74 end