ziyadm / test-bot-repo

0 stars 0 forks source link

store thread id in mission row so we can look up by it #132

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

https://github.com/ziyadm/test-bot-repo/blob/4e1b3531036f4bb58ebcf5aec895f61af995274e/command_handler.py#L275


        )

    async def claim_command(self, interaction: discord.Interaction):
        try:
            # TODO: store thread id in mission row so we can look up by it
            question_discord_channel_id = str(interaction.channel.name.split("-")[1])
            mission_to_update = await Mission.row(
                formula=pyairtable.formulas.match(
                    {mission.Fields.discord_channel_id_field: question_discord_channel_id}
                ),
                airtable_client=self.__state.airtable_client,
            )
        except Exception:
            _ = await self.__state.messenger.command_cannot_be_run_here(
                where_to_follow_up=interaction.followup,
                expected_location=None,
                suggested_command=None,
            )
            return None
        else:
            if not CommandHandler.in_review(mission_to_update):
                return await interaction.followup.send("""Review already claimed!""")

            user_to_update = await User.row(
                formula=pyairtable.formulas.match(
                    {user.Fields.discord_id_field: mission_to_update.fields.player_discord_id}
                ),
                airtable_client=self.__state.airtable_client,
            )

            question_to_update = await Question.row(
                formula=pyairtable.formulas.match(
                    {question.Fields.question_id_field: mission_to_update.fields.question_id}
                ),
                airtable_client=self.__state.airtable_client,
            )

            question_review_channel = await self.__state.discord_client.create_private_channel(
                interaction.user.id,
                f"{mission_to_update.fields.stage.get_field()}-{mission_to_update.fields.question_id}-{user_to_update.fields.discord_name}",
            )
            design_stage = mission_to_update.fields.stage.has_value(
                Stage.design_review
            ) or mission_to_update.fields.stage.has_value(Stage.design)
            content_value = (
                mission_to_update.fields.design if design_stage else mission_to_update.fields.code
            )

            await question_review_channel.send(
                f"Question: {question_to_update.fields.leetcode_url}\n\nContent: {content_value}"
            )
            response = f"Review claimed: {question_review_channel.mention}"

            await mission_to_update.update(
                fields=mission_to_update.fields.immutable_updates(
                    {
                        mission.Fields.review_discord_channel_id_field: str(
                            question_review_channel.id
                        ),
                        mission.Fields.reviewer_discord_id_field: interaction.user.id,
                    }
                ),
                airtable_client=self.__state.airtable_client,
            )

            return await interaction.followup.send(response)

    async def set_rank(self, interaction: discord.Interaction, user_discord_name: str, rank: str):
        user_to_update = await User.row(
github-actions[bot] commented 1 year ago

Closed in cca92a26be9e79626869f5833729d1c0973d4256

ziyadm commented 1 year ago

not sure why this autoclosed?

github-actions[bot] commented 1 year ago

Closed in 92f0ce34bcad773845bdd7e8539a0bf3cf3de6ea