X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sid%2Fplugin.py;h=3844761c88001fae56bb0f532bcd3e7f021df4b7;hb=cf4e0e61fd723ec820449c6dd26a820514404c63;hp=6db1d5984f07875af599dd694393ba0aeb8f69c2;hpb=1c1134e00f13fee92f9a0e0996d08db32579d89a;p=sid.git diff --git a/sid/plugin.py b/sid/plugin.py index 6db1d59..3844761 100644 --- a/sid/plugin.py +++ b/sid/plugin.py @@ -1,22 +1,12 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2010, 2011 Anaël Verrier +# SPDX-FileCopyrightText: 2014, 2020 kaliko -# Copyright (C) 2010, 2011 Anaël Verrier -# Copyright (C) 2014, 2020 kaliko - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 3 only. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +from slixmpp.exceptions import XMPPError from .sid import botcmd + class Plugin: """ Simple Plugin object to derive from: @@ -30,6 +20,20 @@ class Plugin: def __init__(self, bot): self.bot = bot self.log = bot.log.getChild(self.__class__.__name__) + #: :py:obj:`list` : List of tuples (event, handler) + self.handlers = [] + + def add_handlers(self): + """Add handlers declared in self.hanlders""" + for event, handler in self.handlers: + self.log.debug(f'Add {event} > {self.__class__.__name__}().{handler.__name__}') + self.bot.add_event_handler(event, handler) + + def rm_handlers(self): + """Remove handlers declared in self.hanlders""" + for event, handler in self.handlers: + self.log.debug(f'Remove {event} > {self.__class__.__name__}().{handler.__name__}') + self.bot.del_event_handler(event, handler) def send(self, dest, msg, mtype='chat'): """Send msg to dest @@ -65,5 +69,19 @@ class Plugin: to = rcv['mucroom'] self.send(to, msg, mtype=rcv['type']) + async def ban(self, jid, reason): + """Coroutine to ban a jid from the room + + :param str jid: JID to ban + :param str reason: Reason + """ + room = self.bot.room + try: + await self.bot['xep_0045'].set_affiliation(room, + jid=jid, affiliation='outcast', reason=reason) + except XMPPError as error: + self.log.error(error) + def shutdown(self): + """Empty method to override. Called on bot shutdown""" pass