Esempio n. 1
0
File: main.py Progetto: a-kikot/shdk
from aiogram.types import ParseMode
from aiogram.utils import exceptions
from settings import config

import text_util
from maps import ANSWER_CHECKING_MAP, DISTRACTION_MAP
from db import ShdkDatabase


# Configure logging
logging.basicConfig(level=logging.INFO, filename="info.logs")


# Initialize bot and dispatcher
bot = Bot(token=config["bot_token"])
dp = Dispatcher(bot, storage=MongoStorage(uri=config["mongo_uri"]))
db = ShdkDatabase()

admin_ids = config["admin_ids"]


class AdminInput(StatesGroup):
    questions_saving = State()


class PlayerInput(StatesGroup):
    pending_answer = State()
    answered = State()
    current_question = State()

Esempio n. 2
0
from app.core.config import (
    TOKEN, MONGO_URL, MONGO_PORT, SKIP_UPDATES, MONGO_DB, MONGO_USER, MONGO_PSWD, REDIS_URI
)
from app.core.utils import RedisCache


logging.basicConfig(level=logging.INFO)

logger = logging.getLogger(__name__)

logger.setLevel(logging.INFO)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.ERROR)
formatter = logging.Formatter("[%(asctime)s] %(levelname)s - %(message)s")
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)

# Just some tricks to speed-up bot
uvloop.install()

loop = asyncio.get_event_loop()

redis_cache = RedisCache(uri=REDIS_URI)
api_client = ApiClient(redis_cache)

bot = ClearBot(token=TOKEN, loop=loop)
storage = MongoStorage(host=MONGO_URL, port=MONGO_PORT, db_name=MONGO_DB, username=MONGO_USER, password=MONGO_PSWD)
dp = Dispatcher(bot, storage=storage)

runner = Executor(dp, skip_updates=SKIP_UPDATES)
Esempio n. 3
0
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.utils.callback_data import CallbackData
from pydantic import ValidationError

from db.mongo import MongoDB
from schema.resort import Resort
from schema.track import Track
from schema.weather import Weather
from utils.weather import get_current_weather, get_forecast_24h

BOT_TOKEN = environ['BOT_TOKEN']
mongo = MongoDB()
storage = MongoStorage(
    host='mongodb',
    port=27017,
    db_name='sayanbot',
    username=environ['MONGO_INITDB_ROOT_USERNAME'],
    password=environ['MONGO_INITDB_ROOT_PASSWORD'],
)
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher(bot, storage=storage)

console_out_hundler = logging.StreamHandler()
rotate_file_handler = RotatingFileHandler(
    'log.log',
    maxBytes=5000000,
    backupCount=2,
)

logging.basicConfig(
    level=logging.INFO,
Esempio n. 4
0
from config import *
from database import Database

# Configure logging
logging.basicConfig(format=u'%(filename)s [LINE:%(lineno)d] #%(levelname)-4s [%(asctime)s]  %(message)s', level=logging.INFO)

logger = logging.getLogger()

formatter = logging.Formatter(u'%(filename)s [LINE:%(lineno)d] #%(levelname)-4s [%(asctime)s]  %(message)s')

file_handler = logging.FileHandler("logs/bot.log")
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)

error_file_handle = logging.FileHandler("logs/bot_errors.log")
error_file_handle.setLevel(logging.ERROR)
error_file_handle.setFormatter(formatter)

logger.addHandler(error_file_handle)
logger.addHandler(file_handler)

# Initialize databse
db = Database()

# Initialize bot, storage and dispatcher
storage = MongoStorage(host=MONGO_HOST, port=MONGO_PORT, db_name='aiogram_fsm')
bot = Bot(token=TOKEN, parse_mode=types.ParseMode.HTML)
dp = Dispatcher(bot, storage=storage)

dp.middleware.setup(LoggingMiddleware())
Esempio n. 5
0
from starlette.routing import Route
from starlette.responses import JSONResponse
from starlette.middleware import Middleware

from weebhook import set_weebhook
from keyboard import board_1, board_2, board_3
from functions import parser, db_list, num_list, create_reply_keyboard, save_adm
from config import TOKEN, MAIN_DB, ADMIN_DB

client = MongoClient("localhost", 27017)
db = client['NEW_DB']
new_collection = db[MAIN_DB]
adm_collection = db[ADMIN_DB]

bot = Bot(token=TOKEN)
dp = Dispatcher(bot, storage=MongoStorage())


class States(Helper):
    mode = HelperMode.snake_case
    ADMIN = Item()
    DELETE = Item()
    FIO = Item()
    DOLJ = Item()
    ADRESS = Item()
    EMAIL = Item()
    PHONE = Item()
    CHANGE = Item()
    CHANGE_ROOM = Item()

Esempio n. 6
0
from app.config import MONGODB_URI
from aiogram.contrib.fsm_storage.mongo import MongoStorage

storage = MongoStorage(uri=MONGODB_URI)
Esempio n. 7
0
from aiogram.utils.emoji import emojize
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.mongo import MongoStorage
from twitter import Twitter
from validations import is_auth_verifier
from conf.settings import TELEGRAM_TOKEN, MONGO_HOST, MONGO_PORT, MONGO_DB_NAME

# Configure logging
logging.basicConfig(level=logging.INFO)

# Initialize bot and dispatcher
bot = Bot(token=TELEGRAM_TOKEN)
storage = MongoStorage(host=MONGO_HOST, port=MONGO_PORT, db_name=MONGO_DB_NAME)
dp = Dispatcher(bot, storage=storage)


# States
class Form(StatesGroup):
    credentials = State()
    targets = State()


@dp.message_handler(commands=['start', 'entrar'], state='*')
async def send_welcome(message: types.Message, state: FSMContext):
    """
    This handler will be called when user sends `/start` or `/entrar` command
    """
Esempio n. 8
0
import logging

from aiogram import Bot, Dispatcher, executor
from aiogram.contrib.fsm_storage.mongo import MongoStorage

from msu_atpase_storage.config import settings
from msu_atpase_storage.gdrive_ import GDrive
from msu_atpase_storage.gspreadsh import GSheet

logging.basicConfig(level=logging.INFO)

# Initialize bot and dispatcher
bot = Bot(token=settings.tg_token)
storage = MongoStorage()
dp = Dispatcher(bot, storage=storage)
gdrive = GDrive()
gsheet = GSheet()


def main(dispatcher: Dispatcher):
    executor.start_polling(dispatcher, skip_updates=True)
Esempio n. 9
0
import asyncio
import httpx

import betterlogging as bl
from aiogram import Dispatcher, Bot, types
from aiogram.contrib.fsm_storage.mongo import MongoStorage
from motor.core import AgnosticCollection
from motor.motor_asyncio import AsyncIOMotorClient
from odmantic import AIOEngine

from .config import env

bl.basic_colorized_config(level=bl.INFO)

loop = asyncio.get_event_loop()
bot = Bot(env.TOKEN, parse_mode=types.ParseMode.HTML)
storage = MongoStorage(uri=env.DB_URL, db_name=env.DB_NAME)
dp = Dispatcher(bot, storage=storage)
session = httpx.AsyncClient()

motor_client = AsyncIOMotorClient(env.DB_URL)
collection: AgnosticCollection = motor_client[env.DB_NAME][
    env.DB_COLLECTION_NAME]
db_engine = AIOEngine(motor_client, database=env.DB_NAME)
Esempio n. 10
0
from aiogram import Bot, Dispatcher
import logging
import config
import os
from aiogram.contrib.fsm_storage.mongo import MongoStorage

bot = Bot(config.TOKEN)
MongoDB = MongoStorage(host=config.Mongo.host,
                       port=config.Mongo.port + '/' + config.Mongo.db_name,
                       username=config.Mongo.username,
                       password=config.Mongo.password,
                       db_name=config.Mongo.db_name)

income_picture = os.environ.get('INCOME_PICTURE')\
    if os.environ.get('INCOME_PICTURE') is not None else \
    "AgACAgIAAxkDAAIHA17P-qCE0MRFPOhKAlDDl8fzEO_jAAK1rjEb-xKBSq8q47TF4U5XKYNvkS4AAwEAAwIAA3gAA-HPAwABGQQ"


async def get_inc_pic():
    with open('resources/income_profile.png', 'rb') as ph:
        a = await bot.send_photo(config.admins['main'], ph)
        return a['photo'][1]['file_id']


dp = Dispatcher(bot, storage=MongoDB)
logging.basicConfig(level=logging.INFO)
Esempio n. 11
0
from config import BOT_TOKEN
from aiogram import Bot
from aiogram_tools import Dispatcher
from aiogram.contrib.fsm_storage.mongo import MongoStorage
import logging
from database_api import MongoDB

bot = Bot(BOT_TOKEN)
storage = MongoStorage(db_name='iFeedbackBot_fsm')
dp = Dispatcher(bot, storage=storage)

db = MongoDB('iFeedbackBot')
messages = db.messages

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

logger = logging.getLogger('bot')
Esempio n. 12
0
from aiogram import Bot, Dispatcher
from aiogram.contrib.fsm_storage.mongo import MongoStorage
from aiogram.utils.executor import Executor

from app import config

bot = Bot(config.TELEGRAM_TOKEN)
storage = MongoStorage(host=config.MONGO_HOST, port=config.MONGO_PORT)
dp = Dispatcher(bot, storage=storage)
runner = Executor(dp)


def setup():
    from app.models import db
    from app import middlewares
    from app import filters

    db.setup(runner)
    middlewares.setup(dp)
    filters.setup(dp)

    import app.handlers
Esempio n. 13
0
from aiogram import Bot, Dispatcher, types
import os
from aiogram.contrib.fsm_storage.mongo import MongoStorage
import uvloop

API_TOKEN = os.environ['BOT_API_KEY']

bot = Bot(token=API_TOKEN, parse_mode='html')

storage = MongoStorage(host=os.environ['MONGODB_HOSTNAME'],
                       port=os.environ['MONGODB_PORT'],
                       username=os.environ['MONGODB_USERNAME'],
                       password=os.environ['MONGODB_PASSWORD'])

dp = Dispatcher(bot, storage=storage)

uvloop.install()

from bot import modules
from tasks import *