]> kaliko git repositories - sid.git/commitdiff
Expose a CLI interface for rtbl plugin
authorkaliko <kaliko@azylum.org>
Thu, 23 Mar 2023 19:06:48 +0000 (20:06 +0100)
committerkaliko <kaliko@azylum.org>
Thu, 23 Mar 2023 19:06:48 +0000 (20:06 +0100)
python3 -m sid.rtbl --jid botjid@example.org \
                    --room muc_to_moderate@conf.example.org \
                    --rtbl xmppbl.org

doc/source/index.rst
doc/source/rtbl.rst [new file with mode: 0644]
sid/cli/rtbl.py [new file with mode: 0755]
sid/rtbl.py

index 6d670602d4dcfdcde7f50379049a26ddc243a4cf..a74a8acb958005fd8d12d8714e57bcfe4cbedda5 100644 (file)
@@ -11,6 +11,7 @@
    :caption: Contents:
 
    doc.rst
+   rtbl.rst
    plugins.rst
    contribute.rst
 
diff --git a/doc/source/rtbl.rst b/doc/source/rtbl.rst
new file mode 100644 (file)
index 0000000..daa891c
--- /dev/null
@@ -0,0 +1,27 @@
+Real time block list
+--------------------
+
+The real time block list plugin can be used easily calling the module:
+
+.. code:: bash
+
+    # Create the virtual env
+    python3 -m venv --prompt "rtbl-bot" venv
+    ./venv/bin/activate
+    pip install -U pip wheel slixmpp==1.8.3
+    # Fetch the code
+    git clone -b dev https://gitlab.com/kaliko/sid.git
+    # Smoke test
+    python3 -m sid.rtbl --help
+
+
+Then run, within the same virtual env:
+
+.. code:: bash
+
+    # Activate the previously created virtual env
+    ./venv/bin/activate
+    # Run the bot
+    python3 -m sid.rtbl --jid botjid@example.org \
+                        --room muc_to_moderate@conf.example.org \
+                        --rtbl xmppbl.org
diff --git a/sid/cli/rtbl.py b/sid/cli/rtbl.py
new file mode 100755 (executable)
index 0000000..87d552f
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+A MUC ban bot based on "Real-Time Block List" service.
+"""
+
+import getpass
+import logging
+
+from argparse import ArgumentParser
+from getpass import getpass
+
+from ..sid import MUCBot
+from ..rtbl import RTBL
+
+
+def main():
+    # Setup the command line arguments.
+    parser = ArgumentParser()
+
+    # Output verbosity options.
+    parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+                        action="store_const", dest="loglevel",
+                        const=logging.ERROR, default=logging.INFO)
+    parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+                        action="store_const", dest="loglevel",
+                        const=logging.DEBUG, default=logging.INFO)
+
+    # JID and password options.
+    parser.add_argument("-j", "--jid", dest="jid",
+                        help="JID to use")
+    parser.add_argument("-p", "--password", dest="password",
+                        help="password to use")
+    parser.add_argument("-r", "--room", dest="room",
+                        help="Room to join")
+    parser.add_argument("-n", "--nick", dest="nick",
+                        default="sid-rtbl",
+                        help="Bot nickname")
+    parser.add_argument("-b", "--rtbl", dest="rtbl",
+                        help="Real-Time Block List (RTBL) service to use (ie. xmppbl.org)")
+
+    args = parser.parse_args()
+
+    # Setup logging.
+    logging.basicConfig(level=args.loglevel,
+                        format='%(levelname)-8s %(message)s')
+
+    if args.jid is None:
+        args.jid = input("Username: ")
+    if args.password is None:
+        args.password = getpass("Password: ")
+    if args.room is None:
+        args.room = input("Room: ")
+    if args.rtbl is None:
+        args.rtbl = input("Real-Time Block List to use: ")
+
+    RTBL.pubsub_server = args.rtbl
+    # Instanciate the bot
+    xmpp = MUCBot(args.jid, args.password, args.room, args.nick)
+    # Register plugin
+    xmpp.register_bot_plugin(RTBL)
+
+    # Connect to the XMPP server and start processing XMPP stanzas.
+    try:
+        xmpp.connect()
+        xmpp.process()
+    except KeyboardInterrupt:
+        xmpp.shutdown_plugins()
+
+
+if __name__ == '__main__':
+    main()
index b5c58cbef662635c5105572f3812d47d4903547f..bb4427e049989fad5af2f9f3be3d67b946a8d8b1 100644 (file)
@@ -191,5 +191,10 @@ class RTBL(Plugin):
         self.log.debug(f'participants: +{user} (len:{len(self.participants)})')
         await self.rtbl_ban(user)
 
+
+if __name__ == '__main__':
+    from .cli.rtbl import main
+    main()
+
 # VIM MODLINE
 # vim: ai ts=4 sw=4 sts=4 expandtab