This commit is contained in:
Clxud 2023-03-16 18:00:54 +00:00
parent bce429ab48
commit b80a4c3cce
5 changed files with 29 additions and 4 deletions

4
.gitignore vendored
View File

@ -46,4 +46,8 @@ test.lua
*.json *.json
*.log *.log
*.Dockerfile
*.yml
/luvit

View File

@ -1,4 +1,5 @@
return { return {
Enums = require('enums'),
Node = require('node'), Node = require('node'),
Player = require('player'), Player = require('player'),
Pool = require('pool'), Pool = require('pool'),

View File

@ -12,7 +12,7 @@ local SearchType = enums.SearchType
local Emitter = discordia.Emitter local Emitter = discordia.Emitter
local class = discordia.class local class = discordia.class
local Node, get = class('FlareNode', Emitter) local Node, get = class('Node', Emitter)
local format = string.format local format = string.format

View File

@ -3,6 +3,8 @@ local class = discordia.class
local Node = require('node') local Node = require('node')
local Pool, get = class('Pool') local Pool, get = class('Pool')
local dump = require('utils').dump
local random_value = require('utils').random_value
local format = string.format local format = string.format
@ -19,14 +21,17 @@ function Pool:create_node(client, options)
end end
options.pool = self options.pool = self
self._nodes[options.identifier] = Node(client, options) local id = options.identifier
self._nodes[id] = Node(client, options)
end end
function Pool:get_node(identifier) function Pool:get_node(identifier)
if self._nodes[identifier] then if self._nodes[identifier] then
return self._nodes[identifier] return self._nodes[identifier]
else else
return self._nodes[math.random(#self._nodes)] print("getting random node")
local node = random_value(self._nodes)
print(node)
end end
end end

View File

@ -31,8 +31,23 @@ function split(str, character)
return result return result
end end
function random_value(tb)
local values = {}
for k, v in pairs(tb) do table.insert(values, v) end
print(values.index)
return tb[values[math.random(#values)]]
end
function random_key(tb)
local keys = {}
for k in pairs(tb) do table.insert(keys, k) end
return tb[keys[math.random(#keys)]]
end
return { return {
dump = dump, dump = dump,
interp = interp, interp = interp,
split = split split = split,
random_value = random_value,
random_key = random_key
} }