diff --git a/spotbot.py b/spotbot.py index e59bedb..d85fbf4 100644 --- a/spotbot.py +++ b/spotbot.py @@ -13,8 +13,11 @@ def __init__(self, http_req, table, discord_http): def process(self): logging.info('Processing HamAlert message') previous_message, message_id = self.get_last_message() - previous_message = self.strikethrough_mesage(previous_message) - content = self.combine_messages(previous_message, self.ham) + if previous_message: + previous_message = self.strikethrough_mesage(previous_message) + content = self.combine_messages(previous_message, self.ham) + else: + content = str(self.ham) message_id = self.discord_http.post_message(content, message_id) self.table.upsert_entity(self.ham.callsign, message_id) diff --git a/test.py b/test.py index c35d9cd..9b7e97e 100644 --- a/test.py +++ b/test.py @@ -13,6 +13,15 @@ def test_spotbot(self): dt = sb.ham.received_time_pt.strftime("%H:%M") self.assertEqual(sb.discord_http.posted_message, f"~~01:05 | KI7HSG | [pota](https://api.pota.app/spot/comments/KI7HSG/US-0052) | freq: 14.074 | mode: FT8 | loc: US-0052~~\n{dt} | KI7HSG | [sotawatch](https://sotl.as/activators/KI7HSG) | freq: 14.074 | mode: FT8 | loc: ABCD") + def test_spotbot_2(self): + sb = spotbot.SpotBot(FakeHttpRequest(), table=FakeHamAlertTable(None), discord_http=FakeDiscordHttp()) + sb.process() + self.assertEqual(sb.table.saved_callsign, "KI7HSG") + self.assertEqual(sb.table.saved_messageId, "9876") + dt = sb.ham.received_time_pt.strftime("%H:%M") + self.assertEqual(sb.discord_http.posted_message, f"{dt} | KI7HSG | [sotawatch](https://sotl.as/activators/KI7HSG) | freq: 14.074 | mode: FT8 | loc: ABCD") + + ''' Fake classes for testing '''