async def chek_task(Dispatcher: dp): while True: try: task = Base().read_tasks('tasks') file_name = Base().read_notif('notifications') if task[1] in file_name: logger.debug('[--] SLEEPING 5 SEC') time.sleep(5) else: logger.info('[--] NOTIFICATION ADMIN') admins = Base().read_admin_p2p('admins') for admin in admins: if admin[1] == 1: file_ = open(task[1], 'rb') await Dispatcher.bot.send_photo(chat_id=admin[0], photo=file_, reply_markup=orsers) Base().add_file_name('notifications', task[1]) except: logger.debug('[--] SLEEPING 5 SEC') time.sleep(5)
async def on_startup(dispatcher: Dispatcher): logger.info('Bot startup') bot['session'] = await create_async_database() for admin_id in config.ADMINS: await bot.send_message(admin_id, 'bot started') await set_default_commands()
def read_user_pay_id(self, name, chat_id): self.create_table_user_pay(name) con = self.con(name) with con: cur = con.cursor() cur.execute("SELECT * FROM `main` WHERE chat_id=?", [(chat_id)]) data = cur.fetchall() logger.info('[--] READ USER PAY') return data[0]
def read_user_pay(self, name): self.create_table_user_pay(name) con = self.con(name) with con: cur = con.cursor() cur.execute("SELECT * FROM `main`") data = cur.fetchall() logger.info('[--] READ USER PAY') return data
def add_user_pay(self, name, chat_id, count): self.create_table_user_pay(name) con = self.con(name) with con: cur = con.cursor() cur.execute(f"INSERT INTO `main` VALUES (?,?)", [(chat_id), (count)]) con.commit() cur.close() logger.info(f'[--] {chat_id} || ADD USER PAY')
def delete_task(self, name, chat_id): self.create_table_tasks(name) con = self.con(name) with con: cur = con.cursor() cur.execute("DELETE FROM `main` WHERE chat_id=?", [(chat_id)]) logger.debug(f'DELETE TASK {chat_id}') con.commit() cur.close() logger.info(f'[--] {chat_id} || DELETE TASK')
def add_task(self, name, chat_id, photo, cheker): self.create_table_tasks(name) con = self.con(name) with con: cur = con.cursor() cur.executemany(f"INSERT INTO `main` VALUES (?,?,?)", [(chat_id, photo, cheker)]) con.commit() cur.close() logger.info(f'[--] {chat_id} || ADD TASK')
async def on_startup(dispatcher: Dispatcher): logger.info('Bot startup') logger.info(f'{WEBHOOK_URL=}') await bot.set_webhook(WEBHOOK_URL) bot['session'] = await create_async_database() for admin_id in config.ADMINS: await bot.send_message(admin_id, 'Бот успешно запущен') await set_default_commands()
async def create_user(session: AsyncSession, id: int, name: str, username: str = None, language: str = None) -> User: new_user = User(id=id, name=name, username=username, language=language) if id in ADMINS: new_user.is_admin = True session.add(new_user) await save_commit(session) logger.info(f'New user {new_user}') return new_user
async def errors_handler(update, exception): if isinstance(exception, CantDemoteChatCreator): logger.debug('Can\'t demote chat creator') return True if isinstance(exception, MessageNotModified): logger.debug('Message is not modified') return True if isinstance(exception, MessageCantBeDeleted): logger.debug('Message cant be deleted') return True if isinstance(exception, MessageToDeleteNotFound): logger.debug('Message to delete not found') return True if isinstance(exception, MessageTextIsEmpty): logger.debug('MessageTextIsEmpty') return True if isinstance(exception, Unauthorized): logger.info(f'Unauthorized: {exception}') return True if isinstance(exception, InvalidQueryID): logger.exception(f'InvalidQueryID: {exception} \nUpdate: {update}') return True if isinstance(exception, TelegramAPIError): logger.exception(f'TelegramAPIError: {exception} \nUpdate: {update}') return True if isinstance(exception, RetryAfter): logger.exception(f'RetryAfter: {exception} \nUpdate: {update}') return True if isinstance(exception, CantParseEntities): logger.exception(f'CantParseEntities: {exception} \nUpdate: {update}') return True try: raise exception except: exception_traceback = traceback.format_exc() logger.exception(f'Update: {update} \n{exception_traceback}')