summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-05-09 02:17:17 +0200
committermathieui <mathieui@mathieui.net>2013-05-09 02:17:17 +0200
commitbe6f5ba51209ad8d194738761a7d29b9104d633d (patch)
tree8020f14946d1204e6c6bf5d0d2e0c0baf6138684 /plugins
parent61606707d1fe446e75c3a67b8ae361d0b7fbd281 (diff)
downloadpoezio-be6f5ba51209ad8d194738761a7d29b9104d633d.tar.gz
poezio-be6f5ba51209ad8d194738761a7d29b9104d633d.tar.bz2
poezio-be6f5ba51209ad8d194738761a7d29b9104d633d.tar.xz
poezio-be6f5ba51209ad8d194738761a7d29b9104d633d.zip
Add a regex-admin plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/regex_admin.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/plugins/regex_admin.py b/plugins/regex_admin.py
new file mode 100644
index 00000000..dbd5e49f
--- /dev/null
+++ b/plugins/regex_admin.py
@@ -0,0 +1,80 @@
+"""
+This plugins adds a :term:`/rkick` and a :term:`/rban` command,
+in order to kick/ban according to a regex on a nick.
+
+Installation
+------------
+
+You only have to load the plugin:
+
+``/load regex_admin``
+
+Commands
+--------
+
+Those commands take a regular expression (as defined in the
+`re module documentation`_) as a parameter.
+
+For roles
+~~~~~~~~~
+
+.. glossary::
+ :sorted:
+
+ /rkick
+
+ Kick a participant using a regex.
+
+
+ /rban
+
+ Ban a participant using a regex.
+
+.. _re module documentation: http://docs.python.org/3/library/re.html
+"""
+
+
+from plugin import BasePlugin
+from tabs import MucTab
+
+import re
+
+class Plugin(BasePlugin):
+ def init(self):
+ self.api.add_tab_command(MucTab, 'rkick',
+ self.command_rkick,
+ usage='<regex>',
+ help='Kick occupants of a room according to a regex',
+ short='Regex Kick')
+
+ self.api.add_tab_command(MucTab, 'rban',
+ self.command_rban,
+ usage='<regex>',
+ help='Ban occupants of a room according to a regex',
+ short='Regex Ban')
+
+ def return_users(self, users, regex):
+ try:
+ reg = re.compile(regex)
+ except:
+ return []
+
+ ret = []
+ for user in users:
+ if reg.match(user.nick):
+ ret.append(user)
+
+ return ret
+
+ def command_rban(self, regex):
+ tab = self.api.current_tab()
+ users = self.return_users(tab.users, regex)
+ for user in users:
+ tab.command_ban(user.nick)
+
+ def command_rkick(self, regex):
+ tab = self.api.current_tab()
+ users = self.return_users(tab.users, regex)
+ for user in users:
+ tab.command_kick(user.nick)
+