refactor: add some comments 401
This commit is contained in:
parent
853d49205e
commit
3161ffd2f2
1 changed files with 19 additions and 8 deletions
27
main.py
27
main.py
|
|
@ -273,35 +273,46 @@ def searchCodes(page, pbar):
|
||||||
with LOCK:
|
with LOCK:
|
||||||
pbar.update(1)
|
pbar.update(1)
|
||||||
|
|
||||||
# Translating Code: 401
|
# Event Code: 401 Show Text
|
||||||
if page['list'][i]['code'] == 401:
|
if page['list'][i]['code'] == 401:
|
||||||
# Remove repeating characters because it confuses ChatGPT
|
# Remove repeating characters because it confuses ChatGPT
|
||||||
page['list'][i]['parameters'][0] = re.sub(r'(.)\1{2,}', r'\1\1\1\1', page['list'][i]['parameters'][0]) # Remove repeating characters
|
page['list'][i]['parameters'][0] = re.sub(r'(.)\1{2,}', r'\1\1\1\1', page['list'][i]['parameters'][0])
|
||||||
currentGroup.append(page['list'][i]['parameters'][0])
|
|
||||||
|
|
||||||
|
# Using this to keep track of 401's in a row. Throws IndexError at EndOfList (Expected Behavior)
|
||||||
|
currentGroup.append(page['list'][i]['parameters'][0])
|
||||||
while (page['list'][i+1]['code'] == 401):
|
while (page['list'][i+1]['code'] == 401):
|
||||||
del page['list'][i]
|
del page['list'][i]
|
||||||
currentGroup.append(page['list'][i]['parameters'][0])
|
currentGroup.append(page['list'][i]['parameters'][0])
|
||||||
|
|
||||||
# Unlisted Code
|
# Join up 401 groups for better translation.
|
||||||
else:
|
|
||||||
if len(currentGroup) > 0:
|
if len(currentGroup) > 0:
|
||||||
text = ''.join(currentGroup)
|
text = ''.join(currentGroup)
|
||||||
text = text.replace('\\n', '') # Improves translation but may break certain games
|
|
||||||
|
# Improves translation but may break certain games
|
||||||
|
text = text.replace('\\n', '')
|
||||||
text = text.replace('”', '')
|
text = text.replace('”', '')
|
||||||
|
|
||||||
|
# Translate
|
||||||
response = translateGPT(text, ' '.join(textHistory))
|
response = translateGPT(text, ' '.join(textHistory))
|
||||||
tokens += response[1]
|
tokens += response[1]
|
||||||
translatedText = response[0]
|
translatedText = response[0]
|
||||||
|
|
||||||
# TextHistory is what we use to give GPT Context, so thats appended here.
|
# TextHistory is what we use to give GPT Context, so thats appended here.
|
||||||
# translatedText = startString + translatedText + endString
|
|
||||||
textHistory.append(translatedText)
|
textHistory.append(translatedText)
|
||||||
translatedText = textwrap.fill(translatedText, width=50)
|
translatedText = textwrap.fill(translatedText, width=50)
|
||||||
page['list'][i-1]['parameters'][0] = translatedText
|
page['list'][i]['parameters'][0] = translatedText
|
||||||
if len(textHistory) > maxHistory:
|
if len(textHistory) > maxHistory:
|
||||||
textHistory.pop(0)
|
textHistory.pop(0)
|
||||||
currentGroup = []
|
currentGroup = []
|
||||||
|
|
||||||
|
# Event Code: 102 Show Choice
|
||||||
|
if (list['code'] == 102):
|
||||||
|
for i, choice in enumerate(list['parameters'][0]):
|
||||||
|
list['parameters'][0][i] = checkLine(choice)
|
||||||
|
|
||||||
|
# Unlisted Code
|
||||||
|
else:
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# This is part of the logic so we just pass it.
|
# This is part of the logic so we just pass it.
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue