|
@@ -2,6 +2,7 @@ import logging
|
|
|
from dataclasses import dataclass
|
|
|
from enum import Enum, auto
|
|
|
import inspect
|
|
|
+import functools
|
|
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
|
@@ -162,23 +163,30 @@ def as_plugin(command):
|
|
|
sig = inspect.signature(fn)
|
|
|
converters = []
|
|
|
for p in sig.parameters:
|
|
|
- if p in ("msg", "message"):
|
|
|
+ if p in ("msg", "message", "_msg"):
|
|
|
converters.append(lambda self, db, msg: msg)
|
|
|
elif p in ("db", "database"):
|
|
|
converters.append(lambda self, db, msg: db)
|
|
|
elif p in ("log", "logger"):
|
|
|
converters.append(lambda self, db, msg: self.logger)
|
|
|
- elif p == "bot":
|
|
|
+ elif p in ("bot", "rollbot"):
|
|
|
converters.append(lambda self, db, msg: self.bot)
|
|
|
else:
|
|
|
raise ValueError(f"Illegal argument name {p} in decorated plugin {command_name}")
|
|
|
|
|
|
+ def on_command_standin(self, db, msg):
|
|
|
+ res = fn(*[c(self, db, msg) for c in converters])
|
|
|
+ if isinstance(res, RollbotResponse):
|
|
|
+ return res
|
|
|
+ else:
|
|
|
+ return RollbotResponse(msg, txt=str(res))
|
|
|
+
|
|
|
return type(
|
|
|
f"AutoGenerated`{command_name}`Command",
|
|
|
(RollbotPlugin,),
|
|
|
dict(
|
|
|
__init__=init_standin,
|
|
|
- on_command=(lambda self, db, msg: fn(*[c(self, db, msg) for c in converters]))
|
|
|
+ on_command=on_command_standin,
|
|
|
)
|
|
|
)
|
|
|
|