Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
feat 💥: Forums rewrite (#646)
Browse files Browse the repository at this point in the history
* refactor: update create forum thread endpoint

* feat 💥: Create NewThreadCreate event

* feat: add forum list_posts

* feat: add forum fetch post

* feat: add forum get_tag

* feat: create_post now supports abstract tags

* feat: impliment non-async list posts

* refactor: rename list_posts -> fetch_posts

* feat 💥: create GuildForumPost object

* feat: add support for post pinning

* docs: update typehints

* docs: remove `forum post only` comments

* docs: type fix on edit method

* fix: tag emoji is now optional

* feat: support archived posts

* fix: use elif

* fix: handle dict passed in applied tags

* fix: correctly process the set tags

Co-authored-by: Daniel <daniel.jaek@gmail.com>
  • Loading branch information
LordOfPolls and Kigstn authored Sep 25, 2022
1 parent 8dabe60 commit 3f0d211
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 43 deletions.
8 changes: 7 additions & 1 deletion naff/api/events/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def on_guild_join(event):
"StageInstanceDelete",
"StageInstanceUpdate",
"ThreadCreate",
"NewThreadCreate",
"ThreadDelete",
"ThreadListSync",
"ThreadMemberUpdate",
Expand Down Expand Up @@ -168,11 +169,16 @@ class ChannelPinsUpdate(ChannelCreate):

@define(kw_only=False)
class ThreadCreate(BaseEvent):
"""Dispatched when a thread is created."""
"""Dispatched when a thread is created, or a thread is new to the client"""

thread: "TYPE_THREAD_CHANNEL" = field(metadata=docs("The thread this event is dispatched from"))


@define(kw_only=False)
class NewThreadCreate(ThreadCreate):
"""Dispatched when a thread is newly created."""


@define(kw_only=False)
class ThreadUpdate(ThreadCreate):
"""Dispatched when a thread is updated."""
Expand Down
8 changes: 5 additions & 3 deletions naff/api/events/processors/thread_events.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import TYPE_CHECKING

import naff.api.events as events

from ._template import EventMixinTemplate, Processor
from naff.models import to_snowflake
from ._template import EventMixinTemplate, Processor

if TYPE_CHECKING:
from naff.api.events import RawGatewayEvent
Expand All @@ -14,7 +13,10 @@
class ThreadEvents(EventMixinTemplate):
@Processor.define()
async def _on_raw_thread_create(self, event: "RawGatewayEvent") -> None:
self.dispatch(events.ThreadCreate(self.cache.place_channel_data(event.data)))
thread = self.cache.place_channel_data(event.data)
if event.data.get("newly_created"):
self.dispatch(events.NewThreadCreate(thread))
self.dispatch(events.ThreadCreate(thread))

@Processor.define()
async def _on_raw_thread_update(self, event: "RawGatewayEvent") -> None:
Expand Down
2 changes: 1 addition & 1 deletion naff/api/http/http_requests/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ async def create_tag(
payload: PAYLOAD_TYPE = {
"name": name,
"emoji_id": int(emoji_id) if emoji_id else None,
"emoji_name": emoji_name,
"emoji_name": emoji_name if emoji_name else None,
}
payload = dict_filter_none(payload)

Expand Down
6 changes: 3 additions & 3 deletions naff/api/http/http_requests/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,23 @@ async def create_forum_thread(
name: The name of the thread
auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
message: The message-content for the post/thread
applied_tags: The tags to apply to the thread
rate_limit_per_user: The time users must wait between sending messages
files: The files to upload
reason: The reason for creating this thread
Returns:
The created thread object
"""
# note: `{"use_nested_fields": 1}` seems to be a temporary flag until forums launch
return await self.request(
Route("POST", f"/channels/{channel_id}/threads"),
payload={
"name": name,
"auto_archive_duration": auto_archive_duration,
"rate_limit_per_user": rate_limit_per_user,
"applied_tags": applied_tags,
"message": message,
"applied_tags": applied_tags,
},
params={"use_nested_fields": 1},
files=files,
reason=reason,
)
Loading

0 comments on commit 3f0d211

Please sign in to comment.