|
1 | 1 | from datetime import datetime
|
2 | 2 | from pydantic import BaseModel
|
3 | 3 | import requests
|
4 |
| -from src.common import submission_link |
| 4 | +from src.common import submission_link, extract_submission_id |
5 | 5 |
|
6 | 6 |
|
7 | 7 | LEETCODE_DAILY_GROUP_ID = '-1002270137956'
|
@@ -44,23 +44,24 @@ def process_message(bot, db, data):
|
44 | 44 | name = f'{first_name} ({username})'
|
45 | 45 |
|
46 | 46 | if text.startswith('/start') or text.startswith('/help'):
|
47 |
| - bot.send_message(chat_id, "Please, send me a submission id for today's daily challenge") |
48 |
| - elif text.isnumeric(): |
49 |
| - submission_id = text |
| 47 | + bot.send_message(chat_id, "Please, send me a submission id or a link to a submission for today's daily challenge") |
| 48 | + return |
| 49 | + |
| 50 | + submission_id = extract_submission_id(text.strip()) |
50 | 51 |
|
51 |
| - if submission_id.isnumeric(): |
| 52 | + if submission_id: |
52 | 53 | print(f"Will update submissions for {username} on {today}: {text}")
|
53 | 54 | result = db.submissions.update_one(
|
54 | 55 | {'username': name, 'date': today, 'chat_id': chat_id},
|
55 |
| - {'$set': {'text': text}}, |
| 56 | + {'$set': {'text': submission_id}}, |
56 | 57 | True,
|
57 | 58 | )
|
58 | 59 |
|
59 |
| - print(username, today, text, result) |
60 |
| - bot.send_message(chat_id, f"Updated submission for {today}: {submission_link(text)}") |
61 |
| - bot.send_message(LEETCODE_DAILY_GROUP_ID, f"New submission from {name}: {submission_link(text)}") |
| 60 | + print(username, today, submission_id, result) |
| 61 | + bot.send_message(chat_id, f"Updated submission for {today}: {submission_link(submission_id)}") |
| 62 | + bot.send_message(LEETCODE_DAILY_GROUP_ID, f"New submission from {name}: {submission_link(submission_id)}") |
62 | 63 | else:
|
63 |
| - bot.send_message(chat_id, "Incorrect input! please send me a submission id") |
| 64 | + bot.send_message(chat_id, "Incorrect input! Please, send me a submission id or a link to a submission") |
64 | 65 | raise ValueError(f"Incorrect link {data}")
|
65 | 66 |
|
66 | 67 | except Exception as e:
|
|
0 commit comments