Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add thread_name field in the webhook field #1722

Merged
merged 9 commits into from
Oct 4, 2024

Conversation

retr0-init
Copy link
Contributor

@retr0-init retr0-init commented Jul 27, 2024

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

This enables the API to create thread in forum and media channels.

Changes

  • Added thread_name field to the api.http.http_requests.webhook.WebhookRequests.execute_webhook method.
  • Added thread_name field to the models.discord.webhook.Webhook.send method
  • add exclusive check between the thread_name and thread

Related Issues

#1721

Test Scenarios

@interactions.slash_command(
    "test1", description="test channel command", scopes=[DEV_GUILD] if DEV_GUILD else None
)
@interactions.slash_option(
    name="channel",
    description="Channel",
    opt_type=interactions.OptionType.CHANNEL,
    required=True
)
async def test_cmd(self, ctx: interactions.SlashContext, channel: interactions.GuildForum):
    """Register as an extension command"""
    await ctx.send(f"Test Create a post in channel {channel.mention} with webhook")
    wbs: list[interactions.Webhook] = await channel.fetch_webhooks()
    if len(wbs) > 0:
        msg: interactions.Message = await wbs[0].send("test content", embed=interactions.Embed(
            title="Embed title",
            description="Embed desc"
        ), wait=True, thread_name="Post Title")
        await ctx.send(f"Created {msg.jump_url}")

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

@retr0-init
Copy link
Contributor Author

Should I add a check in the method to say thread and thread_name cannot be set together? I think an exception should be created somewhere. Probably in the send method.
Additionally, there should be a channel check whether this should be used there so another exception needs to be created.
I suggest two exception names: WebhookConflictParameters and WebhookInvalidDestination, which both inherits from LibraryException.
What names would you suggest?

@AstreaTSS
Copy link
Member

Typically, input errors like this are just handled through ValueError. I don't see a need of adding a new type of error.

@retr0-init
Copy link
Contributor Author

I think the error report from the discord API for channel checking is enough along with the warnings in the docstring. It should be ready for review.

@retr0-init retr0-init marked this pull request as ready for review July 27, 2024 22:04
@retr0-init
Copy link
Contributor Author

I think this is good to be merged. Is there any further modification needed?

@silasary
Copy link
Member

silasary commented Oct 4, 2024

Yeah, I'm happy with it

@silasary silasary merged commit 5b07e41 into interactions-py:unstable Oct 4, 2024
2 checks passed
@retr0-init retr0-init deleted the issue-1721 branch October 21, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants