third one

This commit is contained in:
2023-11-14 17:30:07 +03:00
parent 8b9298b34c
commit 2251d5a3e9
2 changed files with 60 additions and 14 deletions

View File

@ -86,19 +86,6 @@ def get_group(tg_chat: TgChat) -> Group:
@bot.message_handler(commands=["start"])
async def start(msg: Message):
if msg.chat.type == "private":
# if user := session.query(User).filter(User.id == msg.chat.id).first():
# await bot.send_message(
# chat_id=msg.chat.id,
# text=textbook.private_info.format(count=len(user.fund_members)),
# )
# else:
# user = User(
# id=msg.chat.id,
# name=msg.from_user.first_name,
# username=msg.from_user.username,
# )
# session.add(user)
# session.commit()
user = get_user(msg.from_user)
await bot.send_message(
chat_id=msg.chat.id,
@ -352,6 +339,27 @@ async def contributed(call: types.CallbackQuery):
reply_markup=keyboards.fund_markup(),
parse_mode="html",
)
if (
fund.members.count()
== fund.members.filter(FundMember.contributed == True).count()
):
setattr(fund, "active", False)
session.commit()
await bot.edit_message_text(
text=get_fund_text(fund),
chat_id=call.message.chat.id,
message_id=call.message.id,
reply_markup=None,
parse_mode="html",
)
await bot.send_message(
chat_id=call.message.chat.id,
text=textbook.fund_completed.format(
fund_name=fund.name,
owner_str=f'<a href="tg://user?id={fund.owner.id}">{fund.owner.name}</a>',
),
parse_mode="html",
)
else:
await bot.answer_callback_query(
callback_query_id=call.id,
@ -371,6 +379,38 @@ async def contributed(call: types.CallbackQuery):
)
@bot.message_handler(commands=["remind"])
async def remind(msg: Message):
if msg.chat.type in ("group", "supergroup"):
group = get_group(msg.chat)
if (
fund := session.query(Fund)
.filter(Fund.group_id == group.id, Fund.active == True)
.first()
):
not_contributed = fund.members.filter(FundMember.contributed == False).all()
if len(not_contributed):
s = ""
for fm in not_contributed:
s += f'<a href="tg://user?id={fm.user.id}">{fm.user.name}</a>\n'
await bot.send_message(
chat_id=msg.chat.id,
text=textbook.remind.format(fund_name=fund.name, s=s),
parse_mode="html",
)
else:
await bot.send_message(
chat_id=msg.chat.id,
text=textbook.remind_already.format(fund_name=fund.name),
parse_mode="html",
)
else:
await bot.send_message(
chat_id=msg.chat.id,
text=textbook.fund_not_found,
)
@bot.message_handler(commands=["mystate"])
async def mystate(msg: Message):
state = await bot.get_state(user_id=msg.from_user.id)