Beispiel #1
0
    def init(self) -> None:
        self.name = None
        self.network = None
        self.network_id = None
        self.network_name = None  # deprecated
        self.media = []
        self.lazy_members = {}  # allow lazy joining your own ghost for echo

        self.commands = CommandManager()

        if type(self) == PrivateRoom:
            cmd = CommandParser(prog="WHOIS",
                                description="WHOIS the other user")
            self.commands.register(cmd, self.cmd_whois)

        cmd = CommandParser(
            prog="MAXLINES",
            description=
            "set maximum number of lines per message until truncation or pastebin"
        )
        cmd.add_argument("lines", type=int, nargs="?", help="Number of lines")
        self.commands.register(cmd, self.cmd_maxlines)

        cmd = CommandParser(
            prog="PASTEBIN",
            description="enable or disable automatic pastebin of long messages"
        )
        cmd.add_argument("--enable",
                         dest="enabled",
                         action="store_true",
                         help="Enable pastebin")
        cmd.add_argument("--disable",
                         dest="enabled",
                         action="store_false",
                         help="Disable pastebin (messages will be truncated)")
        cmd.set_defaults(enabled=None)
        self.commands.register(cmd, self.cmd_pastebin)

        self.mx_register("m.room.message", self.on_mx_message)
        self.mx_register("m.room.redaction", self.on_mx_redaction)
Beispiel #2
0
    def init(self) -> None:
        super().init()

        cmd = CommandParser(
            prog="DISPLAYNAMES",
            description=
            "enable or disable use of displaynames in relayed messages")
        cmd.add_argument("--enable",
                         dest="enabled",
                         action="store_true",
                         help="Enable displaynames")
        cmd.add_argument("--disable",
                         dest="enabled",
                         action="store_false",
                         help="Disable displaynames (fallback to MXID)")
        cmd.set_defaults(enabled=None)
        self.commands.register(cmd, self.cmd_displaynames)

        cmd = CommandParser(
            prog="DISAMBIGUATION",
            description=
            "enable or disable disambiguation of conflicting displaynames")
        cmd.add_argument("--enable",
                         dest="enabled",
                         action="store_true",
                         help="Enable disambiguation (postfix with MXID)")
        cmd.add_argument("--disable",
                         dest="enabled",
                         action="store_false",
                         help="Disable disambiguation")
        cmd.set_defaults(enabled=None)
        self.commands.register(cmd, self.cmd_disambiguation)

        cmd = CommandParser(
            prog="ZWSP",
            description="enable or disable Zero-Width-Space anti-ping")
        cmd.add_argument("--enable",
                         dest="enabled",
                         action="store_true",
                         help="Enable ZWSP anti-ping")
        cmd.add_argument("--disable",
                         dest="enabled",
                         action="store_false",
                         help="Disable ZWSP anti-ping")
        cmd.set_defaults(enabled=None)
        self.commands.register(cmd, self.cmd_zwsp)

        cmd = CommandParser(
            prog="NOTICERELAY",
            description="enable or disable relaying of Matrix notices to IRC")
        cmd.add_argument("--enable",
                         dest="enabled",
                         action="store_true",
                         help="Enable notice relay")
        cmd.add_argument("--disable",
                         dest="enabled",
                         action="store_false",
                         help="Disable notice relay")
        cmd.set_defaults(enabled=None)
        self.commands.register(cmd, self.cmd_noticerelay)

        cmd = CommandParser(
            prog="TOPIC",
            description="show or set channel topic and configure sync mode")
        cmd.add_argument("--sync",
                         choices=["off", "irc", "matrix", "any"],
                         help="Topic sync targets, defaults to off")
        cmd.add_argument("text", nargs="*", help="topic text if setting")
        self.commands.register(cmd, self.cmd_topic)

        cmd = CommandParser(
            prog="RELAYTAG",
            description="set RELAYMSG tag if supported by server")
        cmd.add_argument("tag", nargs="?", help="new tag")
        self.commands.register(cmd, self.cmd_relaytag)

        self.mx_register("m.room.topic", self._on_mx_room_topic)
Beispiel #3
0
    def init(self):
        self.commands = CommandManager()

        cmd = CommandParser(prog="NETWORKS",
                            description="list available networks")
        self.commands.register(cmd, self.cmd_networks)

        cmd = CommandParser(prog="SERVERS",
                            description="list servers for a network")
        cmd.add_argument("network", help="network name (see NETWORKS)")
        self.commands.register(cmd, self.cmd_servers)

        cmd = CommandParser(prog="OPEN",
                            description="open network for connecting")
        cmd.add_argument("name", help="network name (see NETWORKS)")
        cmd.add_argument("--new",
                         action="store_true",
                         help="force open a new network connection")
        self.commands.register(cmd, self.cmd_open)

        cmd = CommandParser(
            prog="STATUS",
            description="show bridge status",
            epilog="Note: admins see all users but only their own rooms",
        )
        self.commands.register(cmd, self.cmd_status)

        cmd = CommandParser(
            prog="QUIT",
            description="disconnect from all networks",
            epilog=
            ("For quickly leaving all networks and removing configurations in a single command.\n"
             "\n"
             "Additionally this will close current DM session with the bridge.\n"
             ),
        )
        self.commands.register(cmd, self.cmd_quit)

        if self.serv.is_admin(self.user_id):
            cmd = CommandParser(prog="MASKS", description="list allow masks")
            self.commands.register(cmd, self.cmd_masks)

            cmd = CommandParser(
                prog="ADDMASK",
                description="add new allow mask",
                epilog=
                ("For anyone else than the owner to use this bridge they need to be allowed to talk with the bridge bot.\n"
                 "This is accomplished by adding an allow mask that determines their permission level when using the bridge.\n"
                 "\n"
                 "Only admins can manage networks, normal users can just connect.\n"
                 ),
            )
            cmd.add_argument(
                "mask",
                help="Matrix ID mask (eg: @friend:contoso.com or *:contoso.com)"
            )
            cmd.add_argument("--admin",
                             help="Admin level access",
                             action="store_true")
            self.commands.register(cmd, self.cmd_addmask)

            cmd = CommandParser(
                prog="DELMASK",
                description="delete allow mask",
                epilog=
                ("Note: Removing a mask only prevents starting a new DM with the bridge bot. Use FORGET for ending existing"
                 " sessions."),
            )
            cmd.add_argument(
                "mask",
                help="Matrix ID mask (eg: @friend:contoso.com or *:contoso.com)"
            )
            self.commands.register(cmd, self.cmd_delmask)

            cmd = CommandParser(prog="ADDNETWORK",
                                description="add new network")
            cmd.add_argument("name", help="network name")
            self.commands.register(cmd, self.cmd_addnetwork)

            cmd = CommandParser(prog="DELNETWORK",
                                description="delete network")
            cmd.add_argument("name", help="network name")
            self.commands.register(cmd, self.cmd_delnetwork)

            cmd = CommandParser(prog="ADDSERVER",
                                description="add server to a network")
            cmd.add_argument("network", help="network name")
            cmd.add_argument("address", help="server address")
            cmd.add_argument("port",
                             nargs="?",
                             type=int,
                             help="server port",
                             default=6667)
            cmd.add_argument("--tls",
                             action="store_true",
                             help="use TLS encryption",
                             default=False)
            cmd.add_argument(
                "--tls-insecure",
                action="store_true",
                help=
                "ignore TLS verification errors (hostname, self-signed, expired)",
                default=False,
            )
            cmd.add_argument("--proxy",
                             help="use a SOCKS proxy (socks5://...)",
                             default=None)
            self.commands.register(cmd, self.cmd_addserver)

            cmd = CommandParser(prog="DELSERVER",
                                description="delete server from a network")
            cmd.add_argument("network", help="network name")
            cmd.add_argument("address", help="server address")
            cmd.add_argument("port",
                             nargs="?",
                             type=int,
                             help="server port",
                             default=6667)
            self.commands.register(cmd, self.cmd_delserver)

            cmd = CommandParser(
                prog="FORGET",
                description=
                "remove all connections and configuration of a user",
                epilog=
                ("Kills all connections of this user, removes all user set configuration and makes the bridge leave all rooms"
                 " where this user is in.\n"
                 "If the user still has an allow mask they can DM the bridge again to reconfigure and reconnect.\n"
                 "\n"
                 "This is meant as a way to kick users after removing an allow mask or resetting a user after losing access to"
                 " existing account/rooms for any reason.\n"),
            )
            cmd.add_argument("user",
                             help="Matrix ID (eg: @ex-friend:contoso.com)")
            self.commands.register(cmd, self.cmd_forget)

            cmd = CommandParser(prog="DISPLAYNAME",
                                description="change bridge displayname")
            cmd.add_argument("displayname", help="new bridge displayname")
            self.commands.register(cmd, self.cmd_displayname)

            cmd = CommandParser(prog="AVATAR",
                                description="change bridge avatar")
            cmd.add_argument("url", help="new avatar URL (mxc:// format)")
            self.commands.register(cmd, self.cmd_avatar)

            cmd = CommandParser(
                prog="IDENT",
                description="configure ident replies",
                epilog=
                "Note: MXID here is case sensitive, see subcommand help with IDENTCFG SET -h",
            )
            subcmd = cmd.add_subparsers(help="commands", dest="cmd")
            subcmd.add_parser("list", help="list custom idents (default)")
            cmd_set = subcmd.add_parser("set", help="set custom ident")
            cmd_set.add_argument("mxid", help="mxid of the user")
            cmd_set.add_argument("ident", help="custom ident for the user")
            cmd_remove = subcmd.add_parser("remove",
                                           help="remove custom ident")
            cmd_remove.add_argument("mxid", help="mxid of the user")
            self.commands.register(cmd, self.cmd_ident)

            cmd = CommandParser(
                prog="SYNC",
                description="set default IRC member sync mode",
                epilog="Note: Users can override this per room.",
            )
            group = cmd.add_mutually_exclusive_group()
            group.add_argument(
                "--lazy",
                help="set lazy sync, members are added when they talk",
                action="store_true")
            group.add_argument(
                "--half",
                help=
                "set half sync, members are added when they join or talk (default)",
                action="store_true")
            group.add_argument(
                "--full",
                help="set full sync, members are fully synchronized",
                action="store_true")
            self.commands.register(cmd, self.cmd_sync)

            cmd = CommandParser(
                prog="MAXLINES",
                description=
                "set default maximum number of lines per message until truncation or pastebin",
                epilog="Note: Users can override this per room.",
            )
            cmd.add_argument("lines",
                             type=int,
                             nargs="?",
                             help="Number of lines")
            self.commands.register(cmd, self.cmd_maxlines)

            cmd = CommandParser(
                prog="PASTEBIN",
                description=
                "enable or disable automatic pastebin of long messages by default",
                epilog="Note: Users can override this per room.",
            )
            cmd.add_argument("--enable",
                             dest="enabled",
                             action="store_true",
                             help="Enable pastebin")
            cmd.add_argument(
                "--disable",
                dest="enabled",
                action="store_false",
                help="Disable pastebin (messages will be truncated)")
            cmd.set_defaults(enabled=None)
            self.commands.register(cmd, self.cmd_pastebin)

            cmd = CommandParser(prog="MEDIAURL",
                                description="configure media URL for links")
            cmd.add_argument("url", nargs="?", help="new URL override")
            cmd.add_argument(
                "--remove",
                help="remove URL override (will retry auto-detection)",
                action="store_true")
            self.commands.register(cmd, self.cmd_media_url)

            cmd = CommandParser(prog="VERSION",
                                description="show bridge version")
            self.commands.register(cmd, self.cmd_version)

        self.mx_register("m.room.message", self.on_mx_message)