This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/callbacks/sponsorship.py

177 lines
5.5 KiB
Python
Raw Normal View History

2022-12-21 13:25:47 +02:00
from datetime import datetime
from app import app
2023-03-09 17:25:06 +02:00
from pyrogram.types import (
InlineKeyboardMarkup,
InlineKeyboardButton,
ForceReply,
CallbackQuery,
)
2022-12-27 14:23:24 +02:00
from pyrogram.client import Client
2022-12-21 13:25:47 +02:00
from pyrogram import filters
2023-01-06 16:49:51 +02:00
from classes.errors.holo_user import LabelSettingError
from classes.holo_user import HoloUser
2022-12-27 14:23:24 +02:00
from modules.utils import configGet, locale, logWrite, should_quote
2022-12-22 16:05:27 +02:00
from modules.database import col_tmp, col_sponsorships
2022-12-21 13:25:47 +02:00
2023-03-09 17:25:06 +02:00
2022-12-21 13:25:47 +02:00
# Callbacks sponsorship ========================================================================================================
@app.on_callback_query(filters.regex("sponsor_apply_[\s\S]*"))
2022-12-27 14:23:24 +02:00
async def callback_query_sponsor_apply(app: Client, clb: CallbackQuery):
2022-12-21 13:25:47 +02:00
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
2022-12-27 14:23:24 +02:00
if holo_user.application_state()[0] == "fill":
2023-03-09 17:25:06 +02:00
await clb.message.reply_text(
locale("finish_application", "message"), quote=should_quote(clb.message)
)
2022-12-27 14:23:24 +02:00
return
2022-12-21 13:25:47 +02:00
logWrite(f"User {holo_user.id} applied for sponsorship")
2022-12-22 16:05:27 +02:00
holo_user.sponsorship_restart()
2022-12-21 13:25:47 +02:00
2023-03-09 17:25:06 +02:00
edited_markup = [
[
InlineKeyboardButton(
text=str(locale("sponsor_started", "button")), callback_data="nothing"
)
]
]
await clb.message.edit(
text=locale("sponsorship_applying", "message", locale=holo_user),
reply_markup=InlineKeyboardMarkup(edited_markup),
)
await app.send_message(
holo_user.id,
locale(f"sponsor1", "message", locale=holo_user),
reply_markup=ForceReply(
placeholder=str(locale(f"sponsor1", "force_reply", locale=holo_user.locale))
),
)
await clb.answer(
text=locale("sponsor_started", "callback", locale=holo_user).format(
holo_user.id
),
show_alert=False,
)
2022-12-21 13:25:47 +02:00
2022-12-22 16:05:27 +02:00
@app.on_callback_query(filters.regex("sponsor_yes_[\s\S]*"))
2022-12-27 14:36:54 +02:00
async def callback_query_sponsor_yes(app: Client, clb: CallbackQuery):
2022-12-22 16:05:27 +02:00
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
2023-03-09 17:25:06 +02:00
await app.send_message(
configGet("admin", "groups"),
locale("sponsor_approved_by", "message").format(
clb.from_user.first_name, holo_user.id
),
disable_notification=True,
)
await app.send_message(
holo_user.id, locale("sponsor_approved", "message", locale=holo_user)
)
2023-01-02 15:24:29 +02:00
logWrite(f"User {holo_user.id} got sponsorship approved by {clb.from_user.id}")
2022-12-22 16:05:27 +02:00
if col_sponsorships.find_one({"user": holo_user.id}) is not None:
2023-03-09 17:25:06 +02:00
col_sponsorships.update_one(
{"user": holo_user.id},
2022-12-23 13:54:51 +02:00
{
"$set": {
"date": datetime.now(),
"admin": clb.from_user.id,
2023-03-09 17:25:06 +02:00
"sponsorship": col_tmp.find_one(
{"user": holo_user.id, "type": "sponsorship"}
)["sponsorship"],
2022-12-23 13:54:51 +02:00
}
2023-03-09 17:25:06 +02:00
},
2022-12-23 13:54:51 +02:00
)
2022-12-22 16:05:27 +02:00
else:
2022-12-23 13:54:51 +02:00
col_sponsorships.insert_one(
{
"user": holo_user.id,
"date": datetime.now(),
"admin": clb.from_user.id,
2023-03-09 17:25:06 +02:00
"sponsorship": col_tmp.find_one(
{"user": holo_user.id, "type": "sponsorship"}
)["sponsorship"],
2022-12-23 13:54:51 +02:00
}
)
2023-03-09 17:25:06 +02:00
col_tmp.update_one(
{"user": holo_user.id, "type": "sponsorship"},
{"$set": {"state": "approved", "sent": False}},
2022-12-23 13:54:51 +02:00
)
2022-12-22 16:05:27 +02:00
2023-01-05 21:46:47 +02:00
try:
2023-03-09 17:25:06 +02:00
await holo_user.label_set(
configGet("users", "groups"),
col_tmp.find_one(
{"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}}
)["sponsorship"]["label"],
)
2023-01-05 21:46:47 +02:00
except LabelSettingError as exp:
2023-03-09 17:25:06 +02:00
await app.send_message(
configGet("admin", "groups"), exp.__str__(), disable_notification=True
)
2022-12-22 16:05:27 +02:00
2023-03-09 17:25:06 +02:00
edited_markup = [
[
InlineKeyboardButton(
text=str(locale("accepted", "button")), callback_data="nothing"
)
]
]
await app.edit_message_caption(
clb.message.chat.id,
clb.message.id,
caption=clb.message.caption,
reply_markup=InlineKeyboardMarkup(edited_markup),
)
await clb.answer(
text=locale("sponsor_accepted", "callback").format(fullclb[2]), show_alert=False
)
2022-12-22 16:05:27 +02:00
@app.on_callback_query(filters.regex("sponsor_no_[\s\S]*"))
2022-12-27 14:36:54 +02:00
async def callback_query_sponsor_no(app: Client, clb: CallbackQuery):
2022-12-22 16:05:27 +02:00
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
2023-03-09 17:25:06 +02:00
await app.send_message(
configGet("admin", "groups"),
locale("sponsor_rejected_by", "message").format(
clb.from_user.first_name, holo_user.id
),
disable_notification=True,
)
await app.send_message(
holo_user.id, locale("sponsor_rejected", "message", locale=holo_user)
)
2023-01-02 15:24:29 +02:00
logWrite(f"User {holo_user.id} got sponsorship rejected by {clb.from_user.id}")
2022-12-22 16:05:27 +02:00
2023-03-09 17:25:06 +02:00
col_tmp.update_one(
{"user": holo_user.id, "type": "sponsorship"},
{"$set": {"state": "rejected", "sent": False}},
2022-12-23 13:54:51 +02:00
)
2022-12-22 16:05:27 +02:00
2023-03-09 17:25:06 +02:00
edited_markup = [
[
InlineKeyboardButton(
text=str(locale("declined", "button")), callback_data="nothing"
)
]
]
await app.edit_message_caption(
clb.message.chat.id,
clb.message.id,
caption=clb.message.caption,
reply_markup=InlineKeyboardMarkup(edited_markup),
)
await clb.answer(
text=locale("sponsor_rejected", "callback").format(fullclb[2]), show_alert=False
)