/nearby, subscriptions check, geocoding #2

Merged
profitroll merged 30 commits from dev into master 2023-01-02 12:16:38 +02:00
4 changed files with 41 additions and 12 deletions
Showing only changes of commit 85112dc653 - Show all commits

View File

@ -13,7 +13,7 @@ from modules.logging import logWrite
from modules.utils import configGet, locale, should_quote
class DefaultApplicationTemp(dict):
def __init__(self, user: int):
def __init__(self, user: int, reapply: bool = False):
super().__init__({})
self.dict = {
"user": user,
@ -21,7 +21,7 @@ class DefaultApplicationTemp(dict):
"complete": False,
"sent": False,
"state": "fill",
"reapply": False,
"reapply": reapply,
"stage": 1,
"application": {
"1": None,
@ -326,14 +326,14 @@ class HoloUser():
"""
return True if col_applications.find_one({"user": self.id}) is not None else False
def application_restart(self) -> None:
def application_restart(self, reapply: bool = False) -> None:
"""Reset application of a user in tmp collection and replace it with an empty one
"""
if col_tmp.find_one({"user": self.id, "type": "application"}) is None:
col_tmp.insert_one(document=DefaultApplicationTemp(self.id).dict)
else:
col_tmp.delete_one({"user": self.id, "type": "application"})
col_tmp.insert_one(document=DefaultApplicationTemp(self.id).dict)
col_tmp.insert_one(document=DefaultApplicationTemp(self.id, reapply=reapply).dict)
async def application_next(self, query: str, msg: Message) -> None:
"""Move on filling application of user
@ -352,7 +352,7 @@ class HoloUser():
progress = col_tmp.find_one({"user": self.id, "type": "application"})
stage = progress["stage"]
if progress["state"] == "fill":
if progress["state"] == "fill" and progress["sent"] is False:
if stage == 2:
@ -468,7 +468,7 @@ class HoloUser():
progress = col_tmp.find_one({"user": self.id, "type": "sponsorship"})
stage = progress["stage"]
if progress["state"] == "fill":
if progress["state"] == "fill" and progress["sent"] is False:
if stage == 1:

View File

@ -22,7 +22,7 @@ async def callback_reapply_query_accept(app, clb):
col_applications.delete_one({"user": holo_user.id})
col_applications.insert_one({"user": holo_user.id, "date": datetime.now(), "admin": clb.from_user.id, "application": col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}})["application"]})
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}, {"$set": {"state": "approved", "sent": False}})
col_tmp.update_one({"user": holo_user.id, "type": "application"}, {"$set": {"state": "approved", "sent": False}})
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]

View File

@ -34,11 +34,33 @@ async def callback_query_sponsor_yes(app, clb):
logWrite(f"User {holo_user.id} got approved by {clb.from_user.id}")
if col_sponsorships.find_one({"user": holo_user.id}) is not None:
col_sponsorships.update_one({"user": holo_user.id}, {"date": {"$eq": datetime.now()}, "admin": {"$eq": clb.from_user.id}, "sponsorship": {"$eq": col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]}})
col_sponsorships.update_one({"user": holo_user.id},
{
"$set": {
"date": datetime.now(),
"admin": clb.from_user.id,
"sponsorship": col_tmp.find_one({"user": holo_user.id, "type": "sponsorship"})["sponsorship"]
}
}
)
else:
col_sponsorships.insert_one({"user": holo_user.id, "date": datetime.now(), "admin": clb.from_user.id, "sponsorship": col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]})
col_sponsorships.insert_one(
{
"user": holo_user.id,
"date": datetime.now(),
"admin": clb.from_user.id,
"sponsorship": col_tmp.find_one({"user": holo_user.id, "type": "sponsorship"})["sponsorship"]
}
)
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"state": "approved", "sent": False}})
col_tmp.update_one({"user": holo_user.id, "type":"sponsorship"},
{
"$set": {
"state": "approved",
"sent": False
}
}
)
await holo_user.label_set(configGet("destination_group"), col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]["label"])
@ -57,7 +79,14 @@ async def callback_query_sponsor_no(app, clb):
await app.send_message(holo_user.id, locale("sponsor_rejected", "message", locale=holo_user))
logWrite(f"User {holo_user.id} got rejected by {clb.from_user.id}")
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"state": "rejected", "sent": False}})
col_tmp.update_one({"user": holo_user.id, "type": "sponsorship"},
{
"$set": {
"state": "rejected",
"sent": False
}
}
)
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]

View File

@ -19,7 +19,7 @@ async def cmd_reapply(app, msg):
if member.user.id == msg.from_user.id:
left_chat = False
if not left_chat:
holo_user.application_restart()
holo_user.application_restart(reapply=True)
await welcome_pass(app, msg, once_again=True)
else:
await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([