From 8690133a1955a52f2e9b6928dcdc5976c9f5b792 Mon Sep 17 00:00:00 2001 From: Trevor Blanarik Date: Sat, 21 Sep 2024 04:53:46 +0000 Subject: [PATCH 1/4] add flag to supress embeds for upcoming links --- function_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/function_app.py b/function_app.py index cf8866c..5a8c9d7 100644 --- a/function_app.py +++ b/function_app.py @@ -29,7 +29,7 @@ def create_content(req_body): summitRef = req_body.get('summitRef', '') wwffRef = req_body.get('wwffRef', '') - content = {"content": f"{fullCallsign} | {source} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef}"} + content = {"content": f"{fullCallsign} | {source} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef}", "flags": 4} return content def call_target(content): From e61bdc3b2bac92cc2857d02b5fae642059d6f4aa Mon Sep 17 00:00:00 2001 From: Trevor Blanarik Date: Sat, 21 Sep 2024 05:04:04 +0000 Subject: [PATCH 2/4] creating the spot deeplink function and fixing test casing --- function_app.py | 16 ++++++++++++++-- test.py | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/function_app.py b/function_app.py index 5a8c9d7..a25ad88 100644 --- a/function_app.py +++ b/function_app.py @@ -29,10 +29,22 @@ def create_content(req_body): summitRef = req_body.get('summitRef', '') wwffRef = req_body.get('wwffRef', '') - content = {"content": f"{fullCallsign} | {source} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef}", "flags": 4} + spot_deeplink = create_spot_deeplink(source, fullCallsign, wwffRef) + + content = {"content": f"{fullCallsign} | {source} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef} | {spot_deeplink}", "flags": 4} return content def call_target(content): target_url = os.getenv('TARGET_URL') response = requests.post(target_url, json=content) - return func.HttpResponse(response.text, status_code=response.status_code) \ No newline at end of file + return func.HttpResponse(response.text, status_code=response.status_code) + +def create_spot_deeplink(source, fullCallsign, wwffRef): + + match source: + case "sotawatch": + return "[See their latest spot](https://sotl.as/activators/{fullCallsign})" + case "pota": + return "[See their latest spot](https://api.pota.app/spot/comments/{fullCallsign}/{wwffRef})" + case _: + return "" \ No newline at end of file diff --git a/test.py b/test.py index 24c809e..903af9b 100644 --- a/test.py +++ b/test.py @@ -4,9 +4,9 @@ class TestSpotBot(unittest.TestCase): def test_function_app_basic(self): - req_body = {"fullCallsign": "KI7HSG", "source": "POTA", "frequency": "14.074", "mode": "FT8", "wwffRef":"US-0052"} + req_body = {"fullCallsign": "KI7HSG", "source": "pota", "frequency": "14.074", "mode": "FT8", "wwffRef":"US-0052"} content = function_app.create_content(req_body) - expected = {'content': 'KI7HSG | POTA | freq: 14.074 | mode: FT8 | loc: US-0052'} + expected = {'content': 'KI7HSG | pota | freq: 14.074 | mode: FT8 | loc: US-0052'} self.assertDictEqual(content, expected) def test_function_app(self): From a363d9b6ad5f1288f1f8bd39c2ccf2b215a56780 Mon Sep 17 00:00:00 2001 From: Trevor Blanarik Date: Sat, 21 Sep 2024 05:09:30 +0000 Subject: [PATCH 3/4] adds a deeplink to sota and pota websites --- function_app.py | 4 ++-- test.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/function_app.py b/function_app.py index a25ad88..687a215 100644 --- a/function_app.py +++ b/function_app.py @@ -43,8 +43,8 @@ def create_spot_deeplink(source, fullCallsign, wwffRef): match source: case "sotawatch": - return "[See their latest spot](https://sotl.as/activators/{fullCallsign})" + return f"[See their latest spot](https://sotl.as/activators/{fullCallsign})" case "pota": - return "[See their latest spot](https://api.pota.app/spot/comments/{fullCallsign}/{wwffRef})" + return f"[See their latest spot](https://api.pota.app/spot/comments/{fullCallsign}/{wwffRef})" case _: return "" \ No newline at end of file diff --git a/test.py b/test.py index 903af9b..1e89bcf 100644 --- a/test.py +++ b/test.py @@ -6,13 +6,13 @@ class TestSpotBot(unittest.TestCase): def test_function_app_basic(self): req_body = {"fullCallsign": "KI7HSG", "source": "pota", "frequency": "14.074", "mode": "FT8", "wwffRef":"US-0052"} content = function_app.create_content(req_body) - expected = {'content': 'KI7HSG | pota | freq: 14.074 | mode: FT8 | loc: US-0052'} + expected = {'content': 'KI7HSG | pota | freq: 14.074 | mode: FT8 | loc: US-0052 | [See their latest spot](https://api.pota.app/spot/comments/KI7HSG/US-0052)', 'flags': 4} self.assertDictEqual(content, expected) def test_function_app(self): req_body = {"fullCallsign": "KI7HSG", "source": "sotawatch", "frequency": "14.074", "mode": "FT8", "summitRef": "ABCD"} content = function_app.create_content(req_body) - expected = {'content': 'KI7HSG | sotawatch | freq: 14.074 | mode: FT8 | loc: ABCD'} + expected = {'content': 'KI7HSG | sotawatch | freq: 14.074 | mode: FT8 | loc: ABCD | [See their latest spot](https://sotl.as/activators/KI7HSG)', 'flags': 4} self.assertDictEqual(content, expected) if __name__ == '__main__': From ca28ca008057d319702be274722fddd5d07154f9 Mon Sep 17 00:00:00 2001 From: Trevor Blanarik Date: Sat, 21 Sep 2024 05:28:36 +0000 Subject: [PATCH 4/4] comment and cleanup --- function_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/function_app.py b/function_app.py index 687a215..f141725 100644 --- a/function_app.py +++ b/function_app.py @@ -31,6 +31,7 @@ def create_content(req_body): spot_deeplink = create_spot_deeplink(source, fullCallsign, wwffRef) + # flags = 4 means it will suppress embeds: https://discord.com/developers/docs/resources/message#message-object-message-flags content = {"content": f"{fullCallsign} | {source} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef} | {spot_deeplink}", "flags": 4} return content @@ -40,7 +41,6 @@ def call_target(content): return func.HttpResponse(response.text, status_code=response.status_code) def create_spot_deeplink(source, fullCallsign, wwffRef): - match source: case "sotawatch": return f"[See their latest spot](https://sotl.as/activators/{fullCallsign})"