Skip to content

Commit

Permalink
Add additional SubFlairTemplate params
Browse files Browse the repository at this point in the history
Specifically, added allowable_content and max_emojis params.

As discussed as wanted in this Reddit thread by /u/Levi-Ackerbot:
https://www.reddit.com/r/redditdev/comments/dy1qw7/is_there_any_way_to_limit_the_amount_of_emojis_in/
  • Loading branch information
jackodsteel committed Nov 21, 2019
1 parent c2b4c6b commit 828c3d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ Source Contributors
- Timendum `@timendum <https://github.com/timendum>`_
- vaclav-2012 `@vaclav-2012 <https://github.com/vaclav-2012>`_
- kungming2 `@kungming2 <https://github.com/kungming2>`_
- Jack Steel `@jackodsteel <https://github.com/jackodsteel>`_
- Add "Name <email (optional)> and github profile link" above this line.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Unreleased
unmarking a submission as original content.
* Parameter ``without_websockets`` to :meth:`~.Subreddit.submit_image` and
:meth:`~.Subreddit.submit_video` to submit without using WebSockets.
* Parameters ``allowable_content`` and ``max_emojis`` to
:meth:`~.SubredditRedditorFlairTemplates.add`,
:meth:`~.SubredditLinkFlairTemplates.add`, and
:meth:`~.SubredditFlairTemplates.update`, as well as its child classes.

6.4.0 (2019/09/21)
------------------
Expand Down
25 changes: 25 additions & 0 deletions praw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,8 @@ def _add(
background_color=None,
text_color=None,
mod_only=None,
allowable_content=None,
max_emojis=None,
):
url = API_PATH["flairtemplate_v2"].format(subreddit=self.subreddit)
data = {
Expand All @@ -1273,6 +1275,8 @@ def _add(
"text": text,
"text_editable": bool(text_editable),
"mod_only": bool(mod_only),
"allowable_content": allowable_content,
"max_emojis": max_emojis,
}
self.subreddit._reddit.post(url, data=data)

Expand Down Expand Up @@ -1307,6 +1311,8 @@ def update(
background_color=None,
text_color=None,
mod_only=None,
allowable_content=None,
max_emojis=None,
):
"""Update the flair template provided by ``template_id``.
Expand All @@ -1322,6 +1328,9 @@ def update(
``'light'`` or ``'dark'``.
:param mod_only: (boolean) Indicate if the flair can only be used by
moderators.
:param allowable_content: If specified, most be one of ``'all'``,
``'emoji'``, or ``'text'`` to restrict content to that type.
:param max_emojis: (int) Maximum emojis in the flair (default: 10).
For example to make a user flair template text_editable, try:
Expand All @@ -1348,6 +1357,8 @@ def update(
"text_color": text_color,
"text_editable": text_editable,
"mod_only": mod_only,
"allowable_content": allowable_content,
"max_emojis": max_emojis,
}
self.subreddit._reddit.post(url, data=data)

Expand Down Expand Up @@ -1380,6 +1391,8 @@ def add(
background_color=None,
text_color=None,
mod_only=None,
allowable_content=None,
max_emojis=None,
):
"""Add a Redditor flair template to the associated subreddit.
Expand All @@ -1393,6 +1406,9 @@ def add(
``'light'`` or ``'dark'``.
:param mod_only: (boolean) Indicate if the flair can only be used by
moderators.
:param allowable_content: If specified, most be one of ``'all'``,
``'emoji'``, or ``'text'`` to restrict content to that type.
:param max_emojis: (int) Maximum emojis in the flair (default: 10).
For example, to add an editable Redditor flair try:
Expand All @@ -1410,6 +1426,8 @@ def add(
background_color=background_color,
text_color=text_color,
mod_only=mod_only,
allowable_content=allowable_content,
max_emojis=max_emojis,
)

def clear(self):
Expand Down Expand Up @@ -1452,6 +1470,8 @@ def add(
background_color=None,
text_color=None,
mod_only=None,
allowable_content=None,
max_emojis=None,
):
"""Add a link flair template to the associated subreddit.
Expand All @@ -1465,6 +1485,9 @@ def add(
``'light'`` or ``'dark'``.
:param mod_only: (boolean) Indicate if the flair can only be used by
moderators.
:param allowable_content: If specified, most be one of ``'all'``,
``'emoji'``, or ``'text'`` to restrict content to that type.
:param max_emojis: (int) Maximum emojis in the flair (default: 10).
For example, to add an editable link flair try:
Expand All @@ -1482,6 +1505,8 @@ def add(
background_color=background_color,
text_color=text_color,
mod_only=mod_only,
allowable_content=allowable_content,
max_emojis=max_emojis,
)

def clear(self):
Expand Down

0 comments on commit 828c3d5

Please sign in to comment.