first commit

This commit is contained in:
2026-03-11 01:18:59 +03:00
parent 277615084e
commit 9956edc8ce
10 changed files with 1622 additions and 0 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
.gitignore
LICENSE
wishlist.db

217
.gitignore vendored Normal file
View File

@ -0,0 +1,217 @@
wishlist.db
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/
# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# Redis
*.rdb
*.aof
*.pid
# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/
# ActiveMQ
activemq-data/
# SageMath parsed files
*.sage.py
# Environments
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/
# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/
# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Ruff stuff:
.ruff_cache/
# PyPI configuration file
.pypirc
# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
# Streamlit
.streamlit/secrets.toml

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM python:3.13-bookworm
COPY ./src /src
COPY ./requirements.txt /src
RUN apt update
RUN apt install pipx
RUN pipx install poetry
CMD [ "poetry", "install" ]
CMD [ "poetry", "run", "python", "/src/main.py" ]

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 SaddyDEAD <saddydead@sonoma.su>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,24 @@
name: docker
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
docker-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build -t docker.sonoma.su/wishlistbot .
- name: Login Sonoma Docker registry
run: docker login docker.sonoma.su --username ${{ secrets.DOCKER_LOGIN }} --password ${{ secrets.DOCKER_PASSWORD }}
- name: Push image
run: docker push docker.sonoma.su/wishlistbot

1067
poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

22
pyproject.toml Normal file
View File

@ -0,0 +1,22 @@
[project]
name = "wishlist-bot"
version = "0.1.0"
description = ""
license = "MIT"
authors = [
{name = "SaddyDEAD",email = "saddydead@sonoma.su"}
]
readme = "README.md"
requires-python = ">=3.10,<3.15"
dependencies = [
"aiogram (>=3.26.0,<4.0.0)",
"asyncio (>=4.0.0,<5.0.0)"
]
[tool.poetry]
packages = [{include = "wishlist_bot", from = "src"}]
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

View File

257
src/wishlist_bot/main.py Normal file
View File

@ -0,0 +1,257 @@
import asyncio
import sqlite3
from os import getenv
from enum import Enum
from dataclasses import dataclass
from aiogram import Bot, Dispatcher, F
from aiogram.filters import Command
from aiogram.types import Message
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import State, StatesGroup
TOKEN = getenv("BOT_TOKEN")
ADMIN_ID = int(getenv("ADMIN_ID"))
dp = Dispatcher()
con = sqlite3.connect("wishlist.db")
cur = con.cursor()
class Form(StatesGroup):
waiting_for_answer_admin = State()
waiting_for_answer_verify = State()
waiting_for_gift_add = State()
waiting_for_gift_add_approve = State()
waiting_for_gift= State()
class Role(Enum):
ADMIN = "ADMIN"
MEMBER = "MEMBER"
DEFAULT = "DEFAULT"
@dataclass
class Gift: # ебаный пиздец я ебал питон
name: str | None = None
description: str | None = None
link: str | None = None
picture: str | None = None
presenter: int | None = None
def is_admin(id: int) -> bool:
res = cur.execute(f"SELECT role FROM users WHERE id={id}").fetchone()[0]
if (res == Role.ADMIN.value):
return True
else:
return False
def is_member(id: int) -> bool:
res = cur.execute(f"SELECT role FROM users WHERE id={id}").fetchone()[0]
if (res == Role.MEMBER.value):
return True
else:
return False
@dp.message(Command("start"))
async def command_start_handler(message: Message) -> None:
try:
cur.execute(
f"INSERT OR IGNORE INTO users(id, name, role) VALUES(?, ?, ?)",
(message.from_user.id, message.from_user.full_name, Role.DEFAULT.value)
)
con.commit()
except Exception as e:
print(e)
await message.answer("Привет, теперь попроси подтвердить твое участие именинника 🥳")
@dp.message(Command("add_admin"))
async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.clear()
if is_admin(message.from_user.id):
res = cur.execute("SELECT name FROM users WHERE role=?", (Role.MEMBER.value,)).fetchall()
users = list(map(lambda x: x[0], res))
text = "Напиши имя пользователя, которого надо сделать админом: \n"
for user in users:
text += f"{user} \n"
await message.answer(text)
await state.set_state(Form.waiting_for_answer_admin)
@dp.message(Form.waiting_for_answer_admin)
async def process_answer(message: Message, state: FSMContext):
cur.execute("UPDATE users SET role=? WHERE name=?", (Role.ADMIN.value, message.text))
con.commit()
answer = message.text
await message.answer(f"Теперь {answer} админ!")
await state.clear()
@dp.message(Command("verify"))
async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.clear()
if is_admin(message.from_user.id):
res = cur.execute("SELECT name FROM users WHERE role=?", (Role.DEFAULT.value,)).fetchall()
users = list(map(lambda x: x[0], res))
text = "Напиши имя пользователя, которого верифицировать: \n"
for user in users:
text += f"{user} \n"
await message.answer(text)
await state.set_state(Form.waiting_for_answer_verify)
@dp.message(Form.waiting_for_answer_verify)
async def process_answer(message: Message, state: FSMContext):
cur.execute("UPDATE users SET role=? WHERE name=?", (Role.MEMBER.value, message.text))
con.commit()
answer = message.text
await message.answer(f"Теперь {answer} участник вечеринки!")
await state.clear()
@dp.message(Command("add_gift"))
async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.clear()
if is_admin(message.from_user.id):
text = "Хорошо, отправь мне подарок вот так: \n\nНАЗВАНИЕ \nОПИСАНИЕ \nССЫЛКА \n\nА также можешь прикрепить фотографию!"
await message.answer(text)
await state.set_state(Form.waiting_for_gift_add)
@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]
if len(text.splitlines()) >= 2:
gift.description = text.splitlines()[1]
if len(text.splitlines()) >= 3:
gift.link = text.splitlines()[2]
if message.photo:
gift.picture = message.photo[-1].file_id
if gift.picture is None:
await message.answer(f"{gift.name}\n{gift.description}\n{gift.link}")
try:
cur.execute(
f"INSERT OR IGNORE INTO gifts(name, description, link) VALUES(?, ?, ?)",
(gift.name, gift.description, gift.link)
)
con.commit()
except Exception as e:
print(e)
else:
await message.answer_photo(photo = gift.picture, caption=f"{gift.name}\n{gift.description}\n{gift.link}")
try:
cur.execute(
f"INSERT OR IGNORE INTO gifts(name, description, link, picture) VALUES(?, ?, ?, ?)",
(gift.name, gift.description, gift.link, gift.picture)
)
con.commit()
except Exception as e:
print(e)
await message.answer(f'Отлично, подарок добавлен!')
await state.clear()
@dp.message(Command("gifts"))
async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.clear()
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 = 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}"
if gift.picture is None:
await message.answer(text)
else:
await message.answer_photo(photo = gift.picture, caption=text)
@dp.message(Command("gift"))
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))
for gift in gifts:
text = f"Название: {gift.name}\nОписание: {gift.description}\nСсылка: {gift.link}\nДарит: {gift.presenter}"
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("Вы админ или не участвуете в вечеринке😔")
@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))
con.commit()
answer = message.text
await message.answer(f"Теперь {message.text} дарит {message.from_user.full_name}!")
await state.clear()
async def main() -> None:
cur.execute(
"CREATE TABLE IF NOT EXISTS gifts(name PRIMARY KEY, description TEXT, link TEXT, picture TEXT, presenter TEXT)"
)
cur.execute("CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT NOT NULL, role TEXT NOT NULL)")
cur.execute(
f"INSERT OR IGNORE INTO users(id, name, role) VALUES(?, ?, ?)",
(ADMIN_ID, "ADMIN", Role.ADMIN.value)
)
con.commit()
bot = Bot(token=TOKEN)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())

0
tests/__init__.py Normal file
View File