Implement emoji list
This commit is contained in:
parent
c242176d92
commit
9812075688
3 changed files with 62 additions and 9 deletions
|
@ -316,6 +316,11 @@ def reblogged_by(app, user, status_id) -> Response:
|
||||||
return http.get(app, user, url)
|
return http.get(app, user, url)
|
||||||
|
|
||||||
|
|
||||||
|
def list_emoji(app, user) -> Response:
|
||||||
|
url = "/api/v1/pleroma/emoji"
|
||||||
|
return http.get(app, user, url)
|
||||||
|
|
||||||
|
|
||||||
def _get_next_path(headers):
|
def _get_next_path(headers):
|
||||||
"""Given timeline response headers, returns the path to the next batch"""
|
"""Given timeline response headers, returns the path to the next batch"""
|
||||||
links = headers.get('Link', '')
|
links = headers.get('Link', '')
|
||||||
|
|
|
@ -109,17 +109,22 @@ def thread(app, user, args):
|
||||||
reply_to = post["in_reply_to_id"]
|
reply_to = post["in_reply_to_id"]
|
||||||
ancestors_map = {status['id']: status for status in context["ancestors"]}
|
ancestors_map = {status['id']: status for status in context["ancestors"]}
|
||||||
ancestors = []
|
ancestors = []
|
||||||
while reply_to:
|
try:
|
||||||
ancestors.append(ancestors_map[reply_to])
|
while reply_to:
|
||||||
reply_to = ancestors_map[reply_to]['in_reply_to_id']
|
ancestors.append(ancestors_map[reply_to])
|
||||||
ancestors = reversed(ancestors)
|
reply_to = ancestors_map[reply_to]['in_reply_to_id']
|
||||||
|
ancestors = reversed(ancestors)
|
||||||
|
|
||||||
|
descendants = {
|
||||||
|
'status': from_dict(Status, post),
|
||||||
|
'replies': _get_replies_tree(args.status_id, context["descendants"])
|
||||||
|
}
|
||||||
|
except KeyError:
|
||||||
|
print_out('Full thread not available')
|
||||||
|
print_out(f"This post's privacy setting is: <yellow>{post['visibility']}</yellow>")
|
||||||
|
return
|
||||||
print_timeline([from_dict(Status, s) for s in ancestors], padding=1)
|
print_timeline([from_dict(Status, s) for s in ancestors], padding=1)
|
||||||
|
|
||||||
descendants = {
|
|
||||||
'status': from_dict(Status, post),
|
|
||||||
'replies': _get_replies_tree(args.status_id, context["descendants"])
|
|
||||||
}
|
|
||||||
print_tree(descendants)
|
print_tree(descendants)
|
||||||
else:
|
else:
|
||||||
statuses = chain(context["ancestors"], [post], context["descendants"])
|
statuses = chain(context["ancestors"], [post], context["descendants"])
|
||||||
|
@ -363,6 +368,32 @@ def unreact(app, user, args):
|
||||||
print_status(status)
|
print_status(status)
|
||||||
|
|
||||||
|
|
||||||
|
def emojis(app, user, args):
|
||||||
|
response = api.list_emoji(app, user)
|
||||||
|
if args.json:
|
||||||
|
print(response.text)
|
||||||
|
else:
|
||||||
|
emoji_packs = {}
|
||||||
|
for emoji, data in response.json().items():
|
||||||
|
if args.pack:
|
||||||
|
is_in_pack = False
|
||||||
|
for tag in data['tags']:
|
||||||
|
if tag.lstrip('pack:') == args.pack:
|
||||||
|
is_in_pack = True
|
||||||
|
break
|
||||||
|
if not is_in_pack:
|
||||||
|
continue
|
||||||
|
for tag in data['tags']:
|
||||||
|
pack = tag.removeprefix('pack:')
|
||||||
|
if pack not in emoji_packs:
|
||||||
|
emoji_packs[pack] = {}
|
||||||
|
emoji_packs[pack][emoji] = data['image_url']
|
||||||
|
for pack, emojis in emoji_packs.items():
|
||||||
|
print_out('pack:', pack)
|
||||||
|
for emoji, url in emojis.items():
|
||||||
|
print_out(f'\t{emoji}: {url}')
|
||||||
|
|
||||||
|
|
||||||
def bookmarks(app, user, args):
|
def bookmarks(app, user, args):
|
||||||
timeline(app, user, args, api.bookmark_timeline_generator(app, user, limit=args.count))
|
timeline(app, user, args, api.bookmark_timeline_generator(app, user, limit=args.count))
|
||||||
|
|
||||||
|
|
|
@ -883,6 +883,22 @@ LIST_COMMANDS = [
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
INSTANCE_COMMANDS = [
|
||||||
|
Command(
|
||||||
|
name='emojis',
|
||||||
|
description="List emojis in the instance",
|
||||||
|
arguments=[
|
||||||
|
(["-p", "--pack"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "Only show emojis in this pack"
|
||||||
|
}),
|
||||||
|
json_arg,
|
||||||
|
],
|
||||||
|
require_auth=True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
COMMAND_GROUPS = [
|
COMMAND_GROUPS = [
|
||||||
("Authentication", AUTH_COMMANDS),
|
("Authentication", AUTH_COMMANDS),
|
||||||
("TUI", TUI_COMMANDS),
|
("TUI", TUI_COMMANDS),
|
||||||
|
@ -892,6 +908,7 @@ COMMAND_GROUPS = [
|
||||||
("Accounts", ACCOUNTS_COMMANDS),
|
("Accounts", ACCOUNTS_COMMANDS),
|
||||||
("Hashtags", TAG_COMMANDS),
|
("Hashtags", TAG_COMMANDS),
|
||||||
("Lists", LIST_COMMANDS),
|
("Lists", LIST_COMMANDS),
|
||||||
|
("Instance", INSTANCE_COMMANDS),
|
||||||
]
|
]
|
||||||
|
|
||||||
COMMANDS = list(chain(*[commands for _, commands in COMMAND_GROUPS]))
|
COMMANDS = list(chain(*[commands for _, commands in COMMAND_GROUPS]))
|
||||||
|
@ -985,7 +1002,7 @@ def main():
|
||||||
command_name = sys.argv[1] if len(sys.argv) > 1 else None
|
command_name = sys.argv[1] if len(sys.argv) > 1 else None
|
||||||
args = sys.argv[2:]
|
args = sys.argv[2:]
|
||||||
|
|
||||||
if not command_name or command_name == "--help":
|
if not command_name or command_name in ("-h", "--help"):
|
||||||
return print_usage()
|
return print_usage()
|
||||||
|
|
||||||
user, app = config.get_active_user_app()
|
user, app = config.get_active_user_app()
|
||||||
|
|
Loading…
Reference in a new issue