X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sid%2Fplugin.py;h=f314aca9e0bedaa58dae645bdd28346c9ff7c860;hb=a8273fcb65b081ee9ebda42a0f39f071850d8f66;hp=3f4e7dac89293758f0722e02a3ce8b40b0a64915;hpb=dc0ecfe691b8049a79dcc0b36ccbc67d31c3a0b8;p=sid.git diff --git a/sid/plugin.py b/sid/plugin.py index 3f4e7da..f314aca 100644 --- a/sid/plugin.py +++ b/sid/plugin.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- # SPDX-FileCopyrightText: 2010, 2011 Anaël Verrier -# SPDX-FileCopyrightText: 2014, 2020 kaliko +# SPDX-FileCopyrightText: 2014, 2020, 2023 kaliko + +import logging + +from slixmpp.exceptions import XMPPError from .sid import botcmd @@ -14,12 +18,16 @@ class Plugin: :param sid.sid.MUCBot bot: bot the plugin is load from """ + #: Overriding bot log level for the plugin + log_level = None 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 = [] + if self.log_level: + self.log.setLevel(self.log_level) def add_handlers(self): """Add handlers declared in self.hanlders""" @@ -67,6 +75,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