From 13e857dda642c45b4ee58c2767a52973c8788986 Mon Sep 17 00:00:00 2001
From: The Stranjer <791672+TheStranjer@users.noreply.github.com>
Date: Sun, 28 Aug 2022 05:51:43 -0600
Subject: [PATCH] Include the domain name in the regular expression (#834)

* Include the domain name in the regular expression

* Rename 834.bugfux to 834.bugfix
---
 changelog.d/834.bugfix |  1 +
 src/discordas.ts       | 22 ++++++++++++----------
 2 files changed, 13 insertions(+), 10 deletions(-)
 create mode 100644 changelog.d/834.bugfix

diff --git a/changelog.d/834.bugfix b/changelog.d/834.bugfix
new file mode 100644
index 0000000..a176a18
--- /dev/null
+++ b/changelog.d/834.bugfix
@@ -0,0 +1 @@
+Include the domain name in the regular expression.
diff --git a/src/discordas.ts b/src/discordas.ts
index 951b4fb..baebd98 100644
--- a/src/discordas.ts
+++ b/src/discordas.ts
@@ -39,7 +39,7 @@ const commandOptions = [
     { name: "help", alias: "h", type: Boolean },
 ];
 
-function generateRegistration(opts, registrationPath: string): void {
+function generateRegistration(opts, registrationPath: string, config: DiscordBridgeConfig): void {
     if (!opts.url) {
         throw Error("'url' not given in command line opts, cannot generate registration file");
     }
@@ -52,14 +52,14 @@ function generateRegistration(opts, registrationPath: string): void {
             aliases: [
                 {
                     exclusive: true,
-                    regex: "#_discord_.*",
+                    regex: '#_discord_.+:' + config.bridge.domain,
                 },
             ],
             rooms: [ ],
             users: [
                 {
                     exclusive: true,
-                    regex: "@_discord_.*",
+                    regex: '@_discord_.+:' + config.bridge.domain,
                 },
             ],
         },
@@ -125,13 +125,6 @@ async function run(): Promise<void> {
 
     const configPath = opts.config || "config.yaml";
     const registrationPath = opts.file || "discord-registration.yaml";
-    if (opts["generate-registration"]) {
-        if (fs.existsSync(registrationPath)) {
-            throw Error("Not writing new registration file, file already exists");
-        }
-        generateRegistration(opts, registrationPath);
-        return;
-    }
 
     const config = new DiscordBridgeConfig();
     const readConfig = yaml.safeLoad(fs.readFileSync(configPath, "utf8"));
@@ -140,6 +133,15 @@ async function run(): Promise<void> {
     }
     config.applyConfig(readConfig);
     config.applyEnvironmentOverrides(process.env);
+
+    if (opts["generate-registration"]) {
+        if (fs.existsSync(registrationPath)) {
+            throw Error("Not writing new registration file, file already exists");
+        }
+        generateRegistration(opts, registrationPath, config);
+        return;
+    }
+
     Log.Configure(config.logging);
     const port = opts.port || config.bridge.port;
     if (!port) {
-- 
GitLab