Red-DiscordBot
Red-DiscordBot copied to clipboard
RPC decorator for adding rpc handlers
What component of Red (cog, command, API) would you like to see improvements on?
RPC
Describe the enhancement you're suggesting.
RPC methods are registered manually as of now when a cog is loaded. I'd like propose a decorator similar to commands in dpy, to add RPC methods when a cog is loaded. Something on the lines of @rpc_method which would register the method.

Just a quality of life feature.
Anything else?
One way I could see this done is, adding an attribute to the function which is wrapped.
def rpc_method(func):
"""
Decorator for RPC methods
"""
func.rpc_method = True
return func
then whenever a cog is loaded, one could loop around the methods perhaps? somwhere on the lines of
for name, method in inspect.getmembers(cog, predicate=inspect.ismethod):
if getattr(method, "rpc_method", None) is True:
self.bot.register_rpc_handler(method)