From: kaliko Date: Thu, 23 Mar 2023 19:06:48 +0000 (+0100) Subject: Expose a CLI interface for rtbl plugin X-Git-Tag: 0.3.0~1 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=95c99b21c39e37d0f3ca2715642b28af990c379a;p=sid.git Expose a CLI interface for rtbl plugin python3 -m sid.rtbl --jid botjid@example.org \ --room muc_to_moderate@conf.example.org \ --rtbl xmppbl.org --- diff --git a/doc/source/index.rst b/doc/source/index.rst index 6d67060..a74a8ac 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -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 index 0000000..daa891c --- /dev/null +++ b/doc/source/rtbl.rst @@ -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 index 0000000..87d552f --- /dev/null +++ b/sid/cli/rtbl.py @@ -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() diff --git a/sid/rtbl.py b/sid/rtbl.py index b5c58cb..bb4427e 100644 --- a/sid/rtbl.py +++ b/sid/rtbl.py @@ -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