Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding=utf-8
- #-----Импортим Основные Модули----#
- from ez_modules.private_messages import main_private_messages
- from ez_modules.private_commands import main_private_commands
- #-----Важное/Прочее-----#
- #from SQLight import SQLighter #Импортим класс с SQL
- import constants #Импортим наши константы
- import secrets #Для создания хэшей
- import random #рандом
- import re #Регулярки
- import time #Время
- from time import sleep #Отдельно берём sleep для простоты вызова
- from apscheduler.schedulers.asyncio import AsyncIOScheduler #
- from apscheduler.triggers.combining import OrTrigger # Отложки/Задачник
- from apscheduler.triggers.cron import CronTrigger #
- import traceback #Ошибки
- from requests import exceptions #Ошибки тут/исключения
- import threading
- #import aiopika
- import logging
- import datetime
- import asyncio
- import asyncpg
- from asyncio import get_event_loop
- #-----Импорты бота-----#
- from aiogram import Bot, types, executor, dispatcher
- from aiogram.types import ParseMode
- from aiogram.dispatcher import Dispatcher
- from aiogram.contrib.fsm_storage.memory import MemoryStorage
- from aiogram.utils.exceptions import Throttled
- from aiogram.utils.executor import start_polling#, stop_polling
- #-----Настройки бота-----#
- storage = MemoryStorage()
- loop = get_event_loop()
- #scheduler = AsyncIOScheduler(event_loop=loop)
- bot = Bot(token=constants.TOKEN, loop=loop)
- errorbot = Bot(token=constants.ERRORTOKEN)
- dp = Dispatcher(bot, storage=storage)
- #------------------------#
- #loop.create_task(check_order(loop)) #Запускаем отложки.
- logging.basicConfig(level=logging.INFO)
- #------Ловим сообщения-----#
- @dp.message_handler()
- async def all_message(message: types.Message):
- try:
- await main_private_messages(message)
- await main_private_commands(message)
- #await main_banner(message)
- #await main_private(message)
- #await main_inline(message)
- #await cw3_module(message)
- except Exception:
- why = "Main core error."
- await send_exception(message, why, traceback.format_exc())
- #------Ловим Обратную Связь с Кнопотулек(CallBack)-----#
- #@dp.callback_query_handler()
- #async def all_callback(callback_query: types.CallbackQuery):
- # try:
- # await dp.throttle("callback_{0}".format(callback_query.from_user.id), rate=30)
- # except Throttled:
- # await bot.answer_callback_query(callback_query_id=callback_query.id, text="Эй! Не так быстро!", show_alert=False)
- # else:
- # try:
- # await call_cw3_report(callback_query)
- # except Exception:
- # await bot.send_message(errorlogs, "chat_id = {0}\nuser_id = {1}\n{2}".format(callback_query.message.chat.id, callback_query.from_user.id, traceback.format_exc()))
- #----Отправлялка ошибок----#
- async def send_exception(message, why, error):
- try:
- who_tg_id = message.from_user.id
- who_tg_username = message.from_user.username if message.from_user.username else "None."
- where_chat_id = message.chat.id
- where_chat_title = message.chat.title if message.chat.title else "Private."
- error_text = str(error)
- when_tg_date = message.date
- reason = why
- result = f'Who:<a href="tg://user?id={who_tg_id}"> {who_tg_id} </a>| {when_tg_date}\nWhere: {where_chat_id} | [{where_chat_title}]\n'
- result += f'Why: {reason}\n-----\n{error_text}'
- await errorbot.send_message(constants.ERRORS, result, parse_mode=ParseMode.HTML, disable_web_page_preview=True)
- except Exception:
- print("Show must go on!\n", traceback.format_exc())
- async def on_startup(dispatcher: dispatcher):
- time_shit = str(time.strftime("%d.%m.%y %H:%M:%S", time.localtime()))
- await bot.send_message(constants.ERRORS, "Сильви живее всех живыхъ. ~~~ {}".format(time_shit))
- conn = await asyncpg.create_pool(user='юезрка', password='пароль', host='хост', port = '5432', database='database')
- await conn.execute('INSERT INTO dich_plz(text_plz) VALUES($1)', 'Ура, у меня что-то да вышло. вроде')
- print("Чекай бд, пёс")
- dispatcher['db'] = conn
- async def on_shutdown(dispatcher: dispatcher):
- time_shit = str(time.strftime("%d.%m.%y %H:%M:%S", time.localtime()))
- print("Сильви x_x ~~~ {} \nСпаааатькииии.".format(time_shit))
- #await bot.send_message(constants.ERRORS, "Сильви x_x ~~~ {} \nСпаааатькииии.".format(time_shit))
- #db = dp['db']
- if 'db' in dispatcher:
- await dispatcher['db'].close()
- #------Ловим Инлайн(Inline)-----#
- #@dp.inline_handler()
- #async def all_inline(inline_query: types.InlineQuery):
- #await is_inline(inline_query)'''
- #————————————Запуск—Поллинга—и—Задач—————————————————————————————————————————————————————————————————————————————————————————————————————————
- async def el():
- time_shit = str(time.strftime("%d.%m.%y %H:%M:%S", time.localtime()))
- try:
- #await dispatcher.bot.send_message(chat_id=user.id, text="Bot started", disable_notification=True)
- await errorbot.send_message(constants.ERRORS, "Сильви жива!. ~~~ {} \nПоллинг ожил.".format(time_shit))
- #start_polling(dp)
- except:
- error = str(traceback.format_exc())
- sleep(5)
- print("{}\n\n{}\n\n".format(error, time_shit))
- await errorbot.send_message(constants.ERRORS, "Сильви x_x ~~~ {} \nПоллинг упал.".format(time_shit))
- await el()
- if __name__ == '__main__':
- #asyncio.run(el())
- #executor.start(dp, el())
- start_polling(dp, on_startup=on_startup, on_shutdown=on_shutdown)
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement