Skip to content

Commit

Permalink
all: use custom language definition for YAGDPB templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jo3-l committed Jul 23, 2024
1 parent 7642e28 commit c016edc
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 163 deletions.
4 changes: 2 additions & 2 deletions content/docs/custom-commands/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ a page to edit it.

A new custom command has the default response:

```go
```yag
Edit this to change the output of the custom command {{.CCID}}!
```

Expand Down Expand Up @@ -195,7 +195,7 @@ need to write that code yourself in the response.

Example:

```go
```yag
{{ if eq .Reaction.Emoji.APIName "😀" "⭐️" }}
This is an allowed reaction!
{{ else if eq .Reaction.Emoji.APIName "🦆" }}
Expand Down
2 changes: 1 addition & 1 deletion content/docs/moderation/moderation-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ based on warning count, you can take advantage of the template scripting within

Example:

```go
```yag
{{/* Number of warnings at which action is to be taken (eg: for action to take place at 4 warnings set threshold to 4) */}}
{{ $threshold := 4 }}
{{ define "punish_check" }}
Expand Down
36 changes: 18 additions & 18 deletions content/docs/reference/custom-command-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ YAGPDB has a built-in random response system for custom commands, but sometimes
certain responses to occur. You can do this by creating a singular response and creating a variable with randInt. Then
use an if else if statement like this to print out your desired output. 

```go
```yag
{{$var := randInt 100}}
{{if lt $var 10}}
Expand All @@ -52,7 +52,7 @@ following:

Trigger type: `Join message in server channel`

```go
```yag
{{if .UsernameHasInvite}}
{{$silent := execAdmin "ban" .User.ID "ad blocked"}}
{{else}}
Expand All @@ -69,7 +69,7 @@ This particular command loops over a cslice and a sdict.

Trigger type: `Command` Trigger: `range`

```go
```yag
{{/* range can iterate over many things, let's start with slice */}}
{{ $slice := cslice "YAGPDB " "is " "cool!" }}
{{/* Here, we range over with 1 argument, meaning the dot will be set to current iteration value */}}
Expand All @@ -89,7 +89,7 @@ your input that you are on. 
Range will work on any kind of slice/array. for example. If we wanted to look for all the entries in our database we can
use range and index through them all in the following. 

```go
```yag
{{$lb := dbTopEntries "%" 100 0}}
{{range $lb}}
{{.UserID}} **:** {{.Key}} **:** {{.Value}}
Expand All @@ -106,7 +106,7 @@ will have to use `dict`.

Trigger type: `Command` Trigger: `dict`

```go
```yag
{{ $dict := dict 0 "foobar" "hello" "world" }}
{{/* Retrieve value with integer key with index */}}
0 - {{ index $dict 0 -}}
Expand All @@ -131,7 +131,7 @@ are:

Trigger type: `Command` Trigger: `send` 

```go
```yag
{{$args := parseArgs 2 "Syntax is <channel> <text>"
(carg "channel" "channel to send to")
(carg "string" "text to send")}}
Expand All @@ -145,7 +145,7 @@ This example consists of two custom commands, and after copy/paste `REPLACE-WITH
actual custom command ID's in your system. This custom command is very complex, uses very many advanced functions, all
it does, constructs a 10 second countdown timer command-system for given starting time.

```go
```yag
{{$args := parseArgs 2 ""
(carg "duration" "countdown-duration")
(carg "string" "countdown-message")}}
Expand All @@ -159,7 +159,7 @@ Second part of the custom commands, here we see, how `data`-part of exeCC was ma
`sdict`and now we are calling those keys with `.ExecData` - for example `.ExecData.MessageID` sets new variable the same
as stated in previous code.

```go
```yag
{{$timeLeft := .ExecData.T.Sub currentTime}}
{{$cntDownMessageHeader := print "Countdown Timer: " .ExecData.Message}}
{{$formattedTimeLeft := humanizeDurationSeconds $timeLeft}}
Expand Down Expand Up @@ -190,7 +190,7 @@ inserted to database begins with "notes\_".

#### Save note

```go
```yag
{{$args := parseArgs 2 ""
(carg "string" "key")
(carg "string" "value")}}
Expand All @@ -201,7 +201,7 @@ Saved `{{$args.Get 0}}` as `{{$args.Get 1}}`

#### Get note

```go
```yag
{{$key := print "notes_" .StrippedMsg}}
{{$note := dbGet .User.ID $key}}
{{if $note}}
Expand All @@ -215,7 +215,7 @@ Note: `{{$strippedKey}}` Created {{humanizeTimeSinceDays $note.CreatedAt}} ago:

#### List user's notes

```go
```yag
{{$notes := dbGetPattern .User.ID "notes_%" 100 0}}
{{range $notes}}
{{- $strippedKey := slice .Key 6 (len .Key)}}
Expand All @@ -230,7 +230,7 @@ You don't have any notes :(
With YAGPDB's database system, you can now add cooldowns to you custom commands. You can either make them global
cooldowns or a per user cooldown.

```go
```yag
{{/* CONFIGURATION HERE CHANGE VALUES AS NEEDED */}}
{{/* 0 for per user, 1 for global */}}
Expand Down Expand Up @@ -271,7 +271,7 @@ Trigger type: `Regex` Trigger: `\A`

`BE SURE TO RESTRICT THE COMMAND TO A SINGLE CHANNEL`&#x20;

```go
```yag
{{/* If you are not doing (no twice msg in a row) or (role assignment for latest user) you can remove counter_user and by extension everything to do with $lastUser*/}}
{{/* First time running command, set up initial values*/}}
Expand Down Expand Up @@ -339,7 +339,7 @@ command take away roles from someone instead of giving them by simply using the

Trigger type: `Command` Trigger: `giveRoleName`

```go
```yag
{{if eq (len .Args) 3}}
{{$allowedRoles := (cslice "Patron" "Quality Patron" "Paypal Donors")}}
{{$role := (index .CmdArgs 1)}}
Expand All @@ -365,7 +365,7 @@ only string keys), `sendMessage`, and `cembed`in action.

Trigger type: `Command` Trigger: `bc`

```go
```yag
{{if eq (len .Args) 3}}
{{$channel := (index .CmdArgs 0)}}
{{$msg:= (joinStr " " (slice .CmdArgs 1))}}
Expand Down Expand Up @@ -398,7 +398,7 @@ custom commands.&#x20;

Trigger type: `Command` Trigger: `avatar`

```go
```yag
{{$ln := (len .Args)}}
{{$sizes := (cslice "16" "32" "64" "128" "256" "512" "1024" "2048" "4096")}}
{{$err1 := "Wrong image size input format! Possible values: 16, 32, 64, 128, 256, 512, 1024, 2048, 4096."}}
Expand Down Expand Up @@ -456,7 +456,7 @@ This command is used to replace suggestion bots. You can adapt it to your needs.

Trigger type: `Command` Trigger: `suggest`

```go
```yag
{{ $channel := 476178740133494784 }} {{/* Replace this with your suggestion channel ID */}}
{{if gt (len .Args) 1}}
Expand Down Expand Up @@ -487,7 +487,7 @@ emote file directly from Discord's database.

Trigger type: `Command` Trigger: `bigemote`

```go
```yag
{{ $matches := reFindAllSubmatches `<(a)?:.*?:(\d+)>` .StrippedMsg }}
{{ if $matches }}
{{ $animated := index $matches 0 1 }}
Expand Down
10 changes: 5 additions & 5 deletions content/docs/reference/custom-embeds.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Embeds in custom commands are a little more difficult. Also, there is no generat

To start off, we'll take a look at this example and break it down:
```go
```yag
{{ $embed := cembed "title" "This is my title" "description" "This is my description." }}
{{ sendMessage nil $embed }}
```
Expand All @@ -115,7 +115,7 @@ To make your code readable, especially for large embeds, **indents** may be used

{{< callout title="Custom Command \"embed\"" >}}

```go
```yag
{{ $advice := execAdmin "advice" }}
{{ $topic := execAdmin "topic" }}
{{ $catfact := execAdmin "catfact" }}
Expand Down Expand Up @@ -165,7 +165,7 @@ is given as integer and you can convert a hex color to it using
Up next, I have added some fields. This is a bit more difficult, but doable if you have understood it once. Let's break
it down in this example:
```go
```yag
"fields" (cslice
(sdict "name" "Title of field 1" "value" "Description of field 1" "inline" false)
(sdict "name" "Title of field 2" "value" "Description of field 2" "inline" false)
Expand All @@ -189,7 +189,7 @@ You can display an image by simply pasting the link to it in the response, or by
Trigger type: command trigger: `imageembed`
```go
```yag
{{ $embed := cembed "image" (sdict "url" "https://i.imgur.com/ttIwOmn.png") }}
{{ sendMessage nil $embed }}
```
Expand Down Expand Up @@ -227,7 +227,7 @@ Simple embeds work with switches, here is a list of them all:

The values for simple embeds need to bet placed within quotes:

```go
```yag
-se -title "This is my title" -desc "This is my description" -thumbnail "https://via.placeholder.com/300/"
```

Expand Down
Loading

0 comments on commit c016edc

Please sign in to comment.