2023-04-08 02:18:05 +03:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from typing import Union
|
2022-12-27 19:46:17 +02:00
|
|
|
from app import app
|
2022-12-10 11:42:56 +02:00
|
|
|
from pyrogram import filters
|
2023-04-08 02:18:05 +03:00
|
|
|
from pyrogram.types import (
|
|
|
|
InlineKeyboardMarkup,
|
|
|
|
InlineKeyboardButton,
|
|
|
|
ReplyKeyboardMarkup,
|
|
|
|
ReplyKeyboardRemove,
|
|
|
|
ForceReply,
|
|
|
|
Message,
|
|
|
|
)
|
2022-12-27 14:36:54 +02:00
|
|
|
from pyrogram.client import Client
|
2022-12-27 14:23:24 +02:00
|
|
|
from classes.holo_user import HoloUser
|
2022-12-27 19:46:17 +02:00
|
|
|
from modules import custom_filters
|
2022-12-21 13:25:47 +02:00
|
|
|
from modules.utils import locale, should_quote
|
2023-04-08 02:18:05 +03:00
|
|
|
from modules.database import col_sponsorships
|
|
|
|
from convopyro import listen_message
|
|
|
|
|
|
|
|
|
|
|
|
def is_none_or_cancel(message: Union[Message, None]) -> bool:
|
|
|
|
if (
|
|
|
|
message is None
|
|
|
|
or message.text is not None
|
|
|
|
and message.text.lower() == "/cancel"
|
|
|
|
):
|
|
|
|
return True
|
|
|
|
return False
|
2022-12-10 11:42:56 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
|
|
|
|
@app.on_message(
|
|
|
|
custom_filters.enabled_sponsorships
|
|
|
|
& ~filters.scheduled
|
|
|
|
& filters.command(["sponsorship"], prefixes=["/"])
|
|
|
|
& ~custom_filters.banned
|
|
|
|
& (custom_filters.allowed | custom_filters.admin)
|
|
|
|
)
|
2022-12-27 14:36:54 +02:00
|
|
|
async def cmd_sponsorship(app: Client, msg: Message):
|
2023-01-05 15:34:02 +02:00
|
|
|
holo_user = HoloUser(msg.from_user)
|
|
|
|
if holo_user.application_state()[0] == "fill":
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("finish_application", "message", locale=msg.from_user),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|
2022-12-27 19:46:17 +02:00
|
|
|
return
|
2023-01-05 15:34:02 +02:00
|
|
|
if holo_user.spoiler_state() is True:
|
|
|
|
await msg.reply_text(locale("spoiler_in_progress", "message", locale=holo_user))
|
|
|
|
return
|
2023-04-08 02:18:05 +03:00
|
|
|
|
|
|
|
existent = col_sponsorships.find_one(
|
|
|
|
{
|
|
|
|
"user": msg.from_user.id,
|
|
|
|
"sponsorship.expires": {"$gt": datetime.now() - timedelta(days=1)},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if existent is None:
|
|
|
|
await msg.reply_text(
|
|
|
|
locale("sponsorship_apply", "message", locale=msg.from_user),
|
|
|
|
reply_markup=InlineKeyboardMarkup(
|
2023-03-09 17:25:06 +02:00
|
|
|
[
|
2023-04-08 02:18:05 +03:00
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
text=str(
|
|
|
|
locale("sponsor_apply", "button", locale=msg.from_user)
|
|
|
|
),
|
|
|
|
callback_data=f"sponsor_apply_{msg.from_user.id}",
|
|
|
|
)
|
|
|
|
]
|
2023-03-09 17:25:06 +02:00
|
|
|
]
|
2023-04-08 02:18:05 +03:00
|
|
|
),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
await msg.reply_text(
|
|
|
|
f'You have an active membership for **{existent["sponsorship"]["streamer"]}**. Wanna resubmit it once more?',
|
|
|
|
reply_markup=ReplyKeyboardMarkup(
|
|
|
|
[["Yep, use old data"], ["Nope, refill it once more"]],
|
|
|
|
resize_keyboard=True,
|
|
|
|
one_time_keyboard=True,
|
2023-03-09 17:25:06 +02:00
|
|
|
),
|
|
|
|
)
|
2023-04-08 02:18:05 +03:00
|
|
|
|
|
|
|
answer_decision = await listen_message(app, msg.chat.id)
|
|
|
|
|
|
|
|
if is_none_or_cancel(answer_decision):
|
|
|
|
return
|
|
|
|
|
|
|
|
input_streamer = existent["sponsorship"]["streamer"]
|
|
|
|
|
|
|
|
if answer_decision.text.lower() == "yep, use old data":
|
|
|
|
await answer_decision.reply_text(
|
|
|
|
"Okay, reusing the old data.\n\nUntil when is your sub?\n\nEnter the date as DD.MM.YYYY",
|
|
|
|
reply_markup=ForceReply(placeholder="Expiry date as DD.MM.YYYY"),
|
|
|
|
)
|
|
|
|
while True:
|
|
|
|
answer_date = await listen_message(app, msg.chat.id)
|
|
|
|
|
|
|
|
if is_none_or_cancel(answer_date):
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
input_dt = datetime.strptime(answer_date.text, "%d.%m.%Y")
|
|
|
|
break
|
|
|
|
except ValueError:
|
|
|
|
await answer_date.reply_text(
|
|
|
|
"Invalid date! Provide as DD.MM.YYYY",
|
|
|
|
reply_markup=ForceReply(placeholder="Expiry date as DD.MM.YYYY"),
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
while True:
|
|
|
|
await answer_date.reply_text(
|
|
|
|
"Alright. Now provide your proof **as a single screenshot**"
|
|
|
|
)
|
|
|
|
answer_proof = await listen_message(app, msg.chat.id)
|
|
|
|
|
|
|
|
if is_none_or_cancel(answer_proof):
|
|
|
|
return
|
|
|
|
|
|
|
|
if answer_proof.photo is None:
|
|
|
|
await answer_proof.reply_text(
|
|
|
|
"Please, provide proof **as a single screenshot**"
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
input_proof = answer_proof.photo.file_id
|
|
|
|
break
|
|
|
|
await msg.reply_text(
|
|
|
|
f'Almost done. Do you want to keep the label **{existent["sponsorship"]["label"]}** or you want to change it?',
|
|
|
|
reply_markup=ReplyKeyboardMarkup(
|
|
|
|
[["Keep the old one"], ["Set a new one instead"]],
|
|
|
|
resize_keyboard=True,
|
|
|
|
one_time_keyboard=True,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
answer_label_decision = await listen_message(app, msg.chat.id)
|
|
|
|
|
|
|
|
if is_none_or_cancel(answer_label_decision):
|
|
|
|
return
|
|
|
|
|
|
|
|
if answer_label_decision.text is None:
|
|
|
|
await answer_label_decision.reply_text(
|
|
|
|
"Please, choose a valid option.",
|
|
|
|
reply_markup=ReplyKeyboardMarkup(
|
|
|
|
[["Keep the old one"], ["Set a new one instead"]],
|
|
|
|
resize_keyboard=True,
|
|
|
|
one_time_keyboard=True,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if answer_label_decision.text.lower() == "keep the old one":
|
|
|
|
input_label = existent["sponsorship"]["label"]
|
|
|
|
elif answer_label_decision.text.lower() == "set a new one instead":
|
|
|
|
await answer_label_decision.reply_text(
|
|
|
|
"Okay. Please provide a new label up to 16 characters long",
|
|
|
|
reply_markup=ForceReply(placeholder="New label"),
|
|
|
|
)
|
|
|
|
while True:
|
|
|
|
answer_label = await listen_message(app, msg.chat.id)
|
|
|
|
|
|
|
|
if is_none_or_cancel(answer_label_decision):
|
|
|
|
return
|
|
|
|
|
|
|
|
if answer_label.text is None:
|
|
|
|
await answer_label.reply_text(
|
|
|
|
"Please provide valid label",
|
|
|
|
reply_markup=ForceReply(placeholder="New label"),
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
elif len(answer_label.text) > 16:
|
|
|
|
await answer_label.reply_text(
|
|
|
|
"Please provide a label not longer than 16 characters long",
|
|
|
|
reply_markup=ForceReply(placeholder="New label"),
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
|
|
|
|
input_label = answer_label.text
|
|
|
|
break
|
|
|
|
|
|
|
|
await msg.reply_text(
|
|
|
|
f"So we did it for streamer **{input_streamer}**, til {input_dt.strftime('%d.%m.%Y')}, proofed by `{input_proof}` and labeled as **{input_label}**.",
|
|
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
elif answer_decision.text.lower() == "nope, refill it once more":
|
|
|
|
await msg.reply_text(
|
|
|
|
locale("sponsorship_apply", "message", locale=msg.from_user),
|
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
text=str(
|
|
|
|
locale("sponsor_apply", "button", locale=msg.from_user)
|
|
|
|
),
|
|
|
|
callback_data=f"sponsor_apply_{msg.from_user.id}",
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
await answer_decision.reply_text(
|
|
|
|
"Invalid option!", reply_markup=ReplyKeyboardRemove()
|
|
|
|
)
|
|
|
|
return
|
2022-12-27 19:46:17 +02:00
|
|
|
# else:
|
|
|
|
# await msg.reply_text(locale("sponsorship_application_empty", "message"))
|