From 08788c827e59a3946982d7e94686ecf540e7489a Mon Sep 17 00:00:00 2001 From: Er2 Date: Sun, 13 Feb 2022 14:06:46 +0300 Subject: [PATCH 1/3] fix reload, new valute --- src/cmds/reload.lua | 1 + src/cmds/rub.lua | 9 +++++++++ src/events/ready.lua | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/cmds/reload.lua b/src/cmds/reload.lua index ee00df8..e05e8b8 100644 --- a/src/cmds/reload.lua +++ b/src/cmds/reload.lua @@ -7,6 +7,7 @@ return { end local path = 'src.'..cat..'.'..sub + C.api:off(package.loaded[path]) package.loaded[path] = nil local err, m = pcall(require, path) diff --git a/src/cmds/rub.lua b/src/cmds/rub.lua index 4a5f5aa..20e4675 100644 --- a/src/cmds/rub.lua +++ b/src/cmds/rub.lua @@ -23,6 +23,15 @@ function rub:course(wants) Name = 'Российский рубль', Value = '1' }) + local uah = table.findV(resp.Valute, {CharCode = 'UAH'}) + table.insert(resp.Valute, { + ID = 'R02000', + NumCode = '200', + CharCode = 'SHT', + Nominal = 1, + Name = 'Штаны', + Value = ('%f'):format(tonumber(uah.Value:gsub(',', '.'), nil) / uah.Nominal * 40) + }) wants = type(wants) == 'table' and wants or {} local r, founds = {}, {} diff --git a/src/events/ready.lua b/src/events/ready.lua index feac38a..41a5356 100644 --- a/src/events/ready.lua +++ b/src/events/ready.lua @@ -5,14 +5,20 @@ end function table.find(t, w) - local i - for k,v in pairs(t) do - if v == w then - i = k - break - end + for _,v in pairs(t) do + if v == w then return v end + end +end + +function table.findV(t, w) + local b + for _,v in pairs(t) do + for k,x in pairs(w) do + if x ~= v[k] then b=1; break end + end + if b then b = nil + else return v end end - return i end function dump(t, d) From 65b2f6eebccfbc7b59bd2a768e97ee51a6a18570 Mon Sep 17 00:00:00 2001 From: Er2 Date: Sun, 13 Feb 2022 14:06:46 +0300 Subject: [PATCH 2/3] fix reload, new valute --- src/cmds/reload.lua | 7 ++++--- src/cmds/rub.lua | 9 +++++++++ src/events/ready.lua | 20 +++++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/cmds/reload.lua b/src/cmds/reload.lua index ee00df8..26b0665 100644 --- a/src/cmds/reload.lua +++ b/src/cmds/reload.lua @@ -7,11 +7,12 @@ return { end local path = 'src.'..cat..'.'..sub + C.api:off(package.loaded[path]) package.loaded[path] = nil - local err, m = pcall(require, path) + local suc, m = pcall(require, path) - if not err then return C.api:reply(msg, 'Reload failed. ' .. m) - elseif cat == 'events' then C.api:off(m); C.api:on(sub, m) + if not suc then return C.api:reply(msg, 'Reload failed. ' .. m) + elseif cat == 'events' then C.api:on(sub, m) elseif cat == 'cmds' then C.cmds[sub] = m elseif cat == 'parts' then m(C) end diff --git a/src/cmds/rub.lua b/src/cmds/rub.lua index 4a5f5aa..20e4675 100644 --- a/src/cmds/rub.lua +++ b/src/cmds/rub.lua @@ -23,6 +23,15 @@ function rub:course(wants) Name = 'Российский рубль', Value = '1' }) + local uah = table.findV(resp.Valute, {CharCode = 'UAH'}) + table.insert(resp.Valute, { + ID = 'R02000', + NumCode = '200', + CharCode = 'SHT', + Nominal = 1, + Name = 'Штаны', + Value = ('%f'):format(tonumber(uah.Value:gsub(',', '.'), nil) / uah.Nominal * 40) + }) wants = type(wants) == 'table' and wants or {} local r, founds = {}, {} diff --git a/src/events/ready.lua b/src/events/ready.lua index feac38a..41a5356 100644 --- a/src/events/ready.lua +++ b/src/events/ready.lua @@ -5,14 +5,20 @@ end function table.find(t, w) - local i - for k,v in pairs(t) do - if v == w then - i = k - break - end + for _,v in pairs(t) do + if v == w then return v end + end +end + +function table.findV(t, w) + local b + for _,v in pairs(t) do + for k,x in pairs(w) do + if x ~= v[k] then b=1; break end + end + if b then b = nil + else return v end end - return i end function dump(t, d) From 3bbccb94aba824c999c7ed20abbe441ba3d7f5fc Mon Sep 17 00:00:00 2001 From: Er2 Date: Sun, 13 Feb 2022 15:21:44 +0300 Subject: [PATCH 3/3] optional quoted args, update lib --- etc/api | 2 +- src/cmds/eval.lua | 4 ++-- src/events/command.lua | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/etc/api b/etc/api index e8a1270..fefafd4 160000 --- a/etc/api +++ b/etc/api @@ -1 +1 @@ -Subproject commit e8a127093213a52b0f8513f72fe7c0566b786158 +Subproject commit fefafd4923e824cb5a7f762c7e65d24cdc1f8d87 diff --git a/src/cmds/eval.lua b/src/cmds/eval.lua index e430daf..60a9655 100644 --- a/src/cmds/eval.lua +++ b/src/cmds/eval.lua @@ -39,11 +39,11 @@ return { api = owner and C.api or nil, } for k,v in pairs(env) do t[k] = v end - local e, err = load(table.concat(msg.args, ' '), 'eval', 't', t) + local e, err = load(C.api.unparseArgs(msg.args), 'eval', 't', t) xpcall(function() if err then error(err) end e = tostring(e() or '...') end, function(err) e = err end) C.api:send(msg, s .. '\n' .. e) end -} \ No newline at end of file +} diff --git a/src/events/command.lua b/src/events/command.lua index 38d9da9..c1d682e 100644 --- a/src/events/command.lua +++ b/src/events/command.lua @@ -15,6 +15,7 @@ api:send(msg, C.locale:get('error', 'adm_cmd', l)) else + if cmd.useQArgs then msg.args = api.parseArgs(api.unparseArgs(msg.args)) end msg.loc = C.locale:get('cmds', msg.cmd, l) local succ, err = pcall(cmd.run, C, msg, owner) if not succ then