Add utils from who-er
This commit is contained in:
49
Heimdall.lua
49
Heimdall.lua
@@ -8,7 +8,10 @@ if not Heimdall_Data then Heimdall_Data = {} end
|
|||||||
---@field raceMap table<string, string>
|
---@field raceMap table<string, string>
|
||||||
---@field stinkies table<string, boolean>
|
---@field stinkies table<string, boolean>
|
||||||
---@field messenger HeimdallMessengerData
|
---@field messenger HeimdallMessengerData
|
||||||
|
---@field who HeimdallWhoData
|
||||||
---@field dumpTable fun(table: any, depth?: number): nil
|
---@field dumpTable fun(table: any, depth?: number): nil
|
||||||
|
---@field utf8len fun(input: string): number
|
||||||
|
---@field padString fun(input: string, targetLength: number, left?: boolean): string
|
||||||
|
|
||||||
--- Config ---
|
--- Config ---
|
||||||
---@class HeimdallConfig
|
---@class HeimdallConfig
|
||||||
@@ -37,6 +40,9 @@ if not Heimdall_Data then Heimdall_Data = {} end
|
|||||||
---@field queue table<string, Message>
|
---@field queue table<string, Message>
|
||||||
---@field ticker number?
|
---@field ticker number?
|
||||||
|
|
||||||
|
---@class HeimdallWhoData
|
||||||
|
---@field ticker number?
|
||||||
|
|
||||||
data.messenger = {
|
data.messenger = {
|
||||||
queue = {}
|
queue = {}
|
||||||
}
|
}
|
||||||
@@ -85,3 +91,46 @@ data.raceMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.stinkies = {}
|
data.stinkies = {}
|
||||||
|
|
||||||
|
---@param input string
|
||||||
|
---@return number
|
||||||
|
data.utf8len = function(input)
|
||||||
|
if not input then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
local len = 0
|
||||||
|
local i = 1
|
||||||
|
local n = #input
|
||||||
|
while i <= n do
|
||||||
|
local c = input:byte(i)
|
||||||
|
if c >= 0 and c <= 127 then
|
||||||
|
i = i + 1
|
||||||
|
elseif c >= 194 and c <= 223 then
|
||||||
|
i = i + 2
|
||||||
|
elseif c >= 224 and c <= 239 then
|
||||||
|
i = i + 3
|
||||||
|
elseif c >= 240 and c <= 244 then
|
||||||
|
i = i + 4
|
||||||
|
else
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
len = len + 1
|
||||||
|
end
|
||||||
|
return len
|
||||||
|
end
|
||||||
|
---@param input string
|
||||||
|
---@param targetLength number
|
||||||
|
---@param left boolean
|
||||||
|
---@return string
|
||||||
|
data.padString = function(input, targetLength, left)
|
||||||
|
left = left or false
|
||||||
|
local len = data.utf8len(input)
|
||||||
|
if len < targetLength then
|
||||||
|
if left then
|
||||||
|
input = input .. string.rep(" ", targetLength - len)
|
||||||
|
else
|
||||||
|
input = string.rep(" ", targetLength - len) .. input
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return input
|
||||||
|
end
|
@@ -1,6 +1,8 @@
|
|||||||
local _, data = ...
|
local _, data = ...
|
||||||
---@cast data HeimdallData
|
---@cast data HeimdallData
|
||||||
|
|
||||||
|
if not data.config.messenger.enabled then return end
|
||||||
|
|
||||||
---@class Message
|
---@class Message
|
||||||
---@field message string
|
---@field message string
|
||||||
---@field channel string
|
---@field channel string
|
||||||
|
Reference in New Issue
Block a user