Added language_code context
This commit is contained in:
@@ -100,13 +100,13 @@ class HoloUser():
|
||||
self.locale = holo_user["tg_locale"]
|
||||
self.username = holo_user["tg_username"]
|
||||
|
||||
if isinstance(user, User) and (self.name != user.first_name):
|
||||
if isinstance(user, User) and ((self.name != user.first_name) and (user.first_name is None)):
|
||||
self.set("tg_name", user.first_name)
|
||||
|
||||
if isinstance(user, User) and (self.phone != user.phone_number):
|
||||
self.set("tg_phone", user.phone_number)
|
||||
|
||||
if isinstance(user, User) and ((self.locale != user.language_code) and (user.language_code != None)):
|
||||
if isinstance(user, User) and ((self.locale != user.language_code) and (user.language_code is not None)):
|
||||
self.set("tg_locale", user.language_code)
|
||||
|
||||
if isinstance(user, User) and (self.username != user.username):
|
||||
@@ -328,39 +328,39 @@ class HoloUser():
|
||||
input_dt = datetime.strptime(query, "%d.%m.%Y")
|
||||
except ValueError:
|
||||
logWrite(f"User {msg.from_user.id} failed stage {stage} due to sending invalid date format")
|
||||
await msg.reply_text(locale(f"question2_invalid", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply"))))
|
||||
await msg.reply_text(locale(f"question2_invalid", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
return
|
||||
|
||||
if datetime.now() <= input_dt:
|
||||
logWrite(f"User {msg.from_user.id} failed stage {stage} due to joking")
|
||||
await msg.reply_text(locale("question2_joke", "message"), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply"))))
|
||||
await msg.reply_text(locale("question2_joke", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply", locale=self.locale))))
|
||||
return
|
||||
|
||||
elif ((datetime.now() - input_dt).days) < ((datetime.now() - datetime.now().replace(year=datetime.now().year - configGet("age_allowed"))).days):
|
||||
logWrite(f"User {msg.from_user.id} failed stage {stage} due to being underage")
|
||||
await msg.reply_text(locale("question2_underage", "message").format(str(configGet("age_allowed"))), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply"))))
|
||||
await msg.reply_text(locale("question2_underage", "message", locale=self.locale).format(str(configGet("age_allowed"))), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply", locale=self.locale))))
|
||||
return
|
||||
|
||||
else:
|
||||
print(f'Look: {((datetime.now() - input_dt).days)} > {(datetime.now() - datetime.now().replace(year=datetime.now().year - configGet("age_allowed"))).days}')
|
||||
progress["application"][str(stage)] = input_dt
|
||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "application"}}, {"$set": {"application": progress["application"], "stage": progress["stage"]+1}})
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply"))))
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply", locale=self.locale))))
|
||||
|
||||
elif stage == 3:
|
||||
try:
|
||||
result = (get(f"http://api.geonames.org/searchJSON?q={query}&maxRows=1&countryBias=UA&lang=uk&orderby=relevance&featureClass=P&featureClass=A&username={configGet('username', 'geocoding')}")).json()
|
||||
progress["application"][str(stage)] = result["geonames"][0]
|
||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "application"}}, {"$set": {"application": progress["application"], "stage": progress["stage"]+1}})
|
||||
await msg.reply_text(locale(f"question3_found", "message").format(result["geonames"][0]["name"], result["geonames"][0]["adminName1"]))
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply"))))
|
||||
await msg.reply_text(locale(f"question3_found", "message", locale=self.locale).format(result["geonames"][0]["name"], result["geonames"][0]["adminName1"]))
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply", locale=self.locale))))
|
||||
except (ValueError, KeyError, IndexError):
|
||||
await msg.reply_text(locale(f"question3_invalid", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply"))))
|
||||
await msg.reply_text(locale(f"question3_invalid", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
return
|
||||
except Exception as exp:
|
||||
await msg.reply_text(locale("question3_error", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply"))))
|
||||
await msg.reply_text(locale("question3_error", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
try:
|
||||
await app.send_message(configGet("owner"), locale("question3_traceback", "message").format(query, exp, print_exc()))
|
||||
await app.send_message(configGet("owner"), locale("question3_traceback", "message", locale=self.locale).format(query, exp, print_exc()))
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
logWrite(f"Could not notify admin about failure when sending message! Admin has never interacted with bot!")
|
||||
return
|
||||
@@ -373,20 +373,20 @@ class HoloUser():
|
||||
for question in progress["application"]:
|
||||
if i == 2:
|
||||
age = relativedelta(datetime.now(), progress['application']['2'])
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {progress['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles', locale=self.locale)} {progress['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
|
||||
elif i == 3:
|
||||
if progress['application']['3']['countryCode'] == "UA":
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {progress['application']['3']['name']} ({progress['application']['3']['adminName1']})")
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles', locale=self.locale)} {progress['application']['3']['name']} ({progress['application']['3']['adminName1']})")
|
||||
else:
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {progress['application']['3']['name']} ({progress['application']['3']['adminName1']}, {progress['application']['3']['countryName']})")
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles', locale=self.locale)} {progress['application']['3']['name']} ({progress['application']['3']['adminName1']}, {progress['application']['3']['countryName']})")
|
||||
else:
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {progress['application'][question]}")
|
||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles', locale=self.locale)} {progress['application'][question]}")
|
||||
i += 1
|
||||
await msg.reply_text(locale("confirm", "message").format("\n".join(application_content)), reply_markup=ReplyKeyboardMarkup(locale("confirm", "keyboard"), resize_keyboard=True))
|
||||
await msg.reply_text(locale("confirm", "message", locale=self.locale).format("\n".join(application_content)), reply_markup=ReplyKeyboardMarkup(locale("confirm", "keyboard", locale=self.locale), resize_keyboard=True))
|
||||
|
||||
else:
|
||||
progress["application"][str(stage)] = query
|
||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "application"}}, {"$set": {"application": progress["application"], "stage": progress["stage"]+1}})
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply"))))
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply", locale=self.locale))))
|
||||
|
||||
logWrite(f"User {self.id} completed stage {stage} of application")
|
Reference in New Issue
Block a user