1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.Emoji do
8 @shortdoc "Manages Pleroma instance"
12 defp fetch_manifest do
13 Tesla.get!("https://git.pleroma.social/vaartis/emoji-index/raw/master/index.json").body
17 def run(["ls-packs"]) do
18 Application.ensure_all_started(:hackney)
20 manifest = fetch_manifest()
22 Enum.each(manifest, fn {name, info} ->
25 {"Homepage", info["homepage"]},
26 {"Description", info["description"]},
27 {"License", info["license"]},
28 {"Source", info["src"]}
31 for {param, value} <- to_print do
32 IO.puts(IO.ANSI.format([:bright, param, :normal, ": ", value]))
37 def run(["get-pack", pack_name]) do
38 Application.ensure_all_started(:hackney)
40 manifest = fetch_manifest()
42 if Map.has_key?(manifest, pack_name) do
43 pack = manifest[pack_name]
58 binary_archive = Tesla.get!(src_url).body
60 IO.puts("Unpacking #{pack_name} pack")
62 static_path = Path.join(:code.priv_dir(:pleroma), "static")
67 Pleroma.Config.get!([:instance, :static_dir]),
75 fn {_, f} -> to_charlist(f) end
79 :zip.unzip(binary_archive,
81 file_list: files_to_unzip
84 IO.puts("Wriring emoji.txt for the #{pack_name} pack")
89 fn {shortcode, path} -> "#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}" end
93 File.write!(Path.join(pack_path, "emoji.txt"), emoji_txt_str)
95 IO.puts(IO.ANSI.format([:bright, :red, "No pack named \"#{pack_name}\" found"]))