Decorator method to *register* event handlers. This is the client-less
    `add_event_handler
    <telethon.client.updates.UpdateMethods.add_event_handler>` variant.

    Note that this method only registers callbacks as handlers,
    and does not attach them to any client. This is useful for
    external modules that don't have access to the client, but
    still want to define themselves as a handler. Example:

    >>> from telethon import events
    >>> @events.register(events.NewMessage)
    ... async def handler(event):
    ...     ...
    ...
    >>> # (somewhere else)
    ...
    >>> from telethon import TelegramClient
    >>> client = TelegramClient(...)
    >>> client.add_event_handler(handler)

    Remember that you can use this as a non-decorator
    through ``register(event)(callback)``.

    Args:
        event (`_EventBuilder` | `type`):
            The event builder class or instance to be used,
            for instance ``events.NewMessage``.

def register(event=None):
    """
    Decorator method to *register* event handlers. This is the client-less
    `add_event_handler
    <telethon.client.updates.UpdateMethods.add_event_handler>` variant.

    Note that this method only registers callbacks as handlers,
    and does not attach them to any client. This is useful for
    external modules that don't have access to the client, but
    still want to define themselves as a handler. Example:

    >>> from telethon import events
    >>> @events.register(events.NewMessage)
    ... async def handler(event):
    ...     ...
    ...
    >>> # (somewhere else)
    ...
    >>> from telethon import TelegramClient
    >>> client = TelegramClient(...)
    >>> client.add_event_handler(handler)

    Remember that you can use this as a non-decorator
    through ``register(event)(callback)``.

    Args:
        event (`_EventBuilder` | `type`):
            The event builder class or instance to be used,
            for instance ``events.NewMessage``.
    """
    if isinstance(event, type):
        event = event()
    elif not event:
        event = Raw()

    def decorator(callback):
        handlers = getattr(callback, _HANDLERS_ATTRIBUTE, [])
        handlers.append(event)
        setattr(callback, _HANDLERS_ATTRIBUTE, handlers)
        return callback

    return decorator