From e65fa4097d26e2e98c63966824e33dfd1a7556e1 Mon Sep 17 00:00:00 2001
From: Andrew Morgan <andrew@amorgan.xyz>
Date: Mon, 18 Sep 2017 00:04:06 +0000
Subject: [PATCH] Update README to inform users of auto webhook creation

---
 README.md  | 5 +++--
 src/bot.ts | 8 ++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index ca1d956..0546617 100644
--- a/README.md
+++ b/README.md
@@ -63,8 +63,9 @@ and synapse. Any new servers/guilds you bridge should show up in the network lis
   * These can be taken from the url ("/$GUILDID/$CHANNELID") when you are in a channel.
   * Riot (and other clients with third party protocol support) users can directly join channels from the room directory.
 * You can use Webhooks to make messages relayed by the bridge not nested by the bot user. This will also display the avatar of the user speaking on matrix with their messages.
-  * Enable ``Manage Webhooks`` on the role added by the bot.
-  * Add the ``_matrix`` Webhook for each channel you'd like to enable this feature on.
+  * The bot should create this automatically, but if not perform the following:
+    * Enable ``Manage Webhooks`` on the role added by the bot.
+    * Add the ``_matrix`` Webhook for each channel you'd like to enable this feature on.
 
 ### Running the Bridge
 
diff --git a/src/bot.ts b/src/bot.ts
index 31b7ae7..349a448 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -195,8 +195,12 @@ export class DiscordBot {
       const webhooks = await chan.fetchWebhooks();
       hook = webhooks.filterArray((h) => h.name === "_matrix").pop();
       // Create a new webhook if none already exists
-      if (!hook) {
-        hook = await chan.createWebhook("_matrix", "", "Matrix Bridge: Allow rich user messages");
+      try {
+        if (!hook) {
+          hook = await chan.createWebhook("_matrix", "", "Matrix Bridge: Allow rich user messages");
+        }
+      } catch (err) {
+        log.error("DiscordBot", "Unable to create \"_matrix\" webhook. ", err);
       }
     }
     try {
-- 
GitLab