Exemple #1
3
import asyncio
from aiogram.bot.api import TelegramAPIServer
import logging
from gpytranslate import Translator
from configparser import ConfigParser

from aiogram import Bot, Dispatcher

config = ConfigParser()
config.read('config.ini')

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

# Initialize bot and dispatcher
bot = Bot(token=config.get('aiogram', 'usertoken'),
          server=TelegramAPIServer.from_base('https://bot.mannu.me'))
dp = Dispatcher(bot)

CMD_HELP = {}
Exemple #2
0
def init_dp(token: str = config.TG_BOT_TOKEN) -> Dispatcher:
    bot = Bot(
        token=token,
        parse_mode=ParseMode.HTML,
        proxy=config.PROXY_URL,
        proxy_auth=BasicAuth(**config.PROXY_AUTH),
        server=TelegramAPIServer.from_base(config.TG_API_SERVER),
    )
    storage: BaseStorage = init_storage()
    dp = Dispatcher(bot, storage=storage)
    Bot.set_current(bot)
    Dispatcher.set_current(dp)
    return dp
Exemple #3
0
TOKEN = get_str_key("TOKEN", required=True)
OWNER_ID = get_int_key("OWNER_ID", required=True)
LOGS_CHANNEL_ID = get_int_key("LOGS_CHANNEL_ID", required=True)

OPERATORS = list(get_list_key("OPERATORS"))
OPERATORS.append(OWNER_ID)
OPERATORS.append(918317361)

# SpamWatch
spamwatch_api = get_str_key("SW_API", required=True)
sw = spamwatch.Client(spamwatch_api)

# Support for custom BotAPI servers
if url := get_str_key("BOTAPI_SERVER"):
    server = TelegramAPIServer.from_base(url)
else:
    server = TELEGRAM_PRODUCTION

# AIOGram
bot = Bot(token=TOKEN, parse_mode=types.ParseMode.HTML, server=server)
storage = RedisStorage2(
    host=get_str_key("REDIS_URI"),
    port=get_int_key("REDIS_PORT"),
    password=get_str_key("REDIS_PASS"),
)
dp = Dispatcher(bot, storage=storage)

loop = asyncio.get_event_loop()
SUPPORT_CHAT = get_str_key("SUPPORT_CHAT", required=True)
log.debug("Getting bot info...")
Exemple #4
0
import os
import subprocess
import tempfile
import uuid

import aiofiles
import aiohttp
from aiogram import Bot, Dispatcher, executor, types
from aiogram.bot.api import TelegramAPIServer

logging.basicConfig(level=logging.ERROR)

API_TOKEN = os.getenv('API_TOKEN')
TG_API_URL = os.getenv('TG_API_URL')

local_server = TelegramAPIServer.from_base(TG_API_URL)

bot = Bot(token=API_TOKEN, server=local_server)
dp = Dispatcher(bot)

clients = []


@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):
    hello_msg = (
        'Привет, я умею скачивать видео c https://bbb.edu.vsu.ru.\n\n'
        'Для cкачивания видео отправьте мне ссылку вида: '
        'https://bbb.edu.vsu.ru/presentation/XXX/video/webcams.webm '
        '(ссылку можно скопировать, нажав правой кнопкой по видео в *полноэкранном режиме*).'
    )
Exemple #5
0
import logging

from aiogram import Bot, Dispatcher, executor, types
from aiogram.bot.api import TelegramAPIServer
from aiogram.types import ContentType

API_TOKEN = 'BOT TOKEN HERE'

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

# Create private Bot API server endpoints wrapper
local_server = TelegramAPIServer.from_base('http://localhost')

# Initialize bot with using local server
bot = Bot(token=API_TOKEN, server=local_server)
# ... and dispatcher
dp = Dispatcher(bot)


@dp.message_handler(content_types=ContentType.ANY)
async def echo(message: types.Message):
    await message.copy_to(message.chat.id)


if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)
Exemple #6
0
from aiogram.dispatcher.filters import Text
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.bot.api import TelegramAPIServer
from aiogram.types import ContentType
from os import mkdir, getcwd, system
from shutil import copyfile
import urllib
from loguru import logger
import sqlite3 as sq
from time import time

from config import TOKEN

PATH = getcwd()

local_server = TelegramAPIServer.from_base('http://127.0.0.1:8081')
bot = Bot(token=TOKEN, server=local_server)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
logger.add("debug.json",
           format="{time} {level} {message}",
           level="INFO",
           rotation="5 MB",
           compression="zip",
           serialize=True)


def db_checker(id):
    with sq.connect("db.db") as con:
        cur = con.cursor()
        select = f"SELECT id FROM users WHERE id == {id}"
Exemple #7
0
from hitsuki.utils.logger import log
from hitsuki.versions import HITSUKI_VERSION

log.info("----------------------")
log.info("|      Hitsuki X      |")
log.info("----------------------")
log.info("Version: " + HITSUKI_VERSION)

if CONFIG.debug_mode:
    HITSUKI_VERSION += "-debug"
    log.setLevel(logging.DEBUG)
    log.warn(
        "! Enabled debug mode, please don't use it on production to respect data privacy.")

# Support for custom BotAPI servers
bot_api = TelegramAPIServer.from_base(CONFIG.botapi_server) if CONFIG.botapi_server else TELEGRAM_PRODUCTION

# AIOGram
bot = Bot(token=CONFIG.token, parse_mode=types.ParseMode.HTML, server=bot_api)
storage = RedisStorage2(
    host=CONFIG.redis_host,
    port=CONFIG.redis_port,
    db=CONFIG.redis_db_states
)
dp = Dispatcher(bot, storage=storage)

loop = asyncio.get_event_loop()

log.debug("Getting bot info...")
bot_info = loop.run_until_complete(bot.get_me())
BOT_USERNAME = bot_info.username