Skip to content

Commit 2811842

Browse files
authored
feat: Expand "modify" helper methods into single-argument helper methods to make editing of only one field easier (#479)
* channel.modify * refactor: add `*` * some guild stuff * feat: expand guild.modify * feat: expand guild.modify
1 parent b836d5b commit 2811842

File tree

4 files changed

+502
-10
lines changed

4 files changed

+502
-10
lines changed

interactions/api/models/channel.py

Lines changed: 159 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ async def modify(
302302
:type parent_id: Optional[int]
303303
:param nsfw?: Whether the channel is nsfw or not, defaults to the current value of the channel
304304
:type nsfw: Optional[bool]
305-
:param reason: The reason for the edit
305+
:param reason?: The reason for the edit
306306
:type reason: Optional[str]
307307
:return: The modified channel as new object
308308
:rtype: Channel
@@ -339,6 +339,164 @@ async def modify(
339339
)
340340
return Channel(**res, _client=self._client)
341341

342+
async def set_name(
343+
self,
344+
name: str,
345+
*,
346+
reason: Optional[str] = None,
347+
) -> "Channel":
348+
"""
349+
Sets the name of the channel.
350+
351+
:param name: The new name of the channel
352+
:type name: str
353+
:param reason?: The reason of the edit
354+
:type reason: Optional[str]
355+
:return: The edited channel
356+
:rtype: Channel
357+
"""
358+
359+
return await self.modify(name=name, reason=reason)
360+
361+
async def set_topic(
362+
self,
363+
topic: str,
364+
*,
365+
reason: Optional[str] = None,
366+
) -> "Channel":
367+
"""
368+
Sets the topic of the channel.
369+
370+
:param topic: The new topic of the channel
371+
:type topic: str
372+
:param reason?: The reason of the edit
373+
:type reason: Optional[str]
374+
:return: The edited channel
375+
:rtype: Channel
376+
"""
377+
378+
return await self.modify(topic=topic, reason=reason)
379+
380+
async def set_bitrate(
381+
self,
382+
bitrate: int,
383+
*,
384+
reason: Optional[str] = None,
385+
) -> "Channel":
386+
"""
387+
Sets the bitrate of the channel.
388+
389+
:param bitrate: The new bitrate of the channel
390+
:type bitrate: int
391+
:param reason?: The reason of the edit
392+
:type reason: Optional[str]
393+
:return: The edited channel
394+
:rtype: Channel
395+
"""
396+
397+
if self.type != ChannelType.GUILD_VOICE:
398+
raise TypeError("Bitrate is only available for VoiceChannels")
399+
400+
return await self.modify(bitrate=bitrate, reason=reason)
401+
402+
async def set_user_limit(
403+
self,
404+
user_limit: int,
405+
*,
406+
reason: Optional[str] = None,
407+
) -> "Channel":
408+
"""
409+
Sets the user_limit of the channel.
410+
411+
:param user_limit: The new user limit of the channel
412+
:type user_limit: int
413+
:param reason?: The reason of the edit
414+
:type reason: Optional[str]
415+
:return: The edited channel
416+
:rtype: Channel
417+
"""
418+
419+
if self.type != ChannelType.GUILD_VOICE:
420+
raise TypeError("user_limit is only available for VoiceChannels")
421+
422+
return await self.modify(user_limit=user_limit, reason=reason)
423+
424+
async def set_rate_limit_per_user(
425+
self,
426+
rate_limit_per_user: int,
427+
*,
428+
reason: Optional[str] = None,
429+
) -> "Channel":
430+
"""
431+
Sets the position of the channel.
432+
433+
:param rate_limit_per_user: The new rate_limit_per_user of the channel (0-21600)
434+
:type rate_limit_per_user: int
435+
:param reason?: The reason of the edit
436+
:type reason: Optional[str]
437+
:return: The edited channel
438+
:rtype: Channel
439+
"""
440+
441+
return await self.modify(rate_limit_per_user=rate_limit_per_user, reason=reason)
442+
443+
async def set_position(
444+
self,
445+
position: int,
446+
*,
447+
reason: Optional[str] = None,
448+
) -> "Channel":
449+
"""
450+
Sets the position of the channel.
451+
452+
:param position: The new position of the channel
453+
:type position: int
454+
:param reason?: The reason of the edit
455+
:type reason: Optional[str]
456+
:return: The edited channel
457+
:rtype: Channel
458+
"""
459+
460+
return await self.modify(position=position, reason=reason)
461+
462+
async def set_parent_id(
463+
self,
464+
parent_id: int,
465+
*,
466+
reason: Optional[str] = None,
467+
) -> "Channel":
468+
"""
469+
Sets the parent_id of the channel.
470+
471+
:param parent_id: The new parent_id of the channel
472+
:type parent_id: int
473+
:param reason?: The reason of the edit
474+
:type reason: Optional[str]
475+
:return: The edited channel
476+
:rtype: Channel
477+
"""
478+
479+
return await self.modify(parent_id=parent_id, reason=reason)
480+
481+
async def set_nsfw(
482+
self,
483+
nsfw: bool,
484+
*,
485+
reason: Optional[str] = None,
486+
) -> "Channel":
487+
"""
488+
Sets the nsfw-flag of the channel.
489+
490+
:param nsfw: The new nsfw-flag of the channel
491+
:type nsfw: bool
492+
:param reason?: The reason of the edit
493+
:type reason: Optional[str]
494+
:return: The edited channel
495+
:rtype: Channel
496+
"""
497+
498+
return await self.modify(nsfw=nsfw, reason=reason)
499+
342500
async def add_member(
343501
self,
344502
member_id: int,

interactions/api/models/channel.pyi

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,61 @@ class Channel(DictSerializerMixin):
103103
nsfw: Optional[bool] = MISSING,
104104
reason: Optional[str] = None,
105105
) -> "Channel": ...
106+
async def set_name(
107+
self,
108+
name: str,
109+
*,
110+
reason: Optional[str] = None
111+
) -> "Channel": ...
112+
async def set_topic(
113+
self,
114+
topic: str,
115+
*,
116+
reason: Optional[str] = None
117+
) -> "Channel": ...
118+
async def set_bitrate(
119+
self,
120+
bitrate: int,
121+
*,
122+
reason: Optional[str] = None
123+
) -> "Channel": ...
124+
async def set_user_limit(
125+
self,
126+
user_limit: int,
127+
*,
128+
reason: Optional[str] = None
129+
) -> "Channel": ...
130+
async def set_rate_limit_per_user(
131+
self,
132+
rate_limit_per_user: int,
133+
*,
134+
reason: Optional[str] = None
135+
) -> "Channel": ...
136+
async def set_position(
137+
self,
138+
position: int,
139+
*,
140+
reason: Optional[str] = None
141+
) -> "Channel": ...
142+
async def set_parent_id(
143+
self,
144+
parent_id: int,
145+
*,
146+
reason: Optional[str] = None
147+
) -> "Channel": ...
148+
async def set_nsfw(
149+
self,
150+
nsfw: bool,
151+
*,
152+
reason: Optional[str] = None
153+
) -> "Channel": ...
106154
async def add_member(
107155
self,
108156
member_id: int,
109157
) -> None: ...
110158
async def pin_message(
111-
self,
112-
message_id: int,
159+
self,
160+
message_id: int,
113161
) -> None: ...
114162
async def unpin_message(
115163
self,
@@ -121,8 +169,8 @@ class Channel(DictSerializerMixin):
121169
) -> Message: ...
122170
async def get_pinned_messages(self) -> List[Message]: ...
123171
async def get_message(
124-
self,
125-
message_id: int,
172+
self,
173+
message_id: int,
126174
) -> Message: ...
127175
async def purge(
128176
self,

0 commit comments

Comments
 (0)