"""
Once loaded, every line of your messages will be stripped of their trailing spaces.
"""
from poezio.plugin import BasePlugin
from slixmpp import Message
from typing import Any


class Plugin(BasePlugin):
    def init(self) -> None:
        self.api.add_event_handler('muc_say', self.rstrip)
        self.api.add_event_handler('conversation_say', self.rstrip)
        self.api.add_event_handler('private_say', self.rstrip)

    def rstrip(self, msg: Message, tab: Any) -> None:
        msg['body'] = '\n'.join(
            line.rstrip() for line in msg['body'].split('\n'))
