Бот + прокси

This commit is contained in:
2026-04-30 16:34:57 +03:00
parent ddec6094c2
commit 5dc9c8f0d1
11 changed files with 129 additions and 19 deletions

0
bot/__init__.py Normal file
View File

29
bot/__main__.py Normal file
View File

@@ -0,0 +1,29 @@
import logging
import asyncio
import sys
from bot.commands import router as command_router
from bot.factory import bot, dp, init_bot_and_dp
from config import config
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(name)s:%(lineno)d %(levelname)s %(message)s',
handlers=[
logging.FileHandler('app.log', encoding='utf-8'),
logging.StreamHandler(sys.stdout)
]
)
logger = logging.getLogger(__name__)
async def main():
bot, dp = init_bot_and_dp(f"socks5://{config.PROXY_URL}", config.BOT_TOKEN)
dp.include_router(command_router)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())

30
bot/commands.py Normal file
View File

@@ -0,0 +1,30 @@
from argparse import Namespace
from aiogram import Router
from aiogram.filters.command import Command, CommandStart
from aiogram.types import Message
from bot.factory import bot
from tracker.commands import end_workday
router = Router()
@router.message(CommandStart())
async def start_command(message: Message):
await message.answer(f"Привет, {message.from_user.first_name}!")
@router.message(Command("track"))
async def track_command(message: Message):
await message.answer("Эта фича пока в разработке, но скоро она поможет стартовать и останавливать таймер.")
@router.message(Command("end"))
async def end_command(message: Message):
args = message.text.replace("/end", "").strip().split()
if "-i" in args or "--init-db" in args:
args = Namespace(init_db=True)
await message.answer("Начинаю процесс занесения трудочасов...")
await end_workday(args, bot, message.from_user.id)
await message.answer("Трудочасы занесены!")

12
bot/factory.py Normal file
View File

@@ -0,0 +1,12 @@
from aiogram import Bot, Dispatcher
from aiogram.client.session.aiohttp import AiohttpSession
bot: Bot = None # type: ignore
dp: Dispatcher = None
def init_bot_and_dp(proxy_url: str, token: str):
global bot, dp
bot = Bot(token=token, session=AiohttpSession(proxy=proxy_url) if proxy_url else None)
dp = Dispatcher()
return bot, dp