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=

46
main.py
View File

@@ -4,11 +4,15 @@ from aiogram import Bot, Dispatcher, types, filters
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, WebAppInfo
from aiogram.fsm.state import StatesGroup, State
from aiogram.fsm.context import FSMContext
from dotenv import load_dotenv
TOKEN1 = "7003564044:AAE4R5Nk-E74hOno932iJINNPW3YRjjH8Mo" # web app
TOKEN2 = "8043593409:AAEC4GfxOyfv9LmbfLiwU7_g-mdtuj3y8rI" # delivery
load_dotenv()
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)
bot2 = Bot(token=TOKEN2)
dp1 = Dispatcher()
@@ -18,6 +22,10 @@ class CodeStates(StatesGroup):
phone = State()
full_name = State()
class Broadcast(StatesGroup):
waiting_for_message = State()
@dp2.message(filters.CommandStart())
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)
@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():
await asyncio.gather(
dp1.start_polling(bot1),
@@ -90,4 +128,4 @@ async def main():
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())
asyncio.run(main())

View File

@@ -16,4 +16,5 @@ pydantic_core==2.33.2
typing-inspection==0.4.1
typing_extensions==4.15.0
yarl==1.20.1
requests
requests
python-dotenv