matrix: appservice-irc: set debugService.enable if needed

This is the case for any IRC server that has ignoreIdleUsersOnStartup
set, because of what seems like an appservice-irc bug.

Change-Id: If5063a3bc2d79c7f2fc79ec7560bf9bfe2b25aba
diff --git a/app/matrix/lib/appservice-irc.libsonnet b/app/matrix/lib/appservice-irc.libsonnet
index bc07305..2ef6905 100644
--- a/app/matrix/lib/appservice-irc.libsonnet
+++ b/app/matrix/lib/appservice-irc.libsonnet
@@ -12,8 +12,23 @@
             // false.
             bootstrapJob: true,
             config: std.native("parseYaml")(importstr "appservice/appservice-irc.yaml")[0] {
+                local appservicecfg = self,
                 ircService+: {
-                    [if cfg.passwordEncryptionKeySecret != null then "passwordEncryptionKeyPath"]: "/key/key.pem"
+                    [if cfg.passwordEncryptionKeySecret != null then "passwordEncryptionKeyPath"]: "/key/key.pem",
+                    debugApi+: {
+                        # Unfortunately, we have to enable the debugApi if any
+                        # configured server wants to use
+                        # ignoreIdleUsersOnStartup. This is seemingly an
+                        # appservice-irc bug:
+                        # https://github.com/matrix-org/matrix-appservice-irc/issues/1240
+                        enabled: std.length(std.filter(
+                            function (k) (
+                                local v = appservicecfg.ircService.servers[k];
+                                v.membershipLists.ignoreIdleUsersOnStartup.enabled == true
+                            ),
+                            std.objectFields(appservicecfg.ircService.servers)
+                        )) > 0,
+                    },
                 },
             },
             image: error "image must be set",