|
25 | 25 | MumbleException, |
26 | 26 | ) |
27 | 27 | from utils import (Connection, encode_replay, decode_replay, |
28 | | - gen_random_str, is_valid_uuid4) |
| 28 | + gen_random_str, is_valid_uuid4, get_text) |
29 | 29 | from enochecker3.utils import assert_equals, assert_in |
30 | 30 | from urllib.parse import urlparse |
31 | 31 |
|
@@ -63,16 +63,30 @@ async def putflag_replay( |
63 | 63 |
|
64 | 64 | con.log_debug('Get Text') |
65 | 65 | era = random.choice(['Ancient', 'Medieval', 'Victorian', 'Future']) |
66 | | - # TODO: check if text / source / book / paragraph are correct |
67 | 66 | try: |
68 | | - text = await con.client.get(f'/text?era={era}') |
69 | | - text.raise_for_status() |
70 | | - source = text.json().get('source') |
71 | | - book = text.json().get('book') |
72 | | - paragraph = text.json().get('paragraph') |
| 67 | + rs = await con.client.get(f'/text?era={era}') |
| 68 | + rs.raise_for_status() |
| 69 | + text = rs.json().get('text') |
| 70 | + source = rs.json().get('source') |
| 71 | + book = int(rs.json().get('book')) |
| 72 | + paragraph = int(rs.json().get('paragraph')) |
| 73 | + |
| 74 | + loop = asyncio.get_running_loop() |
| 75 | + text_db = await loop.run_in_executor( |
| 76 | + None, lambda: get_text(era, source, book, paragraph) |
| 77 | + ) |
| 78 | + |
73 | 79 | except Exception as e: |
74 | 80 | con.log_error('Failed to get text', e) |
75 | 81 |
|
| 82 | + if text_db is None: |
| 83 | + con.log_debug('Text from DB returned None') |
| 84 | + raise MumbleException("Failed to get text") |
| 85 | + if text_db != text: |
| 86 | + con.log_debug(f"Text from DB doesn't match. DB: { |
| 87 | + text_db} | Actual: {text}") |
| 88 | + raise MumbleException("Failed to get text") |
| 89 | + |
76 | 90 | time = random.choice([15, 30, 60, 120]) |
77 | 91 | end_time = datetime.now(timezone.utc) |
78 | 92 | start_time = end_time - timedelta(seconds=time) |
@@ -852,17 +866,29 @@ async def putnoise_profile(task: PutnoiseCheckerTaskMessage, db: ChainDB, logger |
852 | 866 |
|
853 | 867 | con.log_debug('Get Text') |
854 | 868 | era = random.choice(['Ancient', 'Medieval', 'Victorian', 'Future']) |
855 | | - # TODO: check if text / source / book / paragraph are correct |
856 | 869 | try: |
857 | 870 | res1 = await con.client.get(f'/text?era={era}') |
858 | 871 | res1.raise_for_status() |
859 | 872 | source = res1.json().get('source') |
860 | | - book = res1.json().get('book') |
861 | | - paragraph = res1.json().get('paragraph') |
| 873 | + book = int(res1.json().get('book')) |
| 874 | + paragraph = int(res1.json().get('paragraph')) |
862 | 875 | text = res1.json().get('text') |
| 876 | + |
| 877 | + loop = asyncio.get_running_loop() |
| 878 | + text_db = await loop.run_in_executor( |
| 879 | + None, lambda: get_text(era, source, book, paragraph) |
| 880 | + ) |
863 | 881 | except Exception as e: |
864 | 882 | con.log_error('Failed to get text', e) |
865 | 883 |
|
| 884 | + if text_db is None: |
| 885 | + con.log_debug('Text from DB returned None') |
| 886 | + raise MumbleException("Failed to get text") |
| 887 | + if text_db != text: |
| 888 | + con.log_debug(f"Text from DB doesn't match. DB: { |
| 889 | + text_db} | Actual: {text}") |
| 890 | + raise MumbleException("Failed to get text") |
| 891 | + |
866 | 892 | mode = random.choice(["time", "word"]) |
867 | 893 | amount_words = random.choice([15, 25, 50, 100]) |
868 | 894 | if mode == "time": |
@@ -1332,7 +1358,6 @@ async def receive_messages(): |
1332 | 1358 | """ |
1333 | 1359 |
|
1334 | 1360 |
|
1335 | | -# TODO: widen the scope of this? |
1336 | 1361 | @checker.havoc(0) |
1337 | 1362 | async def havoc_text(task: HavocCheckerTaskMessage, logger: LoggerAdapter, client: AsyncClient): |
1338 | 1363 | logger.info(f"Havoc 0 (text) {client.base_url}") |
|
0 commit comments