Skip to content

Commit eba0f0a

Browse files
Add nsfw config option for application commands (#802)
Co-authored-by: always-on-duty[bot] <120557446+always-on-duty[bot]@users.noreply.github.com>
1 parent 934d3eb commit eba0f0a

File tree

8 files changed

+250
-125
lines changed

8 files changed

+250
-125
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
## [2.16.0] - 2023-07-26
9+
- `nsfw` config option for application commands.
10+
811
## [2.15.0] - 2023-05-31
912
### Added
1013
- [dependencies.add_cooldown][tanjun.dependencies.limiters.add_cooldown] and
@@ -961,7 +964,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
961964
- Support for python 3.8 in-order to switch over to using collection.abc generic classes due to this being more
962965
forward compatible.
963966

964-
[Unreleased]: https://github.com/FasterSpeeding/Tanjun/compare/v2.15.0...HEAD
967+
[Unreleased]: https://github.com/FasterSpeeding/Tanjun/compare/v2.16.0...HEAD
968+
[2.16.0]: https://github.com/FasterSpeeding/Tanjun/compare/v2.15.0...v2.16.0
965969
[2.15.0]: https://github.com/FasterSpeeding/Tanjun/compare/v2.14.0...v2.15.0
966970
[2.14.0]: https://github.com/FasterSpeeding/Tanjun/compare/v2.13.0...v2.14.0
967971
[2.13.0]: https://github.com/FasterSpeeding/Tanjun/compare/v2.12.0...v2.13.0

dev-requirements/type-checking.txt

Lines changed: 108 additions & 108 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "hikari-tanjun"
7-
version = "2.15.0"
7+
version = "2.16.0"
88
readme = "README.md"
99
requires-python = ">=3.9.0,<3.12"
1010
license = {file = "LICENSE"}

tanjun/abc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,10 @@ def is_global(self) -> bool:
27292729
is inherited regardless of what it's set as on the child command.
27302730
"""
27312731

2732+
@property
2733+
def is_nsfw(self) -> typing.Optional[bool]:
2734+
"""Whether a command should only be accessible in channels marked as NSFW."""
2735+
27322736
@property
27332737
@abc.abstractmethod
27342738
def name(self) -> str:

tanjun/commands/menu.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def as_message_menu(
9595
default_to_ephemeral: typing.Optional[bool] = None,
9696
dm_enabled: typing.Optional[bool] = None,
9797
is_global: bool = True,
98+
nsfw: bool = False,
9899
) -> _AsMsgResultProto:
99100
"""Build a message [MenuCommand][tanjun.MenuCommand] by decorating a function.
100101
@@ -145,6 +146,9 @@ async def message_command(self, ctx: tanjun.abc.MenuContext, message: hikari.Mes
145146
will be used.
146147
is_global
147148
Whether this command is a global command.
149+
nsfw
150+
Whether this command should only be accessible in channels marked as
151+
nsfw.
148152
149153
Returns
150154
-------
@@ -185,6 +189,7 @@ def decorator(
185189
default_to_ephemeral=default_to_ephemeral,
186190
dm_enabled=dm_enabled,
187191
is_global=is_global,
192+
nsfw=nsfw,
188193
_wrapped_command=wrapped_command,
189194
)
190195

@@ -216,6 +221,7 @@ def as_user_menu(
216221
default_to_ephemeral: typing.Optional[bool] = None,
217222
dm_enabled: typing.Optional[bool] = None,
218223
is_global: bool = True,
224+
nsfw: bool = False,
219225
) -> _AsUserResultProto:
220226
"""Build a user [MenuCommand][tanjun.MenuCommand] by decorating a function.
221227
@@ -268,6 +274,9 @@ async def user_command(
268274
will be used.
269275
is_global
270276
Whether this command is a global command.
277+
nsfw
278+
Whether this command should only be accessible in channels marked as
279+
nsfw.
271280
272281
Returns
273282
-------
@@ -308,6 +317,7 @@ def decorator(
308317
default_to_ephemeral=default_to_ephemeral,
309318
dm_enabled=dm_enabled,
310319
is_global=is_global,
320+
nsfw=nsfw,
311321
_wrapped_command=wrapped_command,
312322
)
313323

@@ -328,6 +338,7 @@ class MenuCommand(base.PartialCommand[tanjun.MenuContext], tanjun.MenuCommand[_A
328338
"_description",
329339
"_is_dm_enabled",
330340
"_is_global",
341+
"_is_nsfw",
331342
"_names",
332343
"_parent",
333344
"_tracked_command",
@@ -348,6 +359,7 @@ def __init__(
348359
default_to_ephemeral: typing.Optional[bool] = None,
349360
dm_enabled: typing.Optional[bool] = None,
350361
is_global: bool = True,
362+
nsfw: bool = False,
351363
_wrapped_command: typing.Optional[tanjun.ExecutableCommand[typing.Any]] = None,
352364
) -> None:
353365
...
@@ -367,6 +379,7 @@ def __init__(
367379
default_to_ephemeral: typing.Optional[bool] = None,
368380
dm_enabled: typing.Optional[bool] = None,
369381
is_global: bool = True,
382+
nsfw: bool = False,
370383
_wrapped_command: typing.Optional[tanjun.ExecutableCommand[typing.Any]] = None,
371384
) -> None:
372385
...
@@ -384,6 +397,7 @@ def __init__(
384397
default_to_ephemeral: typing.Optional[bool] = None,
385398
dm_enabled: typing.Optional[bool] = None,
386399
is_global: bool = True,
400+
nsfw: bool = False,
387401
_wrapped_command: typing.Optional[tanjun.ExecutableCommand[typing.Any]] = None,
388402
) -> None:
389403
...
@@ -403,6 +417,7 @@ def __init__(
403417
default_to_ephemeral: typing.Optional[bool] = None,
404418
dm_enabled: typing.Optional[bool] = None,
405419
is_global: bool = True,
420+
nsfw: bool = False,
406421
_wrapped_command: typing.Optional[tanjun.ExecutableCommand[typing.Any]] = None,
407422
) -> None:
408423
...
@@ -422,6 +437,7 @@ def __init__(
422437
default_to_ephemeral: typing.Optional[bool] = None,
423438
dm_enabled: typing.Optional[bool] = None,
424439
is_global: bool = True,
440+
nsfw: bool = False,
425441
_wrapped_command: typing.Optional[tanjun.ExecutableCommand[typing.Any]] = None,
426442
) -> None:
427443
"""Initialise a user or message menu command.
@@ -475,6 +491,9 @@ def __init__(
475491
will be used.
476492
is_global
477493
Whether this command is a global command.
494+
nsfw
495+
Whether this command should only be accessible in channels marked as
496+
nsfw.
478497
479498
Returns
480499
-------
@@ -513,6 +532,7 @@ def __init__(
513532
self._defaults_to_ephemeral = default_to_ephemeral
514533
self._is_dm_enabled = dm_enabled
515534
self._is_global = is_global
535+
self._is_nsfw = nsfw
516536
self._names = names
517537
self._parent: typing.Optional[tanjun.SlashCommandGroup] = None
518538
self._tracked_command: typing.Optional[hikari.ContextMenuCommand] = None
@@ -551,6 +571,11 @@ def is_global(self) -> bool:
551571
# <<inherited docstring from tanjun.abc.AppCommand>>.
552572
return self._is_global
553573

574+
@property
575+
def is_nsfw(self) -> typing.Optional[bool]:
576+
# <<inherited docstring from tanjun.abc.AppCommand>>.
577+
return self._is_nsfw
578+
554579
@property
555580
def name(self) -> str:
556581
# <<inherited docstring from tanjun.abc.AppCommand>>.
@@ -583,7 +608,10 @@ def wrapped_command(self) -> typing.Optional[tanjun.ExecutableCommand[typing.Any
583608
def build(self, *, component: typing.Optional[tanjun.Component] = None) -> hikari.api.ContextMenuCommandBuilder:
584609
# <<inherited docstring from tanjun.abc.MenuCommand>>.
585610
builder = hikari.impl.ContextMenuCommandBuilder(
586-
type=self._type, name=self._names.default_value, name_localizations=self._names.localised_values
611+
type=self._type,
612+
name=self._names.default_value,
613+
name_localizations=self._names.localised_values,
614+
is_nsfw=self._is_nsfw,
587615
)
588616

589617
component = component or self._component

0 commit comments

Comments
 (0)