This commit is contained in:
@ -37,8 +37,8 @@ class Role(Enum):
|
||||
|
||||
|
||||
@dataclass
|
||||
class Gift: # ебаный пиздец я ебал питон
|
||||
name: str | None = None
|
||||
class Gift:
|
||||
name: str
|
||||
description: str | None = None
|
||||
link: str | None = None
|
||||
picture: str | None = None
|
||||
@ -63,6 +63,25 @@ def is_member(id: int) -> bool:
|
||||
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"))
|
||||
async def command_start_handler(message: Message) -> None:
|
||||
try:
|
||||
@ -139,12 +158,10 @@ async def command_start_handler(message: Message, state: FSMContext) -> None:
|
||||
|
||||
@dp.message(Form.waiting_for_gift_add)
|
||||
async def process_answer(message: Message, state: FSMContext):
|
||||
gift = Gift()
|
||||
|
||||
text = message.text or message.caption
|
||||
|
||||
if len(text.splitlines()) >= 1:
|
||||
gift.name = text.splitlines()[0]
|
||||
gift = Gift(text.splitlines()[0])
|
||||
|
||||
if len(text.splitlines()) >= 2:
|
||||
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:
|
||||
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))
|
||||
|
||||
|
||||
for gift in gifts:
|
||||
text = str()
|
||||
|
||||
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}"
|
||||
text = gift_text(gift, message.from_user.id)
|
||||
|
||||
if gift.picture is None:
|
||||
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:
|
||||
await state.clear()
|
||||
|
||||
if is_member(message.from_user.id):
|
||||
res = cur.execute("SELECT * FROM gifts").fetchall()
|
||||
gifts = list(map(lambda x: Gift(x[0], x[1], x[2], x[3], x[4]),res))
|
||||
#if is_member(message.from_user.id):
|
||||
res = cur.execute("SELECT * FROM gifts").fetchall()
|
||||
gifts = list(map(lambda x: Gift(x[0], x[1], x[2], x[3], x[4]),res))
|
||||
|
||||
|
||||
for gift in gifts:
|
||||
text = f"Название: {gift.name}\nОписание: {gift.description}\nСсылка: {gift.link}\nДарит: {gift.presenter}"
|
||||
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)
|
||||
if gift.picture is None:
|
||||
await message.answer(text)
|
||||
else:
|
||||
await message.answer_photo(photo = gift.picture, caption=text)
|
||||
|
||||
await message.answer("Напишите название подарка, который хотите подарить:")
|
||||
await state.set_state(Form.waiting_for_gift)
|
||||
else:
|
||||
await message.answer("Вы админ или не участвуете в вечеринке😔")
|
||||
await message.answer("Напишите название подарка, который хотите подарить:")
|
||||
await state.set_state(Form.waiting_for_gift)
|
||||
#else:
|
||||
# await message.answer("Вы админ или не участвуете в вечеринке😔")
|
||||
|
||||
|
||||
@dp.message(Form.waiting_for_gift)
|
||||
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()
|
||||
|
||||
answer = message.text
|
||||
await message.answer(f"Теперь {message.text} дарит {message.from_user.full_name}!")
|
||||
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:
|
||||
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)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user