Replaced message cloning with message proxying

This commit is contained in:
Yessiest 2022-11-15 00:59:52 +04:00
parent aaa4b992f8
commit 8f90345b96
2 changed files with 22 additions and 3 deletions

View File

@ -1,7 +1,7 @@
return function(message,overrides) return function(message,overrides)
assert(type(message) == "table","table expected, got "..type(message)) assert(type(message) == "table","table expected, got "..type(message))
assert(type(overrides) == "table","table expected for arg#2, got "..type(overrides)) assert(type(overrides) == "table","table expected for arg#2, got "..type(overrides))
local fake = {content = message.content, --[[local fake = {content = message.content,
author = message.author, author = message.author,
member = message.guild:getMember(message.author.id), member = message.guild:getMember(message.author.id),
channel = message.channel, channel = message.channel,
@ -40,9 +40,28 @@ return function(message,overrides)
message:removeReaction(...) message:removeReaction(...)
end, end,
emulated = true emulated = true
} }]]
fake = {}
for k,v in pairs(overrides) do for k,v in pairs(overrides) do
fake[k] = v fake[k] = v
end end
fake = setmetatable(fake, {
__index = function(self,k)
local value = rawget(self,k)
if not value then
value = message[k]
if type(value) == "function" then
return function(x,...)
if not x then error("self expected, got nil") end
return value(message,...)
end
else
return value
end
else
return value
end
end
})
return fake return fake
end end

@ -1 +1 @@
Subproject commit 8a1906df7a402349ff7b083e59cf17223363f59b Subproject commit 4c796978eb2ca1e54d0ed357820610e09f30e8ef