[READ-ONLY] Mirror of https://github.com/thoda-dev/DualUniverse. DualUniverse scripts
0

Configure Feed

Select the types of activity you want to include in your feed.

Create utility.lua

authored by

Thomas and committed by
GitHub
(Feb 10, 2022, 6:29 PM +0100) 35b88106 c4667559

+71
+71
tools/utility.lua
··· 1 + --[[ 2 + Remove duplicate elements in a lua table 3 + By Jericho 4 + ]] 5 + function removeDuplicatesInTable(data) 6 + local hash = {} 7 + local res = {} 8 + for _,v in ipairs(data) do 9 + if (not hash[v]) then 10 + res[#res+1] = v 11 + hash[v] = true 12 + end 13 + end 14 + return res 15 + end 16 + 17 + --[[ 18 + split a string on a delimiter 19 + By jericho 20 + ]] 21 + function strSplit(s, delimiter) 22 + result = {}; 23 + for match in (s..delimiter):gmatch("(.-)"..delimiter) do 24 + table.insert(result, match); 25 + end 26 + return result; 27 + end 28 + 29 + --[[ 30 + Convert timestamp in a string representing a dureation in days, hours, minutes and seconds 31 + By Jericho 32 + ]] 33 + function SecondsToClockString(seconds) 34 + local seconds = tonumber(seconds) 35 + 36 + if seconds == nil or seconds <= 0 then 37 + return "-"; 38 + else 39 + days = string.format("%2.f", math.floor(seconds/(3600*24))); 40 + hours = string.format("%2.f", math.floor(seconds/3600 - (days*24))); 41 + mins = string.format("%2.f", math.floor(seconds/60 - (hours*60) - (days*24*60))); 42 + secs = string.format("%2.f", math.floor(seconds - hours*3600 - (days*24*60*60) - mins *60)); 43 + str = "" 44 + if tonumber(days) > 0 then str = str .. days.."d " end 45 + if tonumber(hours) > 0 then str = str .. hours.."h " end 46 + if tonumber(mins) > 0 then str = str .. mins.."m " end 47 + if tonumber(secs) > 0 then str = str .. secs .."s" end 48 + return str 49 + end 50 + end 51 + 52 + --[[ 53 + remove the quality if exist in a string 54 + ]] 55 + function removeQualityInName(name) 56 + if not name then return '' end 57 + return name:lower():gsub('basic ', ''):gsub('uncommon ', ''):gsub('advanced ', ''):gsub('rare ', ''):gsub('exotic ', '') 58 + end 59 + 60 + --[[ 61 + check if a value exist in a table 62 + ]] 63 + function has_value (tab, val) 64 + for index, value in ipairs(tab) do 65 + if value == val then 66 + return true 67 + end 68 + end 69 + 70 + return false 71 + end