From 6225ace7e3fffe7b7b7ca5025ea3891e44e5056b Mon Sep 17 00:00:00 2001 From: Midgard Date: Fri, 22 Nov 2024 23:01:10 +0100 Subject: [PATCH] Add listcustomemoji --- mmcli/mmcli.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mmcli/mmcli.py b/mmcli/mmcli.py index fb9e834..bd5c89e 100755 --- a/mmcli/mmcli.py +++ b/mmcli/mmcli.py @@ -434,6 +434,31 @@ def removereaction(mm_api: mattermost.MMApi, cmdline_args): mm_api._delete(f"/v4/users/me/posts/{cmdline_args.msgid}/reactions/{cmdline_args.emoji_name}") +def str_for_emoji(emoji, cmdline_args): + obj = { + k: v + for k, v in emoji.items() + if (v or k == "name") and (k != "update_at" or emoji["update_at"] != emoji["create_at"]) + } + + if cmdline_args.format == "json": + return json.dumps(emoji) + if cmdline_args.format == "tsv": + name = tsv_escape(emoji.get("name", "")) + return f"{emoji['id']}\t{name}" + +def listcustomemoji(mm_api: mattermost.MMApi, cmdline_args): + page = 0 + per_page = 200 # Maximum allowed in API + response = [] + while page == 0 or response: + response = mm_api._get(f"/v4/emoji?page={page}&per_page={per_page}&sort=name") + for emoji in response: + print(str_for_emoji(emoji, cmdline_args)) + page += 1 + + + def status(mm_api: mattermost.MMApi, cmdline_args): if not cmdline_args.status: raise ValueError("No status selected") @@ -521,6 +546,7 @@ ACTIONS = { "edit": {"function": edit}, "addreaction": {"function": addreaction}, "removereaction": {"function": removereaction}, + "listcustomemoji": {"function": listcustomemoji}, "status": {"function": status}, "customstatus": {"function": customstatus}, "lastread": {"function": lastread}, @@ -632,6 +658,8 @@ The input format accepted on stdin is one JSON object per line. The possible fie parser_removereaction.add_argument("msgid", help="ID of message") parser_removereaction.add_argument("emoji_name", help="name of the emoji to remove (without colons)") + parser_listcustomemoji = subparsers.add_parser("listcustomemoji", help="list all custom emoji on the server") + parser_status = subparsers.add_parser("status", help="update user status") parser_status.add_argument("--online", dest="status", action="store_const", const="online", help="Set status to online") parser_status.add_argument("--away", dest="status", action="store_const", const="away", help="Set status to away")