from bot.database import SQLighter from aiogram.utils.callback_data import CallbackData from aiogram.utils.exceptions import BotBlocked, MessageNotModified from aiogram import Bot, Dispatcher, executor, types from aiogram.dispatcher.filters.state import State, StatesGroup from aiogram.dispatcher import FSMContext from aiogram.contrib.fsm_storage.files import JSONStorage from bot.other import * from icecream import ic # Initalialization API token for work with Telegram Bot API_TOKEN = base64_decode(config.API_TOKEN) # Configure Memory Storage memory_storage = JSONStorage(config.FSM_FILE_STORAGE) # Configure logging logging.basicConfig(level=logging.INFO) # logging.basicConfig(level=logging.DEBUG) # Initialize bot and dispatcher bot = Bot(token=API_TOKEN) dp = Dispatcher(bot, storage=memory_storage) # Initialize connection with db db = SQLighter("bot/user_data/database.db") loop = asyncio.get_event_loop() myQueue = asyncio.Queue(loop=loop, maxsize=1)
from aiogram import Bot, Dispatcher from aiogram.contrib.fsm_storage.files import JSONStorage from app.settings import TOKEN, LOCAL_DB_PATH bot = Bot(token=TOKEN) dp = Dispatcher(bot, storage=JSONStorage(path=LOCAL_DB_PATH))
import wake_on_lan import settings log_format = ('[%(asctime)s] %(levelname)-8s %(name)-12s %(message)s') # Configure logging logging.basicConfig( level=logging.INFO, format=log_format, handlers=[TimedRotatingFileHandler(settings.LOG_FILE, when='d')], ) # Initialize bot and dispatcher bot = Bot(token=settings.API_TOKEN) dp = Dispatcher(bot, storage=JSONStorage('db.json')) dp.middleware.setup(LoggingMiddleware()) class UserState(StatesGroup): NEW_USER = State() REGISTERED = State() FRAUD = State() def make_menu(): keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, ) keyboard.add(types.KeyboardButton('Включить компьютер')) keyboard.add(types.KeyboardButton('Сброс регистрации')) return keyboard
import logging from aiogram import Bot, Dispatcher from aiogram.contrib.fsm_storage.files import JSONStorage from aiogram.utils import executor from handlers import registration, home, search, conversation, editprofile, admin from config import BOT_TOKEN from database import db logging.basicConfig(level=logging.INFO, filename='logs.log') bot = Bot(token=BOT_TOKEN) dp = Dispatcher(bot, storage=JSONStorage('states.json')) async def shutdown_storage(dispatcher: Dispatcher): db.close() await dispatcher.storage.close() await dispatcher.storage.wait_closed() if __name__ == '__main__': admin.setup(dp) home.setup(dp) registration.setup(dp) conversation.setup(dp) search.setup(dp) editprofile.setup(dp) executor.start_polling(dp, skip_updates=True, on_shutdown=shutdown_storage)
from io import BytesIO from aiogram import Bot, Dispatcher, types from aiogram.utils.executor import start_webhook from aiogram.contrib.middlewares.logging import LoggingMiddleware from aiogram.contrib.fsm_storage.files import JSONStorage from .settings import (BOT_TOKEN, HEROKU_APP_NAME, WEBHOOK_URL, WEBHOOK_PATH, WEBAPP_HOST, WEBAPP_PORT, WEBHOOK_SSL_CERT, WEBHOOK_SSL_PRIV) from .style_transfer import image_loader, getMask, run_style_transfer, getImage, mse_loss logging.basicConfig(level=logging.INFO) bot = Bot(token=BOT_TOKEN) dp = Dispatcher(bot, storage=JSONStorage("file.json")) dp.middleware.setup(LoggingMiddleware()) @dp.message_handler(commands=['start', 'help']) async def send_welcome(message: types.Message): await message.reply( "Hi!\nI'm Style bot!\nSend me an image with caption 'original' and an image with caption 'style'.\nThen send command /execute.\n@superflanker" ) @dp.message_handler(content_types=[ types.message.ContentType.PHOTO, types.message.ContentType.DOCUMENT ]) async def images_handler(message: types.Message): if message.caption in ['style', 'original'
from aiogram import Bot, Dispatcher from aiogram.contrib.fsm_storage.files import JSONStorage from excel_worker import ExcelBook import os TOKEN = os.getenv('BOT_TOKEN1') bot = Bot(TOKEN, parse_mode='Html') storage = JSONStorage('storage/storage.json') dp = Dispatcher(bot, storage=storage) excel_book = ExcelBook('storage/Учет закупок.xlsx')