Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Feb 6, 2025
1 parent 2e96d61 commit cc06597
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions toot/cli/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from toot.tui.constants import VISIBILITY_OPTIONS # move to top-level ?

from toot.cli.validators import validate_duration, validate_language
from toot.entities import MediaAttachment, from_dict
from toot.entities import MediaAttachment, Status, from_dict, from_response
from toot.utils import EOF_KEY, delete_tmp_status_file, editor_input, multiline_input
from toot.utils.datetime import parse_datetime

Expand Down Expand Up @@ -121,6 +121,21 @@
type=AccountParamType(),
help="The account to use, overrides the active account.",
)
@click.option(
"-q",
"--quote-author",
help="When replying to a status, prepend the author's username to the start of the message",
is_flag=True,
default=False,
)
@click.option(
"-Q",
"--quote-all",
help="""When replying to a status, prepend the author's username and the
username of all mentioned accounts to the start of the message""",
is_flag=True,
default=False,
)
@json_option
@pass_context
def post(
Expand All @@ -133,6 +148,9 @@ def post(
sensitive: bool,
spoiler_text: Optional[str],
reply_to: Optional[str],
reply_last: bool,
quote_author: bool,
quote_all: bool,
language: Optional[str],
editor: Optional[str],
scheduled_at: Optional[str],
Expand All @@ -144,7 +162,6 @@ def post(
poll_hide_totals: bool,
json: bool,
using: str,
reply_last: bool,
):
"""Post a new status"""
if len(media) > 4:
Expand All @@ -159,12 +176,14 @@ def post(

media_ids = _upload_media(app, user, media, descriptions, thumbnails)
status_text = _get_status_text(text, editor, media)
scheduled_at = _get_scheduled_at(scheduled_at, scheduled_in)
reply_to = _get_reply_to(app, user, reply_to, reply_last)

if not status_text and not media_ids:
raise click.ClickException("You must specify either text or media to post.")

reply_to_id = _get_reply_to(app, user, reply_to, reply_last)
scheduled_at = _get_scheduled_at(scheduled_at, scheduled_in)
status_text = _prepend_quoted_accounts(app, user, status_text, reply_to_id, quote_author, quote_all)

response = api.post_status(
app,
user,
Expand All @@ -173,7 +192,7 @@ def post(
media_ids=media_ids,
sensitive=sensitive,
spoiler_text=spoiler_text,
in_reply_to_id=reply_to,
in_reply_to_id=reply_to_id,
language=language,
scheduled_at=scheduled_at,
content_type=content_type,
Expand Down Expand Up @@ -245,6 +264,20 @@ def _get_status_text(text, editor, media):
return text


def _prepend_quoted_accounts(app, user, status_text, reply_to_id, quote_author, quote_all):
if not reply_to_id or not (quote_author and quote_all):
return status_text

response = api.fetch_status(app, user, reply_to_id)
response.raise_for_status()
status = from_response(Status, response)

quotes = [status.account.acct]
if quote_all:
quotes += [m.acct for m in status.mentions]
return " ".join(f"@{q}" for q in quotes) + " " + status_text


def _get_scheduled_at(scheduled_at, scheduled_in):
if scheduled_at:
return scheduled_at
Expand Down

0 comments on commit cc06597

Please # to comment.