redditwarp.siteprocs.flair.ASYNC#

class redditwarp.siteprocs.flair.ASYNC.FlairProcedures(client: Client)[source]#

Bases: object

async set_user_flair(sr: str, user: str, text: str | None, css_class: str | None = None) None[source]#

Set the flair information on a user.

Any previously set flair information will be discarded.

A null argument means the field will not be sent in the request. The API treats this as the same as supplying an empty string.

To revoke a flair, specify null or an empty string for the text and css_class parameters.

Parameters:
  • sr (str) – Subreddit name.

  • user (str) – User name.

  • text (Optional[str]) –

    Flair text.

    Specify a string no longer than 64 characters. If longer than 64 characters then the parameter is ignored and an empty string is used.

  • css_class (Optional[str]) –

    Flair CSS class.

    Specify a string no longer than 100 characters. If longer than 100 characters then a BAD_CSS_NAME API error is returned.

Return type:

None

Raises:
  • redditwarp.exceptions.RedditError

    • BAD_FLAIR_TARGET:

      The specified user doesn’t exist.

    • BAD_CSS_NAME:
      • The specified CSS class was longer than 100 characters.

      • The specified CSS class contained invalid characters.

  • redditwarp.http.exceptions.StatusCodeException

    • 403:
      • There is no user context.

      • You do not have permission to set flairs in the specified subreddit.

    • 404:

      The specified subreddit does not exist.

async set_post_flair(sr: str, subm: int | str, text: str | None, css_class: str | None = None) None[source]#

Set the flair information on a post.

Any previously set flair information will be discarded.

A null argument means the field will not be sent in the request. The API treats this as the same as supplying an empty string.

To revoke a flair, specify null or an empty string for the text and css_class parameters.

Parameters:
  • sr (str) – Subreddit name.

  • subm (Union[int, str]) – Submission ID.

  • text (Optional[str]) –

    Flair text.

    Specify a string no longer than 64 characters. If longer than 64 characters then the parameter is ignored and an empty string is used.

  • css_class (Optional[str]) –

    Flair CSS class.

    Specify a string no longer than 100 characters. If longer than 100 characters then a BAD_CSS_NAME API error is returned.

Return type:

None

Raises:
  • redditwarp.exceptions.RedditError

    • BAD_FLAIR_TARGET:

      The specified submission doesn’t exist.

    • BAD_CSS_NAME:
      • The specified CSS class was longer than 100 characters.

      • The specified CSS class contained invalid characters.

  • redditwarp.http.exceptions.StatusCodeException

    • 403:
      • There is no user context.

      • You do not have permission to set flairs in the specified subreddit.

      • The target submission does not belong to the specified subreddit.

    • 404:

      The specified subreddit does not exist.

bulk_set_user_flairs(sr: str, items: Iterable[Tuple[str, str, str]]) CallChunkChainingAsyncIterator[bool][source]#

Bulk set flair information for users.

The second parameter is an iterable of 3-element tuples: (user, text, css_class): the target user name, the flair text, and CSS class to assign.

Parameters:
  • sr (str) –

  • items (Iterable[tuple[str, str, str]]) – An iterable of tuples consisting of (user, text, css_class).

Returns:

For each input item, a boolean appears in the output indicating whether the flair assignment succeeded.

Return type:

CallChunkChainingAsyncIterator[bool]

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:
    • There is no user context.

    • You do not have permission to set flairs in the specified subreddit.

  • 404:

    The specified subreddit does not exist.

async create_user_flair_template(sr: str, *, text: str | None = None, css_class: str | None = None, bg_color: str | None = None, fg_color_scheme: str | None = None, mod_only: bool | None = None, text_editable: bool | None = None, allowable_content: str | None = None, max_emojis: int | None = None) FlairTemplate[source]#

Create a user flair template.

Any previously set flair information will be discarded.

A null argument means the field will not be sent in the request. The API treats this as the same as supplying an empty string.

Parameters:
  • sr (str) –

  • text (Optional[str]) –

  • css_class (Optional[str]) –

  • bg_color (Optional[str]) –

    A 6-digit rgb hex color with an optional hash at the start. E.g. #fb8559.

    For user flair templates, the background color can be unset, making it transparent. (Post flairs cannot be transparent.)

    Effective default: empty string. It will be transparent.

  • fg_color_scheme (Optional[str]) –

    Either dark or light.

    Effective default: dark.

  • mod_only (Optional[bool]) –

    Whether flair is only available for mods to select.

    Effective default: false.

  • text_editable (Optional[bool]) –

    Whether users will be able to edit their flair text.

    Effective default: false.

  • allowable_content (Optional[str]) –

    Either: all, emoji, text.

    Effective default: all.

  • max_emojis (Optional[int]) –

    An integer from 1 to 10.

    Effective default: 10.

Returns:

The newly created flair template.

Return type:

FlairTemplate

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:
    • There is no user context.

    • You do not have permission to set flairs in the specified subreddit.

  • 404:

    The specified subreddit does not exist.

async create_post_flair_template(sr: str, *, text: str | None = None, css_class: str | None = None, bg_color: str | None = None, fg_color_scheme: str | None = None, mod_only: bool | None = None, text_editable: bool | None = None, allowable_content: str | None = None, max_emojis: int | None = None) FlairTemplate[source]#

Create a post flair template.

Behaves similarly to create_user_flair_template().

(parameters):

Same as create_user_flair_template(), but bg_color effective default is different.

Parameters:

bg_color (Optional[str]) – Effective default: #d3d6da.

(returns):

Same as create_user_flair_template().

(raises):

Same as create_user_flair_template().

async update_user_flair_template(sr: str, uuid: str, *, text: str | None = None, css_class: str | None = None, bg_color: str | None = None, fg_color_scheme: str | None = None, mod_only: bool | None = None, text_editable: bool | None = None, allowable_content: str | None = None, max_emojis: int | None = None) FlairTemplate[source]#

Update a user flair template.

Behaves similarly to create_user_flair_template().

(parameters):

Similar to create_user_flair_template().

Parameters:

uuid (str) – The flair template UUID.

async update_post_flair_template(sr: str, uuid: str, *, text: str | None = None, css_class: str | None = None, bg_color: str | None = None, fg_color_scheme: str | None = None, mod_only: bool | None = None, text_editable: bool | None = None, allowable_content: str | None = None, max_emojis: int | None = None) FlairTemplate[source]#

Update a post flair template.

Behaves similarly to update_user_flair_template().

async delete_flair_template(sr: str, uuid: str) None[source]#

Delete a user or post flair template.

Parameters:
  • sr (str) –

  • uuid (str) –

Return type:

None

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:
    • There is no user context.

    • You do not have permission.

  • 404:
    • The specified subreddit does not exist.

    • The specified flair UUID does not exist.

async delete_all_user_flair_templates(sr: str) None[source]#

Delete all user flair templates in a subreddit.

Parameters:

sr (str) –

Return type:

None

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:
    • There is no user context.

    • You do not have permission.

  • 404:

    The specified subreddit does not exist.

async delete_all_post_flair_templates(sr: str) None[source]#

Delete all post flair templates in a subreddit.

async retrieve_user_flair_templates(sr: str) Sequence[FlairTemplate][source]#

Return a list of available user flair templates in a subreddit.

Current user must be a moderator of the subreddit (otherwise a 403 HTTP error is returned).

For non-mods, there is get_post_flair_choices().

Parameters:

sr (str) –

Return type:

Sequence[FlairTemplate]

Raises:
async retrieve_post_flair_templates(sr: str) Sequence[FlairTemplate][source]#

Return a list of available post flair templates in a subreddit.

Behaves similarly to retrieve_user_flair_templates().

async reorder_user_flair_templates(sr: str, order: Sequence[str]) None[source]#

Reorder user flair templates.

Reorders the flair templates as shown in the UI.

The list must contain every flair UUID, otherwise a 400 HTTP error is returned.

If you duplicate an ID the flair will have multiple references in the UI.

Parameters:
  • sr (str) –

  • order (Sequence[str]) – A list of all flair UUIDs.

Return type:

None

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:

    A flair template ID is missing from the provided list.

  • 500:

    The specified subreddit does not exist.

async reorder_post_flair_templates(sr: str, order: Sequence[str]) None[source]#

Reorder post flair templates.

Behaves similarly to reorder_user_flair_templates().

async assign_user_flair_template(sr: str, user: str, uuid: str, *, text: str | None = None) None[source]#

Assign a user flair template.

Parameters:
  • sr (str) –

  • user (str) –

  • uuid (str) –

  • text (Optional[str]) –

    Custom text to override the template’s text.

    Supply None or empty string to use the template’s text.

Return type:

None

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:
    • The specified flair UUID does not exist.

    • You do not have permission.

  • 404:
    • The specified subreddit does not exist.

    • The specified user does not exist.

async assign_post_flair_template(sr: str, subm: int | str, uuid: str, *, text: str | None = None) None[source]#

Assign a post flair template.

Parameters:
  • sr (str) –

  • user (str) –

  • uuid (str) –

  • text (Optional[str]) –

    Custom text to override the template’s text.

    Supply None or empty string to use the template’s text.

Return type:

None

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:
    • The specified flair UUID does not exist.

    • You do not have permission.

  • 404:
    • The specified subreddit does not exist.

    • The specified submission does not exist.

async assign_user_flair(sr: str, user: str, text: str | None, css_class: str | None = None, *, bg_color: str | None = None, fg_color_scheme: str | None = None) None[source]#

Assign a custom user flair.

This is a newer version of set_user_flair().

Parameters:
  • sr (str) –

  • user (str) –

  • text (Optional[str]) –

  • css_class (Optional[str]) –

  • bg_color (Optional[str]) –

  • fg_color_scheme (Optional[str]) –

Return type:

None

Raises:
async assign_post_flair(sr: str, subm: int | str, text: str | None, css_class: str | None = None, *, bg_color: str | None = None, fg_color_scheme: str | None = None) None[source]#

Assign a custom post flair.

This is a newer version of set_user_flair().

Parameters:
  • sr (str) –

  • subm (Union[int, str]) –

  • text (Optional[str]) –

  • css_class (Optional[str]) –

  • bg_color (Optional[str]) –

  • fg_color_scheme (Optional[str]) –

Return type:

None

Raises:
async configure_subreddit_flair_settings(sr: str, *, user_enabled: bool | None = False, user_position: str | None = '', user_self_assign: bool | None = False, post_position: str | None = '', post_self_assign: bool | None = False) None[source]#

Configure subreddit flair settings.

All parameters should be specified. If a parameter is not specified or is an invalid value, its default will be used.

User flairs are disabled when either user_enabled is false or user_position is an empty string.

Post flairs are disabled when post_position is an empty string.

Parameters:
  • sr (str) –

  • user_enabled (Optional[bool]) –

    Whether user flairs are enabled in the subreddit.

    Effective default: false.

  • user_position (Optional[str]) –

    Either left, right, or empty string.

    An empty string value will disable user flairs even if user_enabled is true.

    Effective default: empty string.

  • user_self_assign (Optional[bool]) –

    Whether users are allowed to assign their own user flairs.

    Value is forced false if user_enabled is false (but not if user_position is an empty string).

    Effective default: false.

  • post_position (Optional[str]) –

    Either left, right, or empty string.

    Effective default: empty string.

  • post_self_assign (Optional[bool]) –

    Whether users are allowed to assign their own post flairs.

    Value is forced false if post_position is an empty string.

    Effective default: false.

Return type:

None

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 403:

    You do not have permission.

  • 404:

    The specified subreddit does not exist.

async get_user_flair_template_choices(sr: str) FlairTemplateChoices[source]#

Get user flair template choices.

Parameters:

sr (str) –

Returns:

FlairTemplateChoices, a Sequence[FlairTemplateChoice]

Return type:

FlairTemplateChoices

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 302:

    There is no user context.

  • 404:

    The specified subreddit does not exist.

async get_post_flair_template_choices(sr: str) FlairTemplateChoices[source]#

Get user flair template choices.

Behaves similarly to get_user_flair_template_choices().

async get_user_flair_association(sr: str, user: str) UserFlairAssociation | None[source]#

Get a user flair association in a subreddit.

Parameters:
  • sr (str) –

  • user (str) –

Return type:

Optional[UserFlairAssociation]

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 302:

    The specified subreddit does not exist.

  • 403:
    • There is no user context.

    • You are not a moderator of the subreddit.

get_user_flair_associations(sr: str, amount: int | None = None) ImpartedPaginatorChainingAsyncIterator[UserFlairAssociationAsyncPaginator, UserFlairAssociation][source]#

Get a user flair associations in a subreddit.

Parameters:
  • sr (str) –

  • user (str) –

Return type:

ImpartedPaginatorChainingAsyncIterator[UserFlairAssociationAsyncPaginator, UserFlairAssociation]

Raises:

redditwarp.http.exceptions.StatusCodeException

  • 302:

    The specified subreddit does not exist.

  • 403:
    • There is no user context.

    • You are not a moderator of the subreddit.

async show_my_flair(sr: str) None[source]#

Show the current user’s flair in the subreddit.

To tell if the current user’s flair is shown:

subr = await client.p.subreddit.fetch_by_name('Python')
print(subr.me.flair.shown)
Parameters:

sr (str) –

Return type:

None

Raises:
async hide_my_flair(sr: str) None[source]#

Hide the current user’s flair in the subreddit.

class PostAppearance(outer: FlairProcedures)[source]#

Bases: object

async obtain_thumbnail_upload_lease(*, sr: str, uuid: str, filepath: str, mimetype: str | None = None) UploadLease[source]#
async obtain_background_upload_lease(*, sr: str, uuid: str, filepath: str, mimetype: str | None = None) UploadLease[source]#
async deposit_file(file: IO[bytes], upload_lease: UploadLease, *, timeout: float = 1000) None[source]#
class ObtainUploadLeaseFunction(*args, **kwargs)[source]#

Bases: Protocol

async upload_thumbnail(file: IO[bytes], *, sr: str, uuid: str, filepath: str | None = None, timeout: float = 1000) UploadLease[source]#
async upload_background(file: IO[bytes], *, sr: str, uuid: str, filepath: str | None = None, timeout: float = 1000) UploadLease[source]#
async config(sr: str, uuid: str, *, title_color: str | None = '', background_color: str | None = '', thumbnail_image_url: str | None = '', background_image_url: str | None = '') None[source]#

Configure a post flair’s post appearance settings.

All parameters should be specified. If a parameter is not specified or is an invalid value, its default will be used.

Parameters:
  • title_color (Optional[str]) –

    A hex color.

    The default value will be used if an empty string or any other invalid value is specified.

    Default: #222222.

  • background_color (Optional[str]) –

    A hex color.

    The default value will be used if an empty string or any other invalid value is specified.

    Default: #FFFFFF.

  • thumbnail_image_url (Optional[str]) –

    The URL location of a thumbnail image.

    Specify an empty string to remove the image.

  • background_image_url (Optional[str]) –

    The URL location of a background image.

    Specify an empty string to remove the image.

Return type:

None

Raises:

redditwarp.exceptions.RedditError

  • USER_REQUIRED:

    There is no user context.

property post_appearance: None#

When you edit a post flair template (through the new Reddit UI), there is a toggle at the bottom of the menu that says “Edit post appearance”. The methods on this object relate to these settings.

The important method is config().