]> kaliko git repositories - sid.git/blobdiff - sid/plugin.py
Add ban command to plugin base object
[sid.git] / sid / plugin.py
index efc9a146c31f798eedb48cdb22e0d799b5a704f1..d9ef0ae618d0b9a0122d318baab9470a06debae2 100644 (file)
@@ -1,19 +1,6 @@
 # -*- coding: utf-8 -*-
-
-# Copyright (C) 2010, 2011 Anaël Verrier <elghinn@free.fr>
-# Copyright (C) 2014, 2020 kaliko <kaliko@azylum.org>
-
-# 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 <http://www.gnu.org/licenses/>.
+# SPDX-FileCopyrightText: 2010, 2011 Anaël Verrier <elghinn@free.fr>
+# SPDX-FileCopyrightText: 2014, 2020 kaliko <kaliko@azylum.org>
 
 from .sid import botcmd
 
@@ -80,6 +67,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