28 lines
823 B
Lua
28 lines
823 B
Lua
|
|
-- Generate v4 UUID, copy to clipboard, speak short suffix.
|
||
|
|
math.randomseed(os.time() + (jarvis.context.time.minute or 0) * 1000)
|
||
|
|
|
||
|
|
local function hex(n)
|
||
|
|
local s = {}
|
||
|
|
for _ = 1, n do
|
||
|
|
s[#s + 1] = string.format("%x", math.random(0, 15))
|
||
|
|
end
|
||
|
|
return table.concat(s)
|
||
|
|
end
|
||
|
|
|
||
|
|
-- v4 UUID: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where y is 8|9|a|b
|
||
|
|
local y_pool = { "8", "9", "a", "b" }
|
||
|
|
local uuid = string.format(
|
||
|
|
"%s-%s-4%s-%s%s-%s",
|
||
|
|
hex(8), hex(4), hex(3),
|
||
|
|
y_pool[math.random(1, 4)], hex(3),
|
||
|
|
hex(12)
|
||
|
|
)
|
||
|
|
|
||
|
|
jarvis.system.clipboard.set(uuid)
|
||
|
|
jarvis.system.notify("UUID", uuid)
|
||
|
|
|
||
|
|
-- Speak last 4 hex chars so user knows it landed but doesn't have to listen
|
||
|
|
-- to 32 characters.
|
||
|
|
local suffix = uuid:sub(-4)
|
||
|
|
return jarvis.cmd.ok("UUID в буфере, заканчивается на " .. suffix .. ".")
|