Exemple #1
0
async def main():
    # real main
    logging.basicConfig(level=logging.INFO)
    storage = MemoryStorage()
    bot = Bot(token=API_TOKEN)
    dp = Dispatcher(bot, storage=storage)
    registry = DialogRegistry(dp)
    registry.register(dialog)
    dp.register_message_handler(start, text="/start", state="*")

    await dp.start_polling()
Exemple #2
0
async def main():
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
    )
    logging.getLogger("aiogram_dialog").setLevel(logging.DEBUG)
    logger.info("Starting bot")
    config = load_config("bot.ini")

    if config.tg_bot.use_redis:
        storage = RedisStorage2()
    else:
        storage = MemoryStorage()
    pool = await create_pool(user=config.db.user,
                             password=config.db.password,
                             database=config.db.database,
                             host=config.db.host)

    bot = Bot(token=config.tg_bot.token, parse_mode='html')
    dp = Dispatcher(bot, storage=storage)

    # aiogram_dialog
    logging.getLogger("aiogram_dialog").setLevel(logging.DEBUG)

    registry = DialogRegistry(dp)
    registry.register(broadcast)

    dp.middleware.setup(ThrottlingMiddleware(limit=.5))
    dp.middleware.setup(DbMiddleware(pool))
    dp.middleware.setup(RoleMiddleware())
    dp.middleware.setup(SupportMiddleware(Dispatcher=dp))
    dp.filters_factory.bind(RoleFilter)
    dp.filters_factory.bind(AdminFilter)

    register_admin(dp)
    register_manager(dp)
    register_courier(dp)
    register_customer(dp)
    register_group(dp)

    # register apscheduler @TODO запустить статистику
    # scheduler = AsyncIOScheduler(timezone='Europe/Moscow')
    # scheduler.start()

    # scheduler.add_job(send_stats, 'cron', args=(bot, True, repository.Repo(pool)), hour=23, minute=0,
    #                   replace_existing=True)  # Day stats
    # scheduler.add_job(send_stats, 'cron', args=(bot, True, repository.Repo(pool)), day_of_week='Sun', hour=23, minute=0,
    #                   replace_existing=True)  # week stats

    # start
    try:
        await dp.start_polling()
    finally:
        await bot.close()
Exemple #3
0
async def main():
    # real main
    logging.basicConfig(level=logging.INFO)
    logging.getLogger("aiogram_dialog").setLevel(logging.DEBUG)
    storage = MemoryStorage()
    bot = Bot(token=API_TOKEN)
    dp = Dispatcher(bot, storage=storage)
    registry = DialogRegistry(dp)
    registry.register(bg_dialog)
    registry.register(main_menu)
    dp.register_message_handler(start, text="/start", state="*")

    await dp.start_polling()
Exemple #4
0
async def main():
    logger = logging.getLogger("main")
    logging.basicConfig(level=logging.ERROR)
    ch = logging.StreamHandler()
    ch.setLevel(logging.INFO)

    fh = logging.FileHandler("mapoc-bot-app.log")
    fh.setLevel(logging.DEBUG)

    formatter = logging.Formatter(
        '[%(asctime)s] [%(levelname)s] %(name)s: %(message)s')
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    logger.addHandler(fh)

    logger.info("Starting mapoc-bot")

    storage = MemoryStorage()
    bot = Bot(token=API_TOKEN, parse_mode=types.ParseMode.HTML)
    dp = Dispatcher(bot, storage=storage)
    registry = DialogRegistry(dp)

    register_handlers(dp)
    register_dialogs(registry)

    q_manager = QueueManager()

    try:
        await dp.start_polling()
    finally:
        await bot.close()
Exemple #5
0
async def main():
    # real main
    logging.basicConfig(level=logging.INFO)
    storage = MemoryStorage()
    bot = Bot(token=API_TOKEN)
    dp = Dispatcher(bot, storage=storage)
    registry = DialogRegistry(dp)
    # register handler which resets stack and start dialogs on /start command
    registry.register_start_handler(DialogSG.greeting)
    registry.register(dialog)

    await dp.start_polling()
Exemple #6
0
from aiogram import Bot, Dispatcher, executor
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher.filters.state import StatesGroup, State
from aiogram.types import Message

from aiogram_dialog import Window, Dialog, DialogRegistry, DialogManager, StartMode
from aiogram_dialog.widgets.kbd import Button
from aiogram_dialog.widgets.text import Const

storage = MemoryStorage()
bot = Bot(token='BOT TOKEN HERE')
dp = Dispatcher(bot, storage=storage)
registry = DialogRegistry(dp)


class MySG(StatesGroup):
    main = State()


main_window = Window(
    Const("Hello, unknown person"),
    Button(Const("Useless button"), id="nothing"),
    state=MySG.main,
)
dialog = Dialog(main_window)
registry.register(dialog)


@dp.message_handler(commands=["start"])
async def start(m: Message, dialog_manager: DialogManager):
    await dialog_manager.start(MySG.main, mode=StartMode.RESET_STACK)
Exemple #7
0
from aiogram_dialog import DialogRegistry

registry = DialogRegistry(dp)  # this is required to use `aiogram_dialog`
registry.register(dialog)  # register a dialog
Exemple #8
0
def register_dialogs(registry: DialogRegistry):
    registry.register(dialogs.poster_creation.dialog)