Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup #3

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Use this bot for communicate with users in case you do not want to provide your

## Usage

Messages with an available [content type](./src/bot/handlers/users.py#L24) will be transfered to admin group or admin chat.
Messages with an **available content type** *(TEXT, ANIMATION, AUDIO, DOCUMENT, PHOTO, VIDEO, VOICE)* will be transferred to **admin group** or **admin chat**.

*(See variable `chat_id` from [config.yaml](./deploy/example.config.yaml#L6))*

If the transfer is successful, the requesting party will be notified.

Admin can answer to message by reply. The answer will be sent to the person who asked.
**Admin** can **answer** to message **by reply**. The answer will be sent to the person who asked.

If the transfer is successful, the administrator will be notified.

Expand Down Expand Up @@ -68,6 +68,13 @@ and build docker image:

And use this image with [docker-compose.yml](./deploy/example.docker-compose.yml) from `deploy` dir.

## Hosting
You can rent a server from various hosters, for example from [Aeza](https://aeza.net/?ref=380831).

>*By registering via the [link](https://aeza.net/?ref=380831) you will support the project and receive a 15% bonus on your balance, which will be valid for 24 hours.*

The bot will require the simplest VDS, in rubles this is approximately 100-200 for promotional offers, or about 500 rubles per month.

## Develop and Contribute

Feel free to create issue or pull request.
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
aiogram==3.1.0
sulguk==0.5.0
aiogram==3.1.1
# sulguk==0.6.0
# wait for fix https://github.com/Tishka17/sulguk/issues/19
git+https://github.com/bralbral/sulguk.git
pydantic-settings==2.0.3
pyaml==23.9.6
pyaml==23.9.7
structlog~=23.1.0
# asyncio speedup
uvloop==0.17.0; sys_platform == 'linux'
9 changes: 9 additions & 0 deletions src/bot/handlers/admins/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
async def reply_to_user(
message: Message, bot: Bot, messages: Messages, errors: Errors, **kwargs
):
"""
Answer to user by reply from admin chat or group
:param message:
:param bot:
:param messages:
:param errors:
:param kwargs:
:return:
"""
try:
user_id = extract_id(message.reply_to_message)
except ValueError as ex:
Expand Down
7 changes: 7 additions & 0 deletions src/bot/handlers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
Command("start", "help"),
) # type: ignore
async def start_help_handler(message: Message, messages: Messages, **kwargs) -> None:
"""
Handle /start or /help message
:param message:
:param messages:
:param kwargs:
:return:
"""
await message.answer(
messages.help_message,
disable_web_page_preview=True,
Expand Down
12 changes: 10 additions & 2 deletions src/bot/handlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
router = Router(name="users")


# process messages only from PM
@router.message(F.chat.id == F.from_user.id) # type: ignore
async def handle_user_message(
message: Message,
Expand All @@ -21,6 +20,15 @@ async def handle_user_message(
errors: Errors,
**kwargs,
):
"""Handle user message and send it to admin chat (group)
:param message:
:param bot:
:param chat_id:
:param messages:
:param errors:
:param kwargs:
:return:
"""
if message.content_type not in (
ContentType.TEXT,
ContentType.ANIMATION,
Expand Down Expand Up @@ -52,7 +60,7 @@ async def handle_user_message(
)

else:
if len(message.caption) > 1000:
if message.caption and len(message.caption) > 1000:
await message.reply(text=errors.too_long_message_caption)
return

Expand Down
4 changes: 4 additions & 0 deletions src/bot/utils/setup_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@


async def setup_bot(config: BotConfig) -> Bot:
"""
:param config:
:return:
"""
bot: Bot = Bot(
token=config.token.get_secret_value(),
)
Expand Down
7 changes: 7 additions & 0 deletions src/bot/utils/setup_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
def setup_dispatcher(
logger: BoundLogger, chat_id: int, messages: Messages, errors: Errors
) -> Dispatcher:
"""
:param logger:
:param chat_id:
:param messages:
:param errors:
:return:
"""
dp: Dispatcher = Dispatcher(
storage=MemoryStorage(),
logger=logger,
Expand Down
4 changes: 4 additions & 0 deletions src/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@


def load_config(config_path: str) -> Config:
"""
:param config_path:
:return:
"""
with open(file=config_path, mode="rb") as fh:
raw_data: dict = yaml.load(stream=fh, Loader=yaml.FullLoader)
config: Config = Config.model_validate(raw_data)
Expand Down