penis
All checks were successful
docker / docker-push (push) Successful in 58s

This commit is contained in:
2026-03-11 13:35:50 +03:00
parent 4b354afde4
commit 9e231884f2

View File

@ -37,8 +37,8 @@ class Role(Enum):
@dataclass @dataclass
class Gift: # ебаный пиздец я ебал питон class Gift:
name: str | None = None name: str
description: str | None = None description: str | None = None
link: str | None = None link: str | None = None
picture: str | None = None picture: str | None = None
@ -61,6 +61,25 @@ def is_member(id: int) -> bool:
return True return True
else: else:
return False return False
def gift_text(gift: Gift, id: int) -> str:
text = f"🎁 Название: {gift.name}"
if gift.description is not None:
text += f"\n📃 Описание: {gift.description}"
if gift.link is not None:
text += f"\n📎 Ссылка: {gift.description}"
if is_admin(id):
return text
else:
if gift.presenter is None:
text += f"\n😭 Дарит: Никто"
else:
text += f"\n👤 Дарит: {gift.presenter}"
return text
@dp.message(Command("start")) @dp.message(Command("start"))
@ -139,12 +158,10 @@ async def command_start_handler(message: Message, state: FSMContext) -> None:
@dp.message(Form.waiting_for_gift_add) @dp.message(Form.waiting_for_gift_add)
async def process_answer(message: Message, state: FSMContext): async def process_answer(message: Message, state: FSMContext):
gift = Gift()
text = message.text or message.caption text = message.text or message.caption
if len(text.splitlines()) >= 1: if len(text.splitlines()) >= 1:
gift.name = text.splitlines()[0] gift = Gift(text.splitlines()[0])
if len(text.splitlines()) >= 2: if len(text.splitlines()) >= 2:
gift.description = text.splitlines()[1] gift.description = text.splitlines()[1]
@ -185,17 +202,28 @@ async def process_answer(message: Message, state: FSMContext):
async def command_start_handler(message: Message, state: FSMContext) -> None: async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.clear() await state.clear()
res = cur.execute("SELECT * FROM gifts").fetchall() res = cur.execute("SELECT * FROM gifts WHERE presenter IS NULL").fetchall()
gifts = list(map(lambda x: Gift(x[0], x[1], x[2], x[3], x[4]),res))
for gift in gifts:
text = gift_text(gift, message.from_user.id)
if gift.picture is None:
await message.answer(text)
else:
await message.answer_photo(photo = gift.picture, caption=text)
@dp.message(Command("my_gift"))
async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.clear()
res = cur.execute("SELECT * FROM gifts WHERE presenter=?", (message.from_user.id, )).fetchall()
gifts = list(map(lambda x: Gift(x[0], x[1], x[2], x[3], x[4]),res)) gifts = list(map(lambda x: Gift(x[0], x[1], x[2], x[3], x[4]),res))
for gift in gifts: for gift in gifts:
text = str() text = gift_text(gift, message.from_user.id)
if is_admin(message.from_user.id):
text = f"Название: {gift.name}\nОписание: {gift.description}\nСсылка: {gift.link}"
else:
text = f"Название: {gift.name}\nОписание: {gift.description}\nСсылка: {gift.link}\nДарит: {gift.presenter}"
if gift.picture is None: if gift.picture is None:
await message.answer(text) await message.answer(text)
@ -207,38 +235,47 @@ async def command_start_handler(message: Message, state: FSMContext) -> None:
async def command_start_handler(message: Message, state: FSMContext) -> None: async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.clear() await state.clear()
if is_member(message.from_user.id): #if is_member(message.from_user.id):
res = cur.execute("SELECT * FROM gifts").fetchall() res = cur.execute("SELECT * FROM gifts").fetchall()
gifts = list(map(lambda x: Gift(x[0], x[1], x[2], x[3], x[4]),res)) gifts = list(map(lambda x: Gift(x[0], x[1], x[2], x[3], x[4]),res))
for gift in gifts: for gift in gifts:
text = f"Название: {gift.name}\nОписание: {gift.description}\nСсылка: {gift.link}\nДарит: {gift.presenter}" text = gift_text(gift, message.from_user.id)
if gift.picture is None: if gift.picture is None:
await message.answer(text) await message.answer(text)
else: else:
await message.answer_photo(photo = gift.picture, caption=text) await message.answer_photo(photo = gift.picture, caption=text)
await message.answer("Напишите название подарка, который хотите подарить:") await message.answer("Напишите название подарка, который хотите подарить:")
await state.set_state(Form.waiting_for_gift) await state.set_state(Form.waiting_for_gift)
else: #else:
await message.answer("Вы админ или не участвуете в вечеринке😔") # await message.answer("Вы админ или не участвуете в вечеринке😔")
@dp.message(Form.waiting_for_gift) @dp.message(Form.waiting_for_gift)
async def process_answer(message: Message, state: FSMContext): async def process_answer(message: Message, state: FSMContext):
cur.execute("UPDATE gifts SET presenter=? WHERE name=?", (message.from_user.full_name, message.text)) cur.execute("UPDATE gifts SET presenter=? WHERE name=?", (message.from_user.id, message.text))
con.commit() con.commit()
answer = message.text
await message.answer(f"Теперь {message.text} дарит {message.from_user.full_name}!") await message.answer(f"Теперь {message.text} дарит {message.from_user.full_name}!")
await state.clear() await state.clear()
@dp.message(Command("reset_gift"))
async def process_answer(message: Message, state: FSMContext):
await state.clear()
cur.execute("UPDATE gifts SET presenter=? WHERE presenter=?", (None, message.from_user.id))
con.commit()
await message.answer(f"Вы больше ничего не дарите!")
async def main() -> None: async def main() -> None:
cur.execute( cur.execute(
"CREATE TABLE IF NOT EXISTS gifts(name PRIMARY KEY, description TEXT, link TEXT, picture TEXT, presenter TEXT)" "CREATE TABLE IF NOT EXISTS gifts(name TEXT PRIMARY KEY , description TEXT, link TEXT, picture TEXT, presenter INTEGER REFERENCES users)"
) )
cur.execute("CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT NOT NULL, role TEXT NOT NULL)") cur.execute("CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT NOT NULL, role TEXT NOT NULL)")