From 60c7c2c60bd5ea99acd2ced72f7c520dfd16be35 Mon Sep 17 00:00:00 2001 From: Er2 Date: Tue, 27 Jul 2021 11:15:28 +0300 Subject: [PATCH] bugfixes --- etc/api/core.lua | 2 +- src/cmds/rub.lua | 2 +- src/events/command.lua | 11 +++++++---- src/parts/locale.lua | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/etc/api/core.lua b/etc/api/core.lua index 73c73f4..ec0860f 100644 --- a/etc/api/core.lua +++ b/etc/api/core.lua @@ -38,7 +38,7 @@ local function receiveUpdate(self, update) and not to then return end local args = {} - txt = msg.text:sub(#cmd + #(to or {}) + 3) + msg.text = msg.text:sub(#cmd + #(to or '') + 3) for s in msg.text:gmatch '%S+' do table.insert(args, s) end msg.cmd = cmd diff --git a/src/cmds/rub.lua b/src/cmds/rub.lua index 8c7b1c1..21304b7 100644 --- a/src/cmds/rub.lua +++ b/src/cmds/rub.lua @@ -44,7 +44,7 @@ return { local v, d, f = rub:course(wants) if v == 'error' then - return C.api:reply(msg, C.locale:get('error', 'req_err')) + return C.api:reply(msg, C.locale:get('error', 'req_err', msg.l)) end local nf = {} diff --git a/src/events/command.lua b/src/events/command.lua index 73e26a4..3b24a28 100644 --- a/src/events/command.lua +++ b/src/events/command.lua @@ -1,18 +1,21 @@ return function(C, api, msg) local cmd = C.cmds[msg.cmd] local owner = msg.from.id == C.config.owner + local l = msg.from.language_code + + msg.l = l if cmd == nil then - api:send(msg, C.locale:get('error', 'inv_cmd')) + api:send(msg, C.locale:get('error', 'inv_cmd', l)) elseif type(cmd.run) ~= 'function' then - api:send(msg, C.locale:get('error', 'cmd_run')) + api:send(msg, C.locale:get('error', 'cmd_run', l)) elseif cmd.private and not owner then - api:send(msg, C.locale:get('error', 'adm_cmd')) + api:send(msg, C.locale:get('error', 'adm_cmd', l)) else - msg.loc = C.locale:get('cmds', msg.cmd) + msg.loc = C.locale:get('cmds', msg.cmd, l) local succ, err = pcall(cmd.run, C, msg, owner) if not succ then print(err) diff --git a/src/parts/locale.lua b/src/parts/locale.lua index f5b2bc1..9db7cda 100644 --- a/src/parts/locale.lua +++ b/src/parts/locale.lua @@ -14,10 +14,10 @@ function Locale:get(cat, k, lang) assert(k, 'Give key') lang = lang or self.main - local v = self[lang][cat][k] + local v = (self[lang] or {})[cat] if not v then - return self[self.main][cat][k] - else return v end + return self[Locale.main][cat][k] + else return v[k] end end return function(C)