def sample_module(update, context):
    chat = update.effective_chat

    context.bot.send_chat_action(chat_id=chat.id, action=ChatAction.TYPING)
    try:
        response = "This is a Sample module"

        update.effective_message.reply_text(text=response,
                                            parse_mode=ParseMode.MARKDOWN,
                                            reply_markup=None)
    except Exception as e:
        logger.exception(e)
Пример #2
0
async def client_game_profile_list(
    profile_id: str = Cookie(..., alias="PHPSESSID"),
) -> Union[TarkovSuccessResponse[List[dict]], TarkovErrorResponse]:
    try:
        async with profile_manager.locks[profile_id]:
            profile = profile_manager.get_profile(profile_id)
            return TarkovSuccessResponse(data=[
                profile.pmc.dict(exclude_none=True),
                profile.scav.dict(exclude_none=True),
            ])
    except Profile.ProfileDoesNotExistsError as error:
        logger.exception(error)
        return TarkovSuccessResponse(data=[])
Пример #3
0
 async def with_profile_readonly(
     self,
     profile_id: str = Cookie(..., alias="PHPSESSID"),
 ) -> AsyncIterable[Profile]:
     """
     Provides a Profile instance
     Should work the same way as with_profile method but it won't save the profile
     """
     async with self.locks[profile_id]:
         profile = self.get_profile(profile_id)
         try:
             yield profile
         except Exception as error:
             profile.read()
             logger.exception(error)
             raise
Пример #4
0
async def with_profile_readonly(
    request: Request,
    profile_id: str = Cookie(..., alias="PHPSESSID"),
) -> AsyncIterable[Profile]:
    """
    Provides a Profile instance
    Should work the same way as with_profile method but it won't save the profile
    """
    profile_manager: ProfileManager = request.app.container.profile.manager()

    async with profile_manager.locks[profile_id]:
        profile = profile_manager.get_profile(profile_id)
        try:
            yield profile
        except Exception as error:
            profile.read()
            logger.exception(error)
            raise
Пример #5
0
    async def with_profile(
        self,
        background_tasks: BackgroundTasks,
        profile_id: str = Cookie(..., alias="PHPSESSID"),
    ) -> AsyncIterable[Profile]:
        """
        Provides a Profile instance and saves it after request using background task
        Should be only used as a dependency for fastapi routes
        """
        async with self.locks[profile_id]:
            profile = self.get_profile(profile_id)
            try:
                background_tasks.add_task(self._save_profile_task, profile)
                profile.update()
                yield profile

            except Exception as error:
                # Else read it again from filesystem
                profile.read()
                logger.exception(error)
                raise
Пример #6
0
def help_button(bot: Bot, update: Update):
    query = update.callback_query
    suggestion_match = re.match(r"help_action=(.+?)", query.data)
    back_button = re.match(r"help_back", query.data)
    try:
        if suggestion_match:
            text = query.data.split('=', 1)[1]
            text = text.split(' ')
            get_help(bot, update, args=text)
        elif back_button:
            get_help(bot, update, args=[])

        # ensure no spinning white circle
        bot.answer_callback_query(query.id)
        query.message.delete()
    except BadRequest as e:
        if e.message == "Message is not modified":
            pass
        elif e.message == "Query_id_invalid":
            pass
        elif e.message == "Message can't be deleted":
            pass
        else:
            logger.exception("Exception in help buttons. %s", str(query.data))
Пример #7
0
def qpapers_button(update, context):
    chat = update.effective_chat
    context.bot.send_chat_action(chat_id=chat.id, action=ChatAction.TYPING)
    query = update.callback_query
    logger.info(query.data)
    course_match = re.match(r"qa=(.+?)", query.data)
    back_button_match = re.match(r"qa_back", query.data)
    try:
        if course_match:
            text = query.data.split('=', 1)[1].split('+')
            logger.info(text)

            back_data = "qa_back"

            if len(text) == 1:
                # course selected => select branch
                button_list, word, colm = course(text)

            elif len(text) == 2:
                # course, branch selected => select sem
                button_list, word, colm, back_data = course_branch(text)

            elif len(text) == 3:
                # course, branch, sem selected => select subject
                button_list, word, colm, back_data = course_branch_sem(text)

            elif len(text) == 4:
                # course, branch, sem, subject selected => send the links here
                button_list, word, colm, back_data = course_branch_sem_sub(
                    text)

            else:
                word = "Some Unknown Error\n Use /feedback to send feedback about this error)"
                send_qpapers(update, text=word, keyboard=None)
                return

            # adding back button for easy traversing
            footer_button = [
                InlineKeyboardButton(text="[Back]", callback_data=back_data)
            ]

            reply_markup_keyboard = InlineKeyboardMarkup(
                button_menu.build_menu(button_list,
                                       n_cols=colm,
                                       footer_buttons=footer_button))
            send_qpapers(update, text=word, keyboard=reply_markup_keyboard)

        elif back_button_match:
            get_qpapers(update, context)

        # ensure no spinning white circle
        context.bot.answer_callback_query(query.id)
        query.message.delete()
    except BadRequest as e:
        if e.message == "Message is not modified":
            pass
        elif e.message == "Query_id_invalid":
            pass
        elif e.message == "Message can't be deleted":
            pass
        else:
            logger.exception("Exception :  %s", str(query.data))