From f227a74696ba7464d1898c8ed2b1bdfae7d3b4e7 Mon Sep 17 00:00:00 2001 From: Wasin Phungwigrai Date: Wed, 5 Jul 2023 01:00:25 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20chore(.claspignore):=20add=20.gs?= =?UTF-8?q?=20files=20to=20.claspignore=20to=20exclude=20them=20from=20cla?= =?UTF-8?q?sp=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 fix(Code.ts): move writeMessageLog() call inside the condition to check if SAVE_MESSAGE is true to prevent unnecessary calls 🔀 merge(Code.ts): add SAVE_MESSAGE configuration option to defaultConfig() function to enable/disable saving messages --- .claspignore | 1 + Code.ts | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .claspignore diff --git a/.claspignore b/.claspignore new file mode 100644 index 0000000..8a657e8 --- /dev/null +++ b/.claspignore @@ -0,0 +1 @@ +**/*.gs \ No newline at end of file diff --git a/Code.ts b/Code.ts index 59ee284..765b4d3 100644 --- a/Code.ts +++ b/Code.ts @@ -4,6 +4,7 @@ interface Config { SAVE_VIDEO: boolean; SAVE_AUDIO: boolean; SAVE_FILE: boolean; + SAVE_MESSAGE: boolean; ALLOW_GET_LINK: boolean; ALLOW_OVERWRITE: boolean; COMMAND_GET_LINK: string; @@ -119,7 +120,6 @@ function run() { saveFile(); } else if (messageType === "text" && messageText) { const userId = getUserId(); - writeMessageLog(); if ( getConfigValue("ALLOW_GET_LINK", userId) && messageText === getConfigValue("COMMAND_GET_LINK", selectedId) @@ -168,6 +168,9 @@ function run() { ); } } + if (getConfigValue("SAVE_MESSAGE", selectedId)) { + writeMessageLog(); + } } } @@ -206,11 +209,9 @@ function writeMessageLog() { // get displayName from userId const userId = getUserId(); let displayName = ""; - for (const row of userSheet - .getRange(2, 1, userSheet.getLastRow(), 1) - .getValues()) { - if (row[0] == userId) { - displayName = row[1]; + for (let i = 1; i <= userSheet.getLastRow(); i++) { + if (userSheet.getRange(i, 1).getValue() === userId) { + displayName = userSheet.getRange(i, 2).getValue(); break; } } @@ -479,6 +480,7 @@ function defaultConfig(): Config { SAVE_VIDEO: true, SAVE_AUDIO: true, SAVE_FILE: true, + SAVE_MESSAGE: true, ALLOW_GET_LINK: true, ALLOW_OVERWRITE: true, COMMAND_GET_LINK: "!link",