add new feature

This commit is contained in:
behruz-dev
2025-09-27 18:27:46 +05:00
parent 8970262485
commit 44e4d5e74c
3 changed files with 48 additions and 5 deletions

4
.env.example Normal file
View File

@@ -0,0 +1,4 @@
TOKEN1=
TOKEN2=
BACKEND_URL=
ADMIN_ID=

44
main.py
View File

@@ -4,11 +4,15 @@ from aiogram import Bot, Dispatcher, types, filters
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, WebAppInfo from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, WebAppInfo
from aiogram.fsm.state import StatesGroup, State from aiogram.fsm.state import StatesGroup, State
from aiogram.fsm.context import FSMContext from aiogram.fsm.context import FSMContext
from dotenv import load_dotenv
TOKEN1 = "7003564044:AAE4R5Nk-E74hOno932iJINNPW3YRjjH8Mo" # web app load_dotenv()
TOKEN2 = "8043593409:AAEC4GfxOyfv9LmbfLiwU7_g-mdtuj3y8rI" # delivery
TOKEN1 = os.getenv("TOKEN1")
TOKEN2 = os.getenv("TOKEN2")
BACKEND_URL = os.getenv("BACKEND_URL")
ADMIN_ID = int(os.getenv("ADMIN_ID", "0"))
BACKEND_URL = 'https://agro.felixits.uz'
bot1 = Bot(token=TOKEN1) bot1 = Bot(token=TOKEN1)
bot2 = Bot(token=TOKEN2) bot2 = Bot(token=TOKEN2)
dp1 = Dispatcher() dp1 = Dispatcher()
@@ -18,6 +22,10 @@ class CodeStates(StatesGroup):
phone = State() phone = State()
full_name = State() full_name = State()
class Broadcast(StatesGroup):
waiting_for_message = State()
@dp2.message(filters.CommandStart()) @dp2.message(filters.CommandStart())
async def start_handler(message: types.Message, state: FSMContext): async def start_handler(message: types.Message, state: FSMContext):
@@ -82,6 +90,36 @@ async def start_handler(message: types.Message):
) )
await message.answer("Salom! Web Appni ochish uchun tugmani bosing 👇", reply_markup=keyboard) await message.answer("Salom! Web Appni ochish uchun tugmani bosing 👇", reply_markup=keyboard)
@dp1.message(filters.Command("send"))
async def start_broadcast(message: types.Message, state: FSMContext):
if message.from_user.id != ADMIN_ID:
return await message.answer("❌ Sizda ruxsat yoq")
await message.answer("Yubormoqchi bolgan xabaringizni kiriting:")
await state.set_state(Broadcast.waiting_for_message)
@dp1.message(Broadcast.waiting_for_message)
async def broadcast_message(message: types.Message, state: FSMContext):
msg = message.text
count = 0
url = f'{BACKEND_URL}/api/v1/accounts/user/list/'
res = requests.get(url)
for chat_id in res.json():
if chat_id['tg_id'] == ADMIN_ID:
continue
try:
await bot1.send_message(chat_id['tg_id'], msg)
count += 1
except Exception as e:
print(f"Xato {chat_id['tg_id']}: {e}")
await message.answer(f"{count} ta foydalanuvchiga yuborildi")
await state.clear()
async def main(): async def main():
await asyncio.gather( await asyncio.gather(
dp1.start_polling(bot1), dp1.start_polling(bot1),

View File

@@ -17,3 +17,4 @@ typing-inspection==0.4.1
typing_extensions==4.15.0 typing_extensions==4.15.0
yarl==1.20.1 yarl==1.20.1
requests requests
python-dotenv