logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

clippy.ex (4363B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Clippy do
  5. @moduledoc false
  6. # No software is complete until they have a Clippy implementation.
  7. # A ballmer peak _may_ be required to change this module.
  8. def tip do
  9. tips()
  10. |> Enum.random()
  11. |> puts()
  12. end
  13. def tips do
  14. host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
  15. [
  16. "“πλήρωμα” is “pleroma” in greek",
  17. "For an extended Pleroma Clippy Experience, use the “Redmond” themes in Pleroma FE settings",
  18. "Staff accounts and MRF policies of Pleroma instances are disclosed on the NodeInfo endpoints for easy transparency!\n
  19. - https://catgirl.science/misc/nodeinfo.lua?#{host}
  20. - https://fediverse.network/#{host}/federation",
  21. "Pleroma can federate to the Dark Web!\n
  22. - Tor: https://git.pleroma.social/pleroma/pleroma/wikis/Easy%20Onion%20Federation%20(Tor)
  23. - i2p: https://git.pleroma.social/pleroma/pleroma/wikis/I2p%20federation",
  24. "Lists of Pleroma instances:\n\n- http://distsn.org/pleroma-instances.html\n- https://fediverse.network/pleroma\n- https://the-federation.info/pleroma",
  25. "Pleroma uses the LitePub protocol - https://litepub.social",
  26. "To receive more federated posts, subscribe to relays!\n
  27. - How-to: https://git.pleroma.social/pleroma/pleroma/wikis/Admin%20tasks#relay-managment
  28. - Relays: https://fediverse.network/activityrelay"
  29. ]
  30. end
  31. @spec puts(String.t() | [[IO.ANSI.ansicode() | String.t(), ...], ...]) :: nil
  32. def puts(text_or_lines) do
  33. import IO.ANSI
  34. lines =
  35. if is_binary(text_or_lines) do
  36. String.split(text_or_lines, ~r/\n/)
  37. else
  38. text_or_lines
  39. end
  40. longest_line_size =
  41. lines
  42. |> Enum.map(&charlist_count_text/1)
  43. |> Enum.sort(&>=/2)
  44. |> List.first()
  45. pad_text = longest_line_size
  46. pad =
  47. for(_ <- 1..pad_text, do: "_")
  48. |> Enum.join("")
  49. pad_spaces =
  50. for(_ <- 1..pad_text, do: " ")
  51. |> Enum.join("")
  52. spaces = " "
  53. pre_lines = [
  54. " / \\#{spaces} _#{pad}___",
  55. " | |#{spaces} / #{pad_spaces} \\"
  56. ]
  57. for l <- pre_lines do
  58. IO.puts(l)
  59. end
  60. clippy_lines = [
  61. " #{bright()}@ @#{reset()}#{spaces} ",
  62. " || ||#{spaces}",
  63. " || || <--",
  64. " |\\_/| ",
  65. " \\___/ "
  66. ]
  67. noclippy_line = " "
  68. env = %{
  69. max_size: pad_text,
  70. pad: pad,
  71. pad_spaces: pad_spaces,
  72. spaces: spaces,
  73. pre_lines: pre_lines,
  74. noclippy_line: noclippy_line
  75. }
  76. # surrond one/five line clippy with blank lines around to not fuck up the layout
  77. #
  78. # yes this fix sucks but it's good enough, have you ever seen a release of windows
  79. # without some butched features anyway?
  80. lines =
  81. if length(lines) == 1 or length(lines) == 5 do
  82. [""] ++ lines ++ [""]
  83. else
  84. lines
  85. end
  86. clippy_line(lines, clippy_lines, env)
  87. rescue
  88. e ->
  89. IO.puts("(Clippy crashed, sorry: #{inspect(e)})")
  90. IO.puts(text_or_lines)
  91. end
  92. defp clippy_line([line | lines], [prefix | clippy_lines], env) do
  93. IO.puts([prefix <> "| ", rpad_line(line, env.max_size)])
  94. clippy_line(lines, clippy_lines, env)
  95. end
  96. # more text lines but clippy's complete
  97. defp clippy_line([line | lines], [], env) do
  98. IO.puts([env.noclippy_line, "| ", rpad_line(line, env.max_size)])
  99. if lines == [] do
  100. IO.puts(env.noclippy_line <> "\\_#{env.pad}___/")
  101. end
  102. clippy_line(lines, [], env)
  103. end
  104. # no more text lines but clippy's not complete
  105. defp clippy_line([], [clippy | clippy_lines], env) do
  106. if env.pad do
  107. IO.puts(clippy <> "\\_#{env.pad}___/")
  108. clippy_line([], clippy_lines, %{env | pad: nil})
  109. else
  110. IO.puts(clippy)
  111. clippy_line([], clippy_lines, env)
  112. end
  113. end
  114. defp clippy_line(_, _, _) do
  115. end
  116. defp rpad_line(line, max) do
  117. pad = max - (charlist_count_text(line) - 2)
  118. pads = Enum.join(for(_ <- 1..pad, do: " "))
  119. [IO.ANSI.format(line), pads <> " |"]
  120. end
  121. defp charlist_count_text(line) do
  122. if is_list(line) do
  123. text = Enum.join(Enum.filter(line, &is_binary/1))
  124. String.length(text)
  125. else
  126. String.length(line)
  127. end
  128. end
  129. end