DES MODULES LUA
This commit is contained in:
parent
753b226848
commit
5dac2114ff
3
main.py
3
main.py
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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
|
13
modules/test_lua/version.json
Normal file
13
modules/test_lua/version.json
Normal 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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user