-
Notifications
You must be signed in to change notification settings - Fork 2
Migrating Pre 2.4 Plugins
Innocent Bystander edited this page Jul 29, 2015
·
7 revisions
It is recommended to port older plugin patterns to the new plugin pattern introduced in 2.4.
Important: Plugins developed with this pattern are not compatible with bot version < 2.4.
Note: Older plugin patterns will still run on bot version 2.4 and above, but will generate
LEGACY
and/or [DEPRECATED]
warnings in the log. Developers can use these notices as a rough
guide to identify plugins that are still running old code.
- For commands and handlers:
register_user_command
,register_admin_command
, andregister_handler
are now part of theplugins
package, instead of pre-2.4Handlers
parameter.- Function signatures remain the same, so your handler and command functions do not need to be changed.
- Handlers do not need to be decorated with
@asyncio.coroutine
- this is now performed automatically.
-
_initialise()
/_initialize()
accepts only a single parameter which must be namedbot
- Plugin init no longer requires
return []
- it is automatically assumed that all commands must be explicitly registered withregister_user_command
andregister_admin_command
-
register_shared
is part of the suppliedbot
parameter
- Plugin init no longer requires
- Function naming conventions are still applicable:
- Prefix a function with an underscore (
_
) for "hidden" non-command functions
- Prefix a function with an underscore (
import asyncio
def _initialise(Handlers, bot=None):
Handlers.register_handler(_custom_handler)
Handlers.register_user_command(["custom_command"])
return [] # always a blank list
@asyncio.coroutine
def _custom_handler(bot, event, command):
if "somethinghappened" in event.text
yield from command.run(bot, event, *["custom_command"])
def custom_command(bot, event, *args):
print("something happened!")
import plugins
def _initialise(bot):
plugins.register_handler(_custom_handler)
plugins.register_user_command(["custom_command"])
def _custom_handler(bot, event, command):
if "somethinghappened" in event.text
yield from command.run(bot, event, *["custom_command"])
def custom_command(bot, event, *args):
print("something happened!")
Plugin List | Developer Reference: [ Intro | Plugins | Sinks | In-built Functionality | [Configuration] (Configuration) ]