User:SnpoSuwan/YAGPDB link

From sona pona, the Toki Pona wiki

The following function is for creating links to sona pona using the wikitext syntax. It was created by waso Keli for the YAGPDB Discord bot.

Install

  • Go to the YAGPDB dashboard.
  • Authorise its access to your account.
  • In the dashboard, go to "Custom commands" > "Commands" > "Create a new Custom Command".
  • Change the trigger type to "Regex" and set the trigger to \[\[.+\]\] and case-sensitive.
  • Paste the code below into "Response", then save.

Code

{{/*   Trigger type:   Regex        */}}
{{/*   Trigger:        \[\[.+\]\]   */}}

{{ $bracketed_phrases := reFindAll `\[\[([^\]]*)\]\]` .Cmd }}
{{ range $bracketed_phrases -}}
  {{/* trim leading "[[" and trailing "]]" */}}
  {{- $wiki_link := slice .
     2
     (sub (len .) 2)
  }}
  {{- $wiki_link = reReplace " " $wiki_link "_" }}
  {{- $wiki_link = urlescape $wiki_link }}
  {{- $wiki_link = joinStr "" "https://sona.pona.la/wiki/" $wiki_link "\n" }}
  {{- $wiki_link = reReplace "%23" $wiki_link "#" }}
  {{- $wiki_link }}
{{- end }}

{{/* tan waso */}}