Bot start/stop
This commit is contained in:
45
src/main.py
45
src/main.py
@ -27,7 +27,7 @@ import strings
|
|||||||
import options
|
import options
|
||||||
|
|
||||||
|
|
||||||
async def set_commands():
|
async def setCommands():
|
||||||
commands = [BotCommand(command='start', description='Старт'),
|
commands = [BotCommand(command='start', description='Старт'),
|
||||||
BotCommand(command='help', description='Инструкция'),
|
BotCommand(command='help', description='Инструкция'),
|
||||||
BotCommand(command='info', description='Информация о стратегиях'),
|
BotCommand(command='info', description='Информация о стратегиях'),
|
||||||
@ -52,8 +52,8 @@ bot = Bot(
|
|||||||
default=DefaultBotProperties(parse_mode=ParseMode.HTML),
|
default=DefaultBotProperties(parse_mode=ParseMode.HTML),
|
||||||
)
|
)
|
||||||
|
|
||||||
strategy_router = Router()
|
strategyRouter = Router()
|
||||||
stop_router = Router()
|
stopRouter = Router()
|
||||||
|
|
||||||
|
|
||||||
@dp.message(Command("start"))
|
@dp.message(Command("start"))
|
||||||
@ -87,13 +87,13 @@ async def commandInfo(message: Message) -> None:
|
|||||||
await message.answer(msgText)
|
await message.answer(msgText)
|
||||||
|
|
||||||
|
|
||||||
@strategy_router.message(Command("strategy"), F.chat.id.in_(whitelist.chatIDs))
|
@strategyRouter.message(Command("strategy"), F.chat.id.in_(whitelist.chatIDs))
|
||||||
async def commandStrategy(message: Message, state: FSMContext):
|
async def commandStrategy(message: Message, state: FSMContext):
|
||||||
await message.answer(strings.strategyCommand + '\n' + strings.askPair)
|
await message.answer(strings.strategyCommand + '\n' + strings.askPair)
|
||||||
await state.set_state(startForm.pair)
|
await state.set_state(startForm.pair)
|
||||||
|
|
||||||
@strategy_router.message(F.text, startForm.pair)
|
@strategyRouter.message(F.text, startForm.pair)
|
||||||
async def capture_start_pair(message: Message, state: FSMContext):
|
async def captureStartPair(message: Message, state: FSMContext):
|
||||||
await state.update_data(pair=message.text)
|
await state.update_data(pair=message.text)
|
||||||
data = await state.get_data()
|
data = await state.get_data()
|
||||||
|
|
||||||
@ -110,8 +110,8 @@ async def capture_start_pair(message: Message, state: FSMContext):
|
|||||||
else:
|
else:
|
||||||
await state.set_state(startForm.params)
|
await state.set_state(startForm.params)
|
||||||
|
|
||||||
@strategy_router.message(F.text, startForm.params)
|
@strategyRouter.message(F.text, startForm.params)
|
||||||
async def capture_params(message: Message, state: FSMContext):
|
async def captureParams(message: Message, state: FSMContext):
|
||||||
await state.update_data(params=message.text)
|
await state.update_data(params=message.text)
|
||||||
|
|
||||||
data = await state.get_data()
|
data = await state.get_data()
|
||||||
@ -161,13 +161,13 @@ async def capture_params(message: Message, state: FSMContext):
|
|||||||
await state.clear()
|
await state.clear()
|
||||||
|
|
||||||
|
|
||||||
@stop_router.message(Command("stop"), F.chat.id.in_(whitelist.chatIDs))
|
@stopRouter.message(Command("stop"), F.chat.id.in_(whitelist.chatIDs))
|
||||||
async def commandStop(message: Message, state: FSMContext):
|
async def commandStop(message: Message, state: FSMContext):
|
||||||
await message.answer(strings.stopCommand + '\n' + strings.askPair)
|
await message.answer(strings.stopCommand + '\n' + strings.askPair)
|
||||||
await state.set_state(stopForm.pair)
|
await state.set_state(stopForm.pair)
|
||||||
|
|
||||||
@stop_router.message(F.text, stopForm.pair)
|
@stopRouter.message(F.text, stopForm.pair)
|
||||||
async def capture_stop_pair(message: Message, state: FSMContext):
|
async def captureStopPair(message: Message, state: FSMContext):
|
||||||
await state.update_data(pair=message.text)
|
await state.update_data(pair=message.text)
|
||||||
data = await state.get_data()
|
data = await state.get_data()
|
||||||
|
|
||||||
@ -181,13 +181,26 @@ async def capture_stop_pair(message: Message, state: FSMContext):
|
|||||||
await state.clear()
|
await state.clear()
|
||||||
|
|
||||||
|
|
||||||
async def start_bot():
|
async def startBot():
|
||||||
await set_commands()
|
await setCommands()
|
||||||
|
try:
|
||||||
|
for i in whitelist.chatIDs:
|
||||||
|
await bot.send_message(chat_id=i, text=strings.startBot)
|
||||||
|
except Exception as e:
|
||||||
|
generalLogger.error(e)
|
||||||
|
|
||||||
|
async def stopBot():
|
||||||
|
try:
|
||||||
|
for i in whitelist.chatIDs:
|
||||||
|
await bot.send_message(chat_id=i, text=strings.stopBot)
|
||||||
|
except Exception as e:
|
||||||
|
generalLogger.error(e)
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
dp.include_router(strategy_router)
|
dp.include_router(strategyRouter)
|
||||||
dp.include_router(stop_router)
|
dp.include_router(stopRouter)
|
||||||
dp.startup.register(start_bot)
|
dp.startup.register(startBot)
|
||||||
|
dp.shutdown.register(stopBot)
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user