summaryrefslogtreecommitdiff
path: root/chatcommands.lua
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2025-12-13 19:25:48 -0600
committercheapie <no-email-for-you@example.com>2025-12-13 19:27:24 -0600
commitf885c04e95cf9291330a42ceb0612dd3568ac7c7 (patch)
treeec234363aacb95490fd3ca89287e62e8b0998d72 /chatcommands.lua
parent8869adfb33e0c0109dad606331fe239b1af6e75f (diff)
downloadcelevator-f885c04e95cf9291330a42ceb0612dd3568ac7c7.tar
celevator-f885c04e95cf9291330a42ceb0612dd3568ac7c7.tar.gz
celevator-f885c04e95cf9291330a42ceb0612dd3568ac7c7.tar.bz2
celevator-f885c04e95cf9291330a42ceb0612dd3568ac7c7.tar.xz
celevator-f885c04e95cf9291330a42ceb0612dd3568ac7c7.zip
Add translation support and rudimentary Spanish locale
Diffstat (limited to 'chatcommands.lua')
-rw-r--r--chatcommands.lua86
1 files changed, 44 insertions, 42 deletions
diff --git a/chatcommands.lua b/chatcommands.lua
index 53829e7..eacb4f0 100644
--- a/chatcommands.lua
+++ b/chatcommands.lua
@@ -1,62 +1,64 @@
+local S = core.get_translator("celevator")
+
core.register_chatcommand("carcall",{
- description = "Places a car call at the specified landing on the specified elevator",
- params = "<car ID> <landing number>",
+ description = S("Places a car call at the specified landing on the specified elevator"),
+ params = S("<car ID> <landing number>"),
func = function(name,param)
local carid,landing = string.match(param,"(%d+) (%d+)")
if not (carid and tonumber(carid)) then
- return false,"Invalid car ID"
+ return false,S("Invalid car ID")
end
if not (landing and tonumber(landing)) then
- return false,"Invalid landing number"
+ return false,S("Invalid landing number")
end
local carinfo = core.deserialize(celevator.storage:get_string("car"..carid))
if not (carinfo and carinfo.controllerpos) then
- return false,"No such car or car info is missing"
+ return false,S("No such car or car info is missing")
end
if not celevator.controller.iscontroller(carinfo.controllerpos) then
- return false,"Controller is missing"
+ return false,S("Controller is missing")
end
if celevator.get_meta(carinfo.controllerpos):get_int("carid") ~= tonumber(carid) then
- return false,"Controller found but with wrong ID"
+ return false,S("Controller found but with wrong ID")
end
if core.is_protected(carinfo.controllerpos,name) then
core.record_protection_violation(carinfo.controllerpos,name)
- return false,"Controller is protected"
+ return false,S("Controller is protected")
end
celevator.controller.run(carinfo.controllerpos,{
type = "remotemsg",
channel = "carcall",
msg = tonumber(landing),
})
- return true,"Command sent"
+ return true,S("Command sent")
end,
})
core.register_chatcommand("upcall",{
- description = "Places an up hall call at the specified landing on the specified elevator or dispatcher",
- params = "<car ID> <landing number>",
+ description = S("Places an up hall call at the specified landing on the specified elevator or dispatcher"),
+ params = S("<car ID> <landing number>"),
func = function(name,param)
local carid,landing = string.match(param,"(%d+) (%d+)")
if not (carid and tonumber(carid)) then
- return false,"Invalid car ID"
+ return false,S("Invalid car ID")
end
if not (landing and tonumber(landing)) then
- return false,"Invalid landing number"
+ return false,S("Invalid landing number")
end
local carinfo = core.deserialize(celevator.storage:get_string("car"..carid))
if not (carinfo and (carinfo.controllerpos or carinfo.dispatcherpos)) then
- return false,"No such car or car info is missing"
+ return false,S("No such car or car info is missing")
end
if carinfo.controllerpos then
if not celevator.controller.iscontroller(carinfo.controllerpos) then
- return false,"Controller is missing"
+ return false,S("Controller is missing")
end
if celevator.get_meta(carinfo.controllerpos):get_int("carid") ~= tonumber(carid) then
- return false,"Controller found but with wrong ID"
+ return false,S("Controller found but with wrong ID")
end
if core.is_protected(carinfo.controllerpos,name) then
core.record_protection_violation(carinfo.controllerpos,name)
- return false,"Controller is protected"
+ return false,S("Controller is protected")
end
--One of these will work depending on the mode, the other will be ignored
celevator.controller.run(carinfo.controllerpos,{
@@ -69,53 +71,53 @@ core.register_chatcommand("upcall",{
channel = "swingupcall",
msg = tonumber(landing),
})
- return true,"Command sent"
+ return true,S("Command sent")
elseif carinfo.dispatcherpos then
if not celevator.dispatcher.isdispatcher(carinfo.dispatcherpos) then
- return false,"Dispatcher is missing"
+ return false,S("Dispatcher is missing")
end
if celevator.get_meta(carinfo.dispatcherpos):get_int("carid") ~= tonumber(carid) then
- return false,"Dispatcher found but with wrong ID"
+ return false,S("Dispatcher found but with wrong ID")
end
if core.is_protected(carinfo.dispatcherpos,name) then
core.record_protection_violation(carinfo.dispatcherpos,name)
- return false,"Dispatcher is protected"
+ return false,S("Dispatcher is protected")
end
celevator.dispatcher.run(carinfo.dispatcherpos,{
type = "remotemsg",
channel = "upcall",
msg = tonumber(landing),
})
- return true,"Command sent"
+ return true,S("Command sent")
end
end,
})
core.register_chatcommand("downcall",{
- description = "Places a down hall call at the specified landing on the specified elevator or dispatcher",
- params = "<car ID> <landing number>",
+ description = S("Places a down hall call at the specified landing on the specified elevator or dispatcher"),
+ params = S("<car ID> <landing number>"),
func = function(name,param)
local carid,landing = string.match(param,"(%d+) (%d+)")
if not (carid and tonumber(carid)) then
- return false,"Invalid car ID"
+ return false,S("Invalid car ID")
end
if not (landing and tonumber(landing)) then
- return false,"Invalid landing number"
+ return false,S("Invalid landing number")
end
local carinfo = core.deserialize(celevator.storage:get_string("car"..carid))
if not (carinfo and (carinfo.controllerpos or carinfo.dispatcherpos)) then
- return false,"No such car or car info is missing"
+ return false,S("No such car or car info is missing")
end
if carinfo.controllerpos then
if not celevator.controller.iscontroller(carinfo.controllerpos) then
- return false,"Controller is missing"
+ return false,S("Controller is missing")
end
if celevator.get_meta(carinfo.controllerpos):get_int("carid") ~= tonumber(carid) then
- return false,"Controller found but with wrong ID"
+ return false,S("Controller found but with wrong ID")
end
if core.is_protected(carinfo.controllerpos,name) then
core.record_protection_violation(carinfo.controllerpos,name)
- return false,"Controller is protected"
+ return false,S("Controller is protected")
end
--One of these will work depending on the mode, the other will be ignored
celevator.controller.run(carinfo.controllerpos,{
@@ -128,49 +130,49 @@ core.register_chatcommand("downcall",{
channel = "swingdncall",
msg = tonumber(landing),
})
- return true,"Command sent"
+ return true,S("Command sent")
elseif carinfo.dispatcherpos then
if not celevator.dispatcher.isdispatcher(carinfo.dispatcherpos) then
- return false,"Dispatcher is missing"
+ return false,S("Dispatcher is missing")
end
if celevator.get_meta(carinfo.dispatcherpos):get_int("carid") ~= tonumber(carid) then
- return false,"Dispatcher found but with wrong ID"
+ return false,S("Dispatcher found but with wrong ID")
end
if core.is_protected(carinfo.dispatcherpos,name) then
core.record_protection_violation(carinfo.dispatcherpos,name)
- return false,"Dispatcher is protected"
+ return false,S("Dispatcher is protected")
end
celevator.dispatcher.run(carinfo.dispatcherpos,{
type = "remotemsg",
channel = "dncall",
msg = tonumber(landing),
})
- return true,"Command sent"
+ return true,S("Command sent")
end
end,
})
core.register_chatcommand("elevstatus",{
- description = "View the status of the specified elevator",
- params = "<car ID>",
+ description = S("View the status of the specified elevator"),
+ params = S("<car ID>"),
func = function(_,param)
if not (param and tonumber(param)) then
- return false,"Invalid car ID"
+ return false,S("Invalid car ID")
end
local carinfo = core.deserialize(celevator.storage:get_string("car"..param))
if not (carinfo and carinfo.controllerpos) then
- return false,"No such car or car info is missing"
+ return false,S("No such car or car info is missing")
end
if not celevator.controller.iscontroller(carinfo.controllerpos) then
- return false,"Controller is missing"
+ return false,S("Controller is missing")
end
local controllermeta = celevator.get_meta(carinfo.controllerpos)
if controllermeta:get_int("carid") ~= tonumber(param) then
- return false,"Controller found but with wrong ID"
+ return false,S("Controller found but with wrong ID")
end
local mem = core.deserialize(controllermeta:get_string("mem"))
if not mem then
- return false,"Failed to load controller memory"
+ return false,S("Failed to load controller memory")
end
local infotext = controllermeta:get_string("infotext")
if mem.drive and mem.drive.status and mem.drive.status.vel and mem.drive.status.apos then