From 5e83f01e25009e445b2be1a04fc2cb7a2cdbb601 Mon Sep 17 00:00:00 2001
From: Jack <bartnikjack@gmail.com>
Date: Tue, 7 Jul 2020 16:39:10 +0100
Subject: [PATCH] sending a command to the bot if the user got a pb

---
 functions/index.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/functions/index.js b/functions/index.js
index b3d5ec171..3b777346b 100644
--- a/functions/index.js
+++ b/functions/index.js
@@ -367,6 +367,12 @@ exports.testCompleted = functions.https.onCall((request, response) => {
                 request.obj
               )}`
             );
+            if (obj.mode === "time" && String(obj.mode2) === "60") {
+              console.log(
+                `sending command to the bot to update the role for user ${request.uid} with wpm ${obj.wpm}`
+              );
+              updateDiscordRole(obj.discordId, obj.wpm);
+            }
             return 2;
           } else {
             console.log(
@@ -388,6 +394,15 @@ exports.testCompleted = functions.https.onCall((request, response) => {
   }
 });
 
+function updateDiscordRole(discordId, wpm) {
+  db.collection("bot-commands").add({
+    command: "updateRole",
+    arguments: [discordId, wpm],
+    executed: false,
+    requestTimestamp: Date.now(),
+  });
+}
+
 function isTagValid(name) {
   if (name === null || name === undefined || name === "") return false;
   if (name.length > 16) return false;