Skip to content

Commit

Permalink
fix bug when no previous message
Browse files Browse the repository at this point in the history
  • Loading branch information
tblanarik committed Oct 19, 2024
1 parent b4d8baa commit 0cdd4fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions spotbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand Down

0 comments on commit 0cdd4fa

Please sign in to comment.