X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Femoji.ex;h=513fb59f8fc3aceb3028187935d12d8d61d54828;hb=e87cca97e62d8464c87c7335741f54c2299cc0d6;hp=bafad2ae9fa915a947ed24fae8cf2f8c57e6e3a2;hpb=c54ae662dcc08c0c04a1dff7bb7a361665e877b8;p=akkoma
diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex
index bafad2ae9..513fb59f8 100644
--- a/lib/pleroma/emoji.ex
+++ b/lib/pleroma/emoji.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emoji do
@@ -56,6 +56,9 @@ defmodule Pleroma.Emoji do
end
end
+ @spec exist?(String.t()) :: boolean()
+ def exist?(name), do: not is_nil(get(name))
+
@doc "Returns all the emojos!!"
@spec get_all() :: list({String.t(), String.t(), String.t()})
def get_all do
@@ -98,4 +101,40 @@ defmodule Pleroma.Emoji do
defp update_emojis(emojis) do
:ets.insert(@ets, emojis)
end
+
+ @external_resource "lib/pleroma/emoji-test.txt"
+
+ regional_indicators =
+ Enum.map(127_462..127_487, fn codepoint ->
+ <>
+ end)
+
+ emojis =
+ @external_resource
+ |> File.read!()
+ |> String.split("\n")
+ |> Enum.filter(fn line ->
+ line != "" and not String.starts_with?(line, "#") and
+ String.contains?(line, "fully-qualified")
+ end)
+ |> Enum.map(fn line ->
+ line
+ |> String.split(";", parts: 2)
+ |> hd()
+ |> String.trim()
+ |> String.split()
+ |> Enum.map(fn codepoint ->
+ <>
+ end)
+ |> Enum.join()
+ end)
+ |> Enum.uniq()
+
+ emojis = emojis ++ regional_indicators
+
+ for emoji <- emojis do
+ def is_unicode_emoji?(unquote(emoji)), do: true
+ end
+
+ def is_unicode_emoji?(_), do: false
end