Photo ID used instead of files for sponsorships
This commit is contained in:
parent
373f2332a0
commit
ee288a1983
@ -1,5 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from traceback import print_exc
|
from traceback import format_exc
|
||||||
from app import app, isAnAdmin
|
from app import app, isAnAdmin
|
||||||
from typing import Any, List, Literal, Union
|
from typing import Any, List, Literal, Union
|
||||||
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message, Photo, Video, Document, Animation, Voice, ForceReply, ReplyKeyboardMarkup
|
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message, Photo, Video, Document, Animation, Voice, ForceReply, ReplyKeyboardMarkup
|
||||||
@ -8,7 +8,7 @@ from dateutil.relativedelta import relativedelta
|
|||||||
from classes.errors.geo import PlaceNotFoundError
|
from classes.errors.geo import PlaceNotFoundError
|
||||||
from modules.database import col_tmp, col_users, col_applications, col_sponsorships, col_messages, col_spoilers
|
from modules.database import col_tmp, col_users, col_applications, col_sponsorships, col_messages, col_spoilers
|
||||||
from modules.logging import logWrite
|
from modules.logging import logWrite
|
||||||
from modules.utils import configGet, create_tmp, download_tmp, find_location, locale, should_quote
|
from modules.utils import configGet, find_location, locale, should_quote
|
||||||
|
|
||||||
class DefaultApplicationTemp(dict):
|
class DefaultApplicationTemp(dict):
|
||||||
def __init__(self, user: int, reapply: bool = False):
|
def __init__(self, user: int, reapply: bool = False):
|
||||||
@ -71,6 +71,10 @@ class LabelTooLongError(Exception):
|
|||||||
self.label = label
|
self.label = label
|
||||||
super().__init__(f"Could not set label to '{label}' because it is {len(label)} characters long (16 is maximum)")
|
super().__init__(f"Could not set label to '{label}' because it is {len(label)} characters long (16 is maximum)")
|
||||||
|
|
||||||
|
class LabelSettingError(Exception):
|
||||||
|
def __init__(self, exp: Exception, trace: str) -> None:
|
||||||
|
super().__init__(f"❌ **Could not set label**\n\nException: `{exp}`\n\n**Traceback:**\n```\n{trace}\n```")
|
||||||
|
|
||||||
class HoloUser():
|
class HoloUser():
|
||||||
"""This object represents a user of HoloChecker bot.
|
"""This object represents a user of HoloChecker bot.
|
||||||
It is primarily used to interact with a database in a more python-friendly way,
|
It is primarily used to interact with a database in a more python-friendly way,
|
||||||
@ -266,9 +270,9 @@ class HoloUser():
|
|||||||
|
|
||||||
# Report to admin and to sender about message sending failure
|
# Report to admin and to sender about message sending failure
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
logWrite(f"Exception {exp} happened as {context.from_user.id} tried to send message to {self.id}. Traceback:\n{print_exc()}")
|
logWrite(f"Exception {exp} happened as {context.from_user.id} tried to send message to {self.id}. Traceback:\n{format_exc()}")
|
||||||
try:
|
try:
|
||||||
await app.send_message(configGet("owner"), locale("message_traceback", "message").format(context.from_user.id, self.id, exp, print_exc()))
|
await app.send_message(configGet("owner"), locale("message_traceback", "message").format(context.from_user.id, self.id, exp, format_exc()))
|
||||||
except bad_request_400.PeerIdInvalid:
|
except bad_request_400.PeerIdInvalid:
|
||||||
logWrite(f"Could not notify admin about failure when sending message! Admin has never interacted with bot!")
|
logWrite(f"Could not notify admin about failure when sending message! Admin has never interacted with bot!")
|
||||||
await context.reply_text(locale("message_error", "message"), quote=should_quote(context))
|
await context.reply_text(locale("message_error", "message"), quote=should_quote(context))
|
||||||
@ -288,10 +292,9 @@ class HoloUser():
|
|||||||
if not await isAnAdmin(self.id):
|
if not await isAnAdmin(self.id):
|
||||||
await app.set_administrator_title(configGet("users", "groups"), self.id, label)
|
await app.set_administrator_title(configGet("users", "groups"), self.id, label)
|
||||||
self.set("label", label)
|
self.set("label", label)
|
||||||
except bad_request_400.UserCreator:
|
except Exception as exp:
|
||||||
logWrite(f"Could not set {self.id}'s title to '{self.label}' because of bad_request_400.UserCreator")
|
logWrite(f"Could not set {self.id}'s title to '{self.label}' due to {exp}")
|
||||||
except bad_request_400.ChatAdminRequired:
|
raise LabelSettingError(exp, format_exc())
|
||||||
logWrite(f"Could not set {self.id}'s title to '{self.label}' because of bad_request_400.ChatAdminRequired")
|
|
||||||
|
|
||||||
async def label_reset(self, chat: Chat) -> None:
|
async def label_reset(self, chat: Chat) -> None:
|
||||||
"""Reset label in destination group
|
"""Reset label in destination group
|
||||||
@ -391,7 +394,6 @@ class HoloUser():
|
|||||||
return
|
return
|
||||||
|
|
||||||
else:
|
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
|
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}})
|
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", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply", locale=self.locale))))
|
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))))
|
||||||
@ -412,7 +414,7 @@ class HoloUser():
|
|||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
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))))
|
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:
|
try:
|
||||||
await app.send_message(configGet("owner"), locale("question3_traceback", "message", locale=self.locale).format(query, exp, print_exc()))
|
await app.send_message(configGet("owner"), locale("question3_traceback", "message", locale=self.locale).format(query, exp, format_exc()))
|
||||||
except bad_request_400.PeerIdInvalid:
|
except bad_request_400.PeerIdInvalid:
|
||||||
logWrite(f"Could not notify admin about failure when sending message! Admin has never interacted with bot!")
|
logWrite(f"Could not notify admin about failure when sending message! Admin has never interacted with bot!")
|
||||||
return
|
return
|
||||||
@ -483,12 +485,9 @@ class HoloUser():
|
|||||||
* msg (`Message`): Message that should receive replies
|
* msg (`Message`): Message that should receive replies
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if col_tmp.find_one({"user": self.id, "type": "sponsorship"}) is not None:
|
progress = col_tmp.find_one({"user": self.id, "type": "sponsorship"})
|
||||||
|
|
||||||
progress = col_tmp.find_one({"user": self.id, "type": "sponsorship"})
|
if progress is not None:
|
||||||
|
|
||||||
if progress is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
stage = progress["stage"]
|
stage = progress["stage"]
|
||||||
|
|
||||||
@ -522,7 +521,7 @@ class HoloUser():
|
|||||||
elif stage == 3:
|
elif stage == 3:
|
||||||
|
|
||||||
if photo is not None:
|
if photo is not None:
|
||||||
progress["sponsorship"]["proof"] = await download_tmp(app, photo.file_id)
|
progress["sponsorship"]["proof"] = photo.file_id
|
||||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"sponsorship": progress["sponsorship"], "stage": progress["stage"]+1}})
|
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"sponsorship": progress["sponsorship"], "stage": progress["stage"]+1}})
|
||||||
await msg.reply_text(locale(f"sponsor{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor{stage+1}", "force_reply", locale=self.locale))))
|
await msg.reply_text(locale(f"sponsor{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor{stage+1}", "force_reply", locale=self.locale))))
|
||||||
|
|
||||||
@ -533,7 +532,7 @@ class HoloUser():
|
|||||||
progress["sponsorship"]["label"] = query
|
progress["sponsorship"]["label"] = query
|
||||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"sponsorship": progress["sponsorship"], "complete": True}})
|
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"sponsorship": progress["sponsorship"], "complete": True}})
|
||||||
await msg.reply_photo(
|
await msg.reply_photo(
|
||||||
photo=create_tmp(progress["sponsorship"]["proof"], kind="image"),
|
photo=progress["sponsorship"]["proof"],
|
||||||
caption=locale("sponsor_confirm", "message", locale=self.locale).format(
|
caption=locale("sponsor_confirm", "message", locale=self.locale).format(
|
||||||
progress["sponsorship"]["streamer"],
|
progress["sponsorship"]["streamer"],
|
||||||
progress["sponsorship"]["expires"].strftime("%d.%m.%Y"),
|
progress["sponsorship"]["expires"].strftime("%d.%m.%Y"),
|
||||||
|
@ -115,13 +115,11 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
|
|||||||
if question == "expires":
|
if question == "expires":
|
||||||
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question].strftime('%d.%m.%Y')}")
|
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question].strftime('%d.%m.%Y')}")
|
||||||
elif question == "proof":
|
elif question == "proof":
|
||||||
filename = uuid1()
|
continue
|
||||||
with open(f"tmp{sep}{filename}.jpg", "wb") as f:
|
|
||||||
f.write(tmp_sponsorship['sponsorship']['proof'])
|
|
||||||
else:
|
else:
|
||||||
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question]}")
|
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question]}")
|
||||||
|
|
||||||
await app.send_photo(chat_id=configGet("admin", "groups"), photo=f"tmp{sep}{filename}.jpg", caption=(locale("sponsor_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(sponsorship_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
|
await app.send_photo(chat_id=configGet("admin", "groups"), photo=tmp_sponsorship["sponsorship"]["proof"], caption=(locale("sponsor_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(sponsorship_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(text=str(locale("sponsor_yes", "button")), callback_data=f"sponsor_yes_{holo_user.id}")
|
InlineKeyboardButton(text=str(locale("sponsor_yes", "button")), callback_data=f"sponsor_yes_{holo_user.id}")
|
||||||
@ -133,7 +131,7 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
remove(f"tmp{sep}{filename}.jpg")
|
# remove(f"tmp{sep}{filename}.jpg")
|
||||||
|
|
||||||
logWrite(f"User {holo_user.id} sent his sponsorship application and it will now be reviewed")
|
logWrite(f"User {holo_user.id} sent his sponsorship application and it will now be reviewed")
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
"bsonType": "date"
|
"bsonType": "date"
|
||||||
},
|
},
|
||||||
"sponsorship.proof": {
|
"sponsorship.proof": {
|
||||||
"bsonType": "binData"
|
"bsonType": "string"
|
||||||
},
|
},
|
||||||
"sponsorship.label": {
|
"sponsorship.label": {
|
||||||
"bsonType": "string"
|
"bsonType": "string"
|
||||||
|
Reference in New Issue
Block a user