Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from aiogram import Bot, Dispatcher, executor, types
- from aiogram.dispatcher import FSMContext
- from aiogram.contrib.fsm_storage.memory import MemoryStorage
- from aiogram.contrib.fsm_storage.redis import RedisStorage
- from aiogram.dispatcher.filters.state import State, StatesGroup
- from aiogram.utils.markdown import code
- import asyncio
- from core import connect
- import traceback
- import functools
- API_TOKEN = '602152181:AAFugswrbPdKvwqpJsrHULhWlneHXU1oouU'
- # Configure logging
- logging.basicConfig(level=logging.INFO)
- # Initialize bot and dispatcher
- #loop = asyncio.get_event_loop()
- bot = Bot(token=API_TOKEN, parse_mode="markdown")
- storage = MemoryStorage()
- dp = Dispatcher(bot, storage=storage)
- class Install(StatesGroup):
- ip = State()
- user = State()
- password = State()
- domain = State()
- start = State()
- @dp.message_handler(commands=["start"])
- async def echo(message: types.Message):
- await bot.send_message(message.chat.id, "Hi!")
- @dp.message_handler(commands=["install"])
- async def install(message: types.Message):
- await Install.ip.set()
- await bot.send_message(message.chat.id, "Send me your server ip address:")
- @dp.message_handler(state=Install.ip)
- async def process_ip(message: types.Message, state: FSMContext):
- async with state.proxy() as data:
- data['ip'] = message.text
- await Install.next()
- await bot.send_message(message.chat.id, "User:")
- @dp.message_handler(state=Install.user)
- async def process_user(message: types.Message, state: FSMContext):
- print("hi")
- async with state.proxy() as data:
- data['user'] = message.text
- await Install.next()
- print('ok')
- await bot.send_message(message.chat.id, "Password:")
- @dp.message_handler(state=Install.password)
- async def process_password(message: types.Message, state: FSMContext):
- async with state.proxy() as data:
- data['password'] = message.text
- await Install.next()
- await bot.send_message(message.chat.id, "Domain:")
- @dp.message_handler(state=Install.domain)
- async def process_domain(message: types.Message, state: FSMContext):
- async with state.proxy() as data:
- data['domain'] = message.text
- await Install.next()
- await bot.send_message(message.chat.id, "Do you want to start bitcart after installation?(Y/N)")
- @dp.message_handler(state=Install.start)
- async def process_start(message: types.Message, state: FSMContext):
- async with state.proxy() as data:
- data['start'] = message.text
- try:
- connect(data['ip'], data['user'], data['password'],
- print, data['start'], data['domain'])
- except Exception:
- await bot.send_message(message.chat.id, "Error connecting to server/installing.\n"+code(traceback.format_exc().splitlines()[-1]))
- await bot.send_message(message.chat.id, str(data))
- data.state = None
- #functools.partial(print_func, chat_id=message.chat.id)
- async def print_func_async(chat_id, message):
- await bot.send_message(chat_id, message)
- def print_func(message, chat_id):
- loop.create_task(print_func_async(chat_id, message))
- if __name__ == '__main__':
- executor.start_polling(dp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement