DES MODULES LUA

This commit is contained in:
fomys 2019-06-05 03:37:50 +02:00
parent 753b226848
commit 5dac2114ff
6 changed files with 24 additions and 8 deletions

View File

@ -281,7 +281,7 @@ class LBI(discord.Client):
initialized_class = imported.MainClass(self)
self.modules.update({module: {"imported": imported, "initialized_class": initialized_class}})
self.info("Module {module} successfully imported.".format(module=module))
initialized_class.on_load()
initialized_class.dispatch("load")
if module not in self.config["modules"]:
self.config["modules"].append(module)
self.save_config()
@ -315,7 +315,6 @@ class LBI(discord.Client):
@event
def dispatch(self, event, *args, **kwargs):
print(event)
super().dispatch(event, *args, **kwargs)
for module in self.modules.values():
module["initialized_class"].dispatch(event, *args, **kwargs)

View File

@ -39,10 +39,9 @@ class BaseClassLua:
self.storage.makedirs(path.join("storage", self.name), exist_ok=True)
# Get lua globals
self.lua = lupa.LuaRuntime(unpack_returned_tuples=True)
self.luaMethods = self.lua.eval("require \"main\"")
self.luaMethods = self.lua.require("modules/test_lua/main")
def dispatch(self, event, *args, **kwargs):
print(self.luaMethods)
print(self.luaMethods.__dict__)
print(dict(self.luaMethods))
if self.luaMethods["on_"+event] is not None:
self.luaMethods["on_"+event](asyncio.ensure_future, self.client, *args, **kwargs)

View File

@ -186,7 +186,7 @@ class BaseClassPython:
pass
else:
# Run event
asyncio.ensure_future(self._run_event(coro, method, *args, **kwargs), loop=self.loop)
asyncio.ensure_future(self._run_event(coro, method, *args, **kwargs), loop=self.client.loop)
async def _run_event(self, coro, event_name, *args, **kwargs):
# Run event

View File

@ -53,6 +53,7 @@ class MainClass(BaseClassPython):
return
for arg in args:
e = self.client.load_module(arg)
print(e)
if e:
await message.channel.send("An error occurred during the loading of the module {module}."
.format(module=arg))

View File

@ -1,8 +1,12 @@
main = {}
function main.on_message(discord, message)
function main.on_message(await, client, message, ...)
print("I LOVE LUA")
print(message.content)
if message.author.bot == false then
await(message.channel.send("Tu n'es pas un bot"))
end
end
return main

View File

@ -0,0 +1,13 @@
{
"version": "0.1.0",
"dependencies": {
"base": {
"min": "0.1.0",
"max": "0.1.0"
}
},
"bot_version": {
"min": "0.1.0",
"max": "0.1.0"
}
}