Skip to content

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.

Step-by-step

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, and register_handler are now part of the plugins package, instead of pre-2.4 Handlers 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 named bot
    • Plugin init no longer requires return [] - it is automatically assumed that all commands must be explicitly registered with register_user_command and register_admin_command
    • register_shared is part of the supplied bot parameter
  • Function naming conventions are still applicable:
    • Prefix a function with an underscore (_) for "hidden" non-command functions

Example

Pre-2.4

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!")

2.4

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!")

# ## ###

Clone this wiki locally