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)
|
initialized_class = imported.MainClass(self)
|
||||||
self.modules.update({module: {"imported": imported, "initialized_class": initialized_class}})
|
self.modules.update({module: {"imported": imported, "initialized_class": initialized_class}})
|
||||||
self.info("Module {module} successfully imported.".format(module=module))
|
self.info("Module {module} successfully imported.".format(module=module))
|
||||||
initialized_class.on_load()
|
initialized_class.dispatch("load")
|
||||||
if module not in self.config["modules"]:
|
if module not in self.config["modules"]:
|
||||||
self.config["modules"].append(module)
|
self.config["modules"].append(module)
|
||||||
self.save_config()
|
self.save_config()
|
||||||
@ -315,7 +315,6 @@ class LBI(discord.Client):
|
|||||||
|
|
||||||
@event
|
@event
|
||||||
def dispatch(self, event, *args, **kwargs):
|
def dispatch(self, event, *args, **kwargs):
|
||||||
print(event)
|
|
||||||
super().dispatch(event, *args, **kwargs)
|
super().dispatch(event, *args, **kwargs)
|
||||||
for module in self.modules.values():
|
for module in self.modules.values():
|
||||||
module["initialized_class"].dispatch(event, *args, **kwargs)
|
module["initialized_class"].dispatch(event, *args, **kwargs)
|
||||||
|
@ -39,10 +39,9 @@ class BaseClassLua:
|
|||||||
self.storage.makedirs(path.join("storage", self.name), exist_ok=True)
|
self.storage.makedirs(path.join("storage", self.name), exist_ok=True)
|
||||||
# Get lua globals
|
# Get lua globals
|
||||||
self.lua = lupa.LuaRuntime(unpack_returned_tuples=True)
|
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):
|
def dispatch(self, event, *args, **kwargs):
|
||||||
print(self.luaMethods)
|
if self.luaMethods["on_"+event] is not None:
|
||||||
print(self.luaMethods.__dict__)
|
self.luaMethods["on_"+event](asyncio.ensure_future, self.client, *args, **kwargs)
|
||||||
print(dict(self.luaMethods))
|
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ class BaseClassPython:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# Run event
|
# 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):
|
async def _run_event(self, coro, event_name, *args, **kwargs):
|
||||||
# Run event
|
# Run event
|
||||||
|
@ -53,6 +53,7 @@ class MainClass(BaseClassPython):
|
|||||||
return
|
return
|
||||||
for arg in args:
|
for arg in args:
|
||||||
e = self.client.load_module(arg)
|
e = self.client.load_module(arg)
|
||||||
|
print(e)
|
||||||
if e:
|
if e:
|
||||||
await message.channel.send("An error occurred during the loading of the module {module}."
|
await message.channel.send("An error occurred during the loading of the module {module}."
|
||||||
.format(module=arg))
|
.format(module=arg))
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
main = {}
|
main = {}
|
||||||
|
|
||||||
function main.on_message(discord, message)
|
|
||||||
|
function main.on_message(await, client, message, ...)
|
||||||
print("I LOVE LUA")
|
print("I LOVE LUA")
|
||||||
print(message.content)
|
print(message.content)
|
||||||
|
if message.author.bot == false then
|
||||||
|
await(message.channel.send("Tu n'es pas un bot"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return main
|
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