Texas Hold'em
A commonly seen poker game
The entire game consists of 4 different commands, each of which processes different tasks.
Since the words in this command is too many (the number exceeds 10000), you need to delete the comments ({{/* ... */}}
and {{- /* ... */ -}}
) or just copy the comment-free code below here. Do not change anything if you don't know what it means.
Main Command
Trigger type: Regex
Trigger: (?i)\A-(texas)\s*
Case sensitive: NO
Main Command (with comments)
{{/* Variables */}}
{{/* The "a" "b" "c" "d" stand for "club", "square", "heart", and "spade" */}}
{{$list := shuffle (cslice
"aA" "bA" "cA" "dA"
"a2" "b2" "c2" "d2"
"a3" "b3" "c3" "d3"
"a4" "b4" "c4" "d4"
"a5" "b5" "c5" "d5"
"a6" "b6" "c6" "d6"
"a7" "b7" "c7" "d7"
"a8" "b8" "c8" "d8"
"a9" "b9" "c9" "d9"
"a10" "b10" "c10" "d10"
"aJ" "bJ" "cJ" "dJ"
"aQ" "bQ" "cQ" "dQ"
"aK" "bK" "cK" "dK"
)}}
{{$symbol := sdict
"a" "<:club:850392281679659018>"
"b" "<:diamond:850392281744015361>"
"c" "<:heart:850392281668124683>"
"d" "<:spade:850392281852018748>"
}}
{{$valid := 1}} {{/* Whether the game is still valid or not */}}
{{$cc := .CCID}}
{{$cd := 10}}
{{$data := sdict}}
{{$db := (dbGet 0 "Texas Hold'em").Value}}
{{if .ExecData}} {{/* If someone starts the game, after a set period, the game will start */}}
{{/* In-game variables */}}
{{$data = sdict $db}}
{{$player := sdict (or $data.player sdict)}} {{/* Player data */}}
{{$sign := $data.sign}} {{/* This represents the state of the game */}}
{{$id := or $data.id 0}} {{/* Message ID */}}
{{$desc := or $data.desc ""}} {{/* Message (embed) description */}}
{{$list := $data.list}} {{/* The shuffled card table ($list) */}}
{{$indexFrom := $data.indexFrom}} {{/* the position to index on the shuffled card table ($list) */}}
{{$table := $data.table}} {{/* The cards shown on the game table */}}
{{$bet := $data.bet}} {{/* Players' bet */}}
{{$highest_add := toInt $data.highestAdd}} {{/* The highest additional bet in the last round */}}
{{$record := or $data.record "Nothing."}} {{/* This shows what happened in the last round */}}
{{$playerBet := $data.playerBet}} {{/* This shows how much each player bets */}}
{{$card := ""}} {{/* The new card drawn in this round */}}
{{/* Pre-process something */}}
{{/* If the state is 2, 4, 6, or 8, renew the amount of the bet */}}
{{if eq $sign 2 4 6 8}}
{{$bet = add $bet $highest_add}}
{{end}}
{{/* In-game process */}}
{{if eq $sign 1}} {{/* Execute right after the game registration time ends */}}
{{if gt (len $player) 1}} {{/* There are at least 2 players */}}
{{$id = sendMessageRetID nil (complexMessage
"content" "You have **10 seconds** to bet more (`+<amount>`) or quit the game (`+quit`)."
"embed" (cembed
"title" "Texas Hold'em"
"description" "[?] [?] [?] [?] [?]"
"footer" (sdict "text" "🎲 ~ game in progress")
"color" 0x787878)
)}}
{{else}} {{/* The number of players isn't enough */}}
{{$valid = 0}}
{{print "The number of players isn't enough (`2`)"}}
{{end}}
{{else if not $player}} {{/* When everybody lefts during the game, this part will be executed */}}
{{$valid = 0}}
{{sendMessage nil (cembed
"title" "Texas Hold'em"
"description" "The game ends because everyone quits."
"fields" (cslice (sdict "name" "Record" "value" $record))
"color" 0x787878
)}}
{{else if eq (len $player) 1}} {{/* When everybody lefts except for someone, this part will be executed (the remaining person will be the winner) */}}
{{$cc = 32}}
{{$cd = 0}}
{{else if eq $sign 3}} {{/* 3 cards will be drawn in this round */}}
{{- range seq $indexFrom (add $indexFrom 3) -}}
{{- $card = print $card (index $list .) -}}
{{- end -}}
{{$cd = 20}}
{{else if eq $sign 5 7}} {{/* 1 card will be drawn in this round */}}
{{$card = index $list $indexFrom}}
{{else if eq $sign 9}} {{/* This part will be executed when the game ends and there are still at least 2 players remaining */}}
{{$result := sdict}} {{/* This variable saves the game result */}}
{{/* The hardest and the most important part of the command and the game */}}
{{- range $k, $v := $player -}} {{- /* range through every player's data */ -}}
{{- /* Categorize the cards and transform the cards to numbers in order to compare them */ -}}
{{- $temp := reFindAllSubmatches `(a|b|c|d)([2-9]|10|A|J|Q|K)` (print (index $v 1) " " $table) -}}
{{- $card := cslice -}}
{{- $s := sdict "A" 14 "J" 11 "Q" 12 "K" 13 -}}
{{- range $temp -}}
{{- $num := index . 2 -}}
{{- if eq $num "A" "J" "Q" "K" -}}
{{- $num = $s.Get $num -}}
{{- end -}}
{{- $card = $card.Append (mult 10 $num|add -96 (index . 1 0)) -}}
{{- end -}}
{{- /* Sort the cards from smaller ones to bigger ones with bubble sort method*/ -}}
{{- $sort := cslice -}}
{{- range $card -}}
{{- $temp := 999 -}}
{{- range $card -}}
{{- if and (lt . $temp) (not (in $sort .)) -}}
{{- $temp = . -}}
{{- end -}}
{{- end -}}
{{- $sort = $sort.Append $temp -}}
{{- end -}}
{{- /* Categorize the cards by their numbers for further uses */ -}}
{{- /* Variables */ -}}
{{- $cs := cslice -}}
{{- $ac := cslice 0 $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs -}}
{{- $f := cslice 0 $cs $cs $cs $cs -}}
{{- $flush := $cs -}}
{{- /* Process the cards */ -}}
{{- range $sort -}}
{{- $an := div . 10 -}} {{- /* The number of the card */ -}}
{{- $as := toInt (mod . 10) -}} {{- /* The symbol of the card */ -}}
{{- /* Categorize the cards */ -}}
{{- $v := (index $ac $an).Append . -}}
{{- $ac.Set $an $v -}}
{{- /* Check whether the player has a flush */ -}}
{{- $v := (index $f $as).Append . -}}
{{- $f.Set $as $v -}}
{{- if ge (len $v) 5 -}}
{{- $flush = $v -}}
{{- end -}}
{{- end -}}
{{- /* Check whether the player has a straight or a straight flush */ -}}
{{- template "process_straight" ($s := sdict "card" $sort) -}}
{{- template "process_straight" ($sf := sdict "card" $flush) -}}
{{- /* Score stuff variables */ -}}
{{- $score := 0 -}}
{{- $e := "" -}} {{- /* When the players' card forms are the same, the extra determining cards will be saved here */ -}}
{{- /* Calculate the scores */ -}}
{{- if $sf.hasS -}} {{- /* Straight flush */ -}}
{{- $score = add 1600 $sf.num -}}
{{- else if $flush -}} {{- /* Flush */ -}}
{{- $num := index $flush (sub (len $flush) 1) -}}
{{- $score = add 1000 $num -}}
{{- else if $s.hasS -}} {{- /* Straight */ -}}
{{- $score = add 800 $s.num -}}
{{- end -}}
{{- /* Pair stuff variables */ -}}
{{- /* Here we process pair stuff in a special way. We will only save the cards when they can get the highest score */ -}}
{{- /* The priority of the variables: $foat > $toat > $pair > $single */ -}}
{{- $foat := 0 -}} {{- /* Four of a type (kind) */ -}}
{{- $toat := 0 -}} {{- /* Three of a type (kind) */ -}}
{{- $pair := cslice -}} {{- /* Pair(s) */ -}}
{{- $single := cslice -}} {{- /* Random cards remaining */ -}}
{{- /* Start to process the pair stuff */ -}}
{{- range seq 0 13 -}}
{{- $i := sub 14 . -}} {{- /* Index from the biggest number (A, which mostly stands for 14 in this game) */ -}}
{{- $t := index $ac $i -}} {{- /* The cards in the same number */ -}}
{{- $len := len $t -}} {{- /* How many cards are in the same number */ -}}
{{- if eq $len 4 -}} {{- /* Four of a type (kind) */ -}}
{{- $foat = mult 10 $i -}}
{{- else if and (eq $len 3) (not $toat) -}} {{- /* Three of a type (kind), but no four of a type (kind) */ -}}
{{- $toat = mult 10 $i -}}
{{- else if and (eq $len 2 3) (lt (len $pair) 2) -}} {{- /* Pairs. Note that we only save "two" pairs */ -}}
{{- $pair = $pair.Append (index $t (sub $len 1)) -}}
{{- else if eq $len 2 -}} {{- /* When you have three pairs, the third pair will be saved as single numbers */ -}}
{{- $single = $single.AppendSlice (cslice (index $t 1) (index $t 0)) -}}
{{- else if eq $len 1 -}} {{- /* Single numbers */ -}}
{{- $single = $single.Append (index $t 0) -}}
{{- end -}}
{{- end -}}
{{- /* Calculate the scores */ -}}
{{- if $foat -}}
{{- $r := add 1400 $foat -}}
{{- range seq 0 7 -}} {{- /* Find the biggest single number */ -}}
{{- $num := index $sort (sub 6 .) -}}
{{- if and (ne (div $foat 10) (div $num 10)) (not $e) -}}
{{- $e = cslice $num -}}
{{- end -}}
{{- end -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- else if $toat -}}
{{- $r := add 600 $toat -}}
{{- $e = cslice (index $single 0) (index $single 1) -}}
{{- if $pair -}} {{- /* Full house */ -}}
{{- $r = add $r 600 -}}
{{- $e = cslice (index $pair 0) -}}
{{- end -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- else if $pair -}}
{{- $r := add 200 (index $pair 0) -}}
{{- $e = cslice (index $single 0) (index $single 1) (index $single 2) -}} {{- /* Only a pair */ -}}
{{- if ge (len $pair) 2 -}} {{- /* Two pairs */ -}}
{{- $r = add $r 200 -}}
{{- $e = cslice (index $pair 1) (index $single 0) -}}
{{- end -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- else -}}
{{- $r := index $single 0 -}}
{{- $e = cslice (index $single 1) (index $single 2) (index $single 3) (index $single 4) -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- end -}}
{{- /* Save the result */ -}}
{{- $result.Set $k (cslice $score $e) -}}
{{- end -}}
{{$cc = 32}} {{/* Execute a specific command. The value of this variable depends on your command number */}}
{{$cd = 0}}
{{$data.Set "r" $result}}
{{end}}
{{/* In-game process */}}
{{if and $valid (ne $sign 1) (ne (len $player) 1)}}
{{$data.Del "hasAct"}}
{{/* Get the previous message */}}
{{$msg := getMessage nil $id}}
{{$embed := structToSdict (index $msg.Embeds 0)}}
{{$content := ""}}
{{/* In game-process */}}
{{if eq $sign 2 4 6 8}} {{/* Whether you should continue or not */}}
{{$embed.Set "fields" (cslice
(sdict "name" "Current Bet" "value" (str $bet) "inline" false)
(sdict "name" "Record" "value" $record "inline" false))
}}
{{$content = "You have **10 seconds** to decide whether you should continue or not."}}
{{$data.Set "bet" $bet}}
{{$data.Del "record"}}
{{else if eq $sign 3 5 7}} {{/* Draw new cards */}}
{{$table = print $table $card}}
{{$temp := reFindAllSubmatches `(a|b|c|d)([2-9]|10|A|J|Q|K)` $card}}
{{- range $temp -}}
{{- $desc = print $desc ($symbol.Get (index . 1)) (index . 2) " " -}}
{{- end -}}
{{$content = print "You have **" $cd " seconds** to bet more (`+<amount>`) or quit the game (`+quit`)."}}
{{$D := $desc}} {{/* Embed description */}}
{{if eq $sign 5}}
{{$D = print $D "[?]"}}
{{else if eq $sign 3}}
{{$D = print $D "[?] [?]"}}
{{end}}
{{/* Process the data */}}
{{$embed.Set "Description" $D}}
{{$embed.Set "fields" (cslice
(sdict "name" "Current Bet" "value" (str $bet) "inline" false)
)}}
{{$data.Set "desc" $desc}}
{{$data.Set "indexFrom" (add $indexFrom (or (and (eq $sign 3) 3) 1))}}
{{$data.Del "highestAdd"}}
{{$data.Set "table" $table}}
{{end}}
{{/* Send the message & the embed */}}
{{if ne $sign 9}}
{{$id = sendMessageRetID nil (complexMessage "content" $content "embed" (cembed $embed))}}
{{end}}
{{/* Update remaining players' bet */}}
{{if eq $sign 3 5 7 9}}
{{- range $k, $v := $playerBet -}}
{{- if ($player.Get $k) -}}
{{- $playerBet.Set $k $bet -}}
{{- end -}}
{{- end -}}
{{end}}
{{end}}
{{/* Process the data */}}
{{$data.Set "id" $id}}
{{$data.Set "sign" (add $sign 1)}}
{{$data.Del "hasBet"}}
{{else if not $db}} {{/* Someone just starts a new game */}}
{{$bet := 50}}
{{$id := sendMessageRetID nil (cembed
"title" "Texas Hold'em"
"description" "React to <:fus:898294390181736529> to join the game"
"color" 0x787878)}}
{{addMessageReactions nil $id ":fus:898294390181736529"}}
{{$data = sdict "id" $id "bet" $bet "money" 0 "sign" 1 "list" $list "indexFrom" 0}}
{{$cd = 30}}
{{end}}
{{if $valid}} {{/* The game can continue */}}
{{dbSet 0 "Texas Hold'em" $data}}
{{execCC $cc nil $cd $data}}
{{else}} {{/* The game ends in the middle of the process for some reasons */}}
{{dbDel 0 "Texas Hold'em"}}
{{end}}
{{/* Process straight */}}
{{define "process_straight"}}
{{- /* Variables */ -}}
{{- $p_n := 0 -}} {{- /* Previous card number */ -}}
{{- $p_s := 0 -}} {{- /* Previous card symbol */ -}}
{{- $sn := 0 -}} {{- /* Straight. Number */ -}}
{{- $sc := 1 -}} {{- /* Straight. Consecutive numbers count */ -}}
{{- $ss := 0 -}} {{- /* Straight. Symbol */ -}}
{{- $hasS := 0 -}} {{- /* Has a straight or not */ -}}
{{- /* Process the cards */ -}}
{{- range .card -}}
{{- $an := div . 10 -}} {{- /* Current card number */ -}}
{{- $as := toInt (mod . 10) -}} {{- /* Current card symbol */ -}}
{{- if eq (sub $an $p_n) 1 -}} {{- /* Whether the number is consecutive */ -}}
{{- $sc = add $sc 1 -}}
{{- if ge $sc 5 -}} {{- /* Has a straight */ -}}
{{- $hasS = 1 -}}
{{- $sn = $an -}}
{{- $ss = $as -}}
{{- else if and (eq $sc 4) (eq $an 5) -}} {{- /* Special condition set for the straight "1 2 3 4 5" */ -}}
{{- $sn = $an -}}
{{- $ss = $as -}}
{{- end -}}
{{- else if and (eq $sc 4) $sn -}} {{- /* Check whether the player has a straight "1 2 3 4 5" */ -}}
{{- if eq $an 14 -}}
{{- $hasS = 1 -}}
{{- end -}}
{{- else if eq $an $p_n -}} {{- /* If the next card is the same as the previous card */ }}
{{- if and $hasS (eq $sn $an) -}} {{- /* If the player already has a straight, then change the determining symbol to this one */ -}}
{{- $ss = $as -}}
{{- end -}}
{{- else -}} {{- /* The number is not consecutive. Reset the straight. */ -}}
{{- $sc = 1 -}}
{{- end -}}
{{- /* Renew the variables */ -}}
{{- $p_n = $an -}}
{{- $p_s = $as -}}
{{- end -}}
{{- /* Return the values */ -}}
{{- .Set "hasS" $hasS -}}
{{- .Set "num" (add $ss (mult 10 $sn)) -}}
{{end}}
Main Command (pure code)
{{$list := shuffle (cslice
"aA" "bA" "cA" "dA"
"a2" "b2" "c2" "d2"
"a3" "b3" "c3" "d3"
"a4" "b4" "c4" "d4"
"a5" "b5" "c5" "d5"
"a6" "b6" "c6" "d6"
"a7" "b7" "c7" "d7"
"a8" "b8" "c8" "d8"
"a9" "b9" "c9" "d9"
"a10" "b10" "c10" "d10"
"aJ" "bJ" "cJ" "dJ"
"aQ" "bQ" "cQ" "dQ"
"aK" "bK" "cK" "dK"
)}}
{{$symbol := sdict
"a" "<:club:850392281679659018>"
"b" "<:diamond:850392281744015361>"
"c" "<:heart:850392281668124683>"
"d" "<:spade:850392281852018748>"
}}
{{$valid := 1}}
{{$cc := .CCID}}
{{$cd := 10}}
{{$data := sdict}}
{{$db := (dbGet 0 "Texas Hold'em").Value}}
{{if .ExecData}}
{{$data = sdict $db}}
{{$player := sdict (or $data.player sdict)}}
{{$sign := $data.sign}}
{{$id := or $data.id 0}}
{{$desc := or $data.desc ""}}
{{$list := $data.list}}
{{$indexFrom := $data.indexFrom}}
{{$table := $data.table}}
{{$bet := $data.bet}}
{{$highest_add := toInt $data.highestAdd}}
{{$record := or $data.record "Nothing."}}
{{$playerBet := $data.playerBet}}
{{$card := ""}}
{{if eq $sign 2 4 6 8}}
{{$bet = add $bet $highest_add}}
{{end}}
{{if eq $sign 1}}
{{if gt (len $player) 1}}
{{$id = sendMessageRetID nil (complexMessage
"content" "You have **10 seconds** to bet more (`+<amount>`) or quit the game (`+quit`)."
"embed" (cembed
"title" "Texas Hold'em"
"description" "[?] [?] [?] [?] [?]"
"footer" (sdict "text" "🎲 ~ game in progress")
"color" 0x787878)
)}}
{{else}}
{{$valid = 0}}
{{print "The number of players isn't enough (`2`)"}}
{{end}}
{{else if not $player}}
{{$valid = 0}}
{{sendMessage nil (cembed
"title" "Texas Hold'em"
"description" "The game ends because everyone quits."
"fields" (cslice (sdict "name" "Record" "value" $record))
"color" 0x787878
)}}
{{else if eq (len $player) 1}}
{{$cc = 32}}
{{$cd = 0}}
{{else if eq $sign 3}}
{{- range seq $indexFrom (add $indexFrom 3) -}}
{{- $card = print $card (index $list .) -}}
{{- end -}}
{{$cd = 20}}
{{else if eq $sign 5 7}}
{{$card = index $list $indexFrom}}
{{else if eq $sign 9}}
{{$result := sdict}}
{{- range $k, $v := $player -}}
{{- $temp := reFindAllSubmatches `(a|b|c|d)([2-9]|10|A|J|Q|K)` (print (index $v 1) " " $table) -}}
{{- $card := cslice -}}
{{- $s := sdict "A" 14 "J" 11 "Q" 12 "K" 13 -}}
{{- range $temp -}}
{{- $num := index . 2 -}}
{{- if eq $num "A" "J" "Q" "K" -}}
{{- $num = $s.Get $num -}}
{{- end -}}
{{- $card = $card.Append (mult 10 $num|add -96 (index . 1 0)) -}}
{{- end -}}
{{- $sort := cslice -}}
{{- range $card -}}
{{- $temp := 999 -}}
{{- range $card -}}
{{- if and (lt . $temp) (not (in $sort .)) -}}
{{- $temp = . -}}
{{- end -}}
{{- end -}}
{{- $sort = $sort.Append $temp -}}
{{- end -}}
{{- $cs := cslice -}}
{{- $ac := cslice 0 $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs $cs -}}
{{- $f := cslice 0 $cs $cs $cs $cs -}}
{{- $flush := $cs -}}
{{- range $sort -}}
{{- $an := div . 10 -}}
{{- $as := toInt (mod . 10) -}}
{{- $v := (index $ac $an).Append . -}}
{{- $ac.Set $an $v -}}
{{- $v := (index $f $as).Append . -}}
{{- $f.Set $as $v -}}
{{- if ge (len $v) 5 -}}
{{- $flush = $v -}}
{{- end -}}
{{- end -}}
{{- template "process_straight" ($s := sdict "card" $sort) -}}
{{- template "process_straight" ($sf := sdict "card" $flush) -}}
{{- $score := 0 -}}
{{- $e := "" -}}
{{- if $sf.hasS -}}
{{- $score = add 1600 $sf.num -}}
{{- else if $flush -}}
{{- $num := index $flush (sub (len $flush) 1) -}}
{{- $score = add 1000 $num -}}
{{- else if $s.hasS -}}
{{- $score = add 800 $s.num -}}
{{- end -}}
{{- $foat := 0 -}}
{{- $toat := 0 -}}
{{- $pair := cslice -}}
{{- $single := cslice -}}
{{- range seq 0 13 -}}
{{- $i := sub 14 . -}}
{{- $t := index $ac $i -}}
{{- $len := len $t -}}
{{- if eq $len 4 -}}
{{- $foat = mult 10 $i -}}
{{- else if and (eq $len 3) (not $toat) -}}
{{- $toat = mult 10 $i -}}
{{- else if and (eq $len 2 3) (lt (len $pair) 2) -}}
{{- $pair = $pair.Append (index $t (sub $len 1)) -}}
{{- else if eq $len 2 -}}
{{- $single = $single.AppendSlice (cslice (index $t 1) (index $t 0)) -}}
{{- else if eq $len 1 -}}
{{- $single = $single.Append (index $t 0) -}}
{{- end -}}
{{- end -}}
{{- if $foat -}}
{{- $r := add 1400 $foat -}}
{{- range seq 0 7 -}}
{{- $num := index $sort (sub 6 .) -}}
{{- if and (ne (div $foat 10) (div $num 10)) (not $e) -}}
{{- $e = cslice $num -}}
{{- end -}}
{{- end -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- else if $toat -}}
{{- $r := add 600 $toat -}}
{{- $e = cslice (index $single 0) (index $single 1) -}}
{{- if $pair -}}
{{- $r = add $r 600 -}}
{{- $e = cslice (index $pair 0) -}}
{{- end -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- else if $pair -}}
{{- $r := add 200 (index $pair 0) -}}
{{- $e = cslice (index $single 0) (index $single 1) (index $single 2) -}}
{{- if ge (len $pair) 2 -}}
{{- $r = add $r 200 -}}
{{- $e = cslice (index $pair 1) (index $single 0) -}}
{{- end -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- else -}}
{{- $r := index $single 0 -}}
{{- $e = cslice (index $single 1) (index $single 2) (index $single 3) (index $single 4) -}}
{{- if gt $r $score -}}
{{- $score = $r -}}
{{- end -}}
{{- end -}}
{{- $result.Set $k (cslice $score $e) -}}
{{- end -}}
{{$cc = 32}}
{{$cd = 0}}
{{$data.Set "r" $result}}
{{end}}
{{if and $valid (ne $sign 1) (ne (len $player) 1)}}
{{$data.Del "hasAct"}}
{{$msg := getMessage nil $id}}
{{$embed := structToSdict (index $msg.Embeds 0)}}
{{$content := ""}}
{{if eq $sign 2 4 6 8}}
{{$embed.Set "fields" (cslice
(sdict "name" "Current Bet" "value" (str $bet) "inline" false)
(sdict "name" "Record" "value" $record "inline" false))
}}
{{$content = "You have **10 seconds** to decide whether you should continue or not."}}
{{$data.Set "bet" $bet}}
{{$data.Del "record"}}
{{else if eq $sign 3 5 7}}
{{$table = print $table $card}}
{{$temp := reFindAllSubmatches `(a|b|c|d)([2-9]|10|A|J|Q|K)` $card}}
{{- range $temp -}}
{{- $desc = print $desc ($symbol.Get (index . 1)) (index . 2) " " -}}
{{- end -}}
{{$content = print "You have **" $cd " seconds** to bet more (`+<amount>`) or quit the game (`+quit`)."}}
{{$D := $desc}}
{{if eq $sign 5}}
{{$D = print $D "[?]"}}
{{else if eq $sign 3}}
{{$D = print $D "[?] [?]"}}
{{end}}
{{$embed.Set "Description" $D}}
{{$embed.Set "fields" (cslice
(sdict "name" "Current Bet" "value" (str $bet) "inline" false)
)}}
{{$data.Set "desc" $desc}}
{{$data.Set "indexFrom" (add $indexFrom (or (and (eq $sign 3) 3) 1))}}
{{$data.Del "highestAdd"}}
{{$data.Set "table" $table}}
{{end}}
{{if ne $sign 9}}
{{$id = sendMessageRetID nil (complexMessage "content" $content "embed" (cembed $embed))}}
{{end}}
{{if eq $sign 3 5 7 9}}
{{- range $k, $v := $playerBet -}}
{{- if ($player.Get $k) -}}
{{- $playerBet.Set $k $bet -}}
{{- end -}}
{{- end -}}
{{end}}
{{end}}
{{$data.Set "id" $id}}
{{$data.Set "sign" (add $sign 1)}}
{{$data.Del "hasBet"}}
{{else if not $db}}
{{$bet := 50}}
{{$id := sendMessageRetID nil (cembed
"title" "Texas Hold'em"
"description" "React to <:fus:898294390181736529> to join the game"
"color" 0x787878)}}
{{addMessageReactions nil $id ":fus:898294390181736529"}}
{{$data = sdict "id" $id "bet" $bet "money" 0 "sign" 1 "list" $list "indexFrom" 0}}
{{$cd = 30}}
{{end}}
{{if $valid}}
{{dbSet 0 "Texas Hold'em" $data}}
{{execCC $cc nil $cd $data}}
{{else}}
{{dbDel 0 "Texas Hold'em"}}
{{end}}
{{define "process_straight"}}
{{- $p_n := 0 -}}
{{- $p_s := 0 -}}
{{- $sn := 0 -}}
{{- $sc := 1 -}}
{{- $ss := 0 -}}
{{- $hasS := 0 -}}
{{- range .card -}}
{{- $an := div . 10 -}}
{{- $as := toInt (mod . 10) -}}
{{- if eq (sub $an $p_n) 1 -}}
{{- $sc = add $sc 1 -}}
{{- if ge $sc 5 -}}
{{- $hasS = 1 -}}
{{- $sn = $an -}}
{{- $ss = $as -}}
{{- else if and (eq $sc 4) (eq $an 5) -}}
{{- $sn = $an -}}
{{- $ss = $as -}}
{{- end -}}
{{- else if and (eq $sc 4) $sn -}}
{{- if eq $an 14 -}}
{{- $hasS = 1 -}}
{{- end -}}
{{- else if eq $an $p_n -}}
{{- if and $hasS (eq $sn $an) -}}
{{- $ss = $as -}}
{{- end -}}
{{- else -}}
{{- $sc = 1 -}}
{{- end -}}
{{- $p_n = $an -}}
{{- $p_s = $as -}}
{{- end -}}
{{- .Set "hasS" $hasS -}}
{{- .Set "num" (add $ss (mult 10 $sn)) -}}
{{end}}
Registration Command
Trigger type: Reaction Trigger: Added + Removed reactions
{{$reactionID := .Reaction.Emoji.ID}}
{{$donut := (dbGet .User.ID "yag money").Value|toInt}}
{{$basicBet := 50}}
{{$db := sdict (or (dbGet 0 "Texas Hold'em").Value sdict)}}
{{$msgID := toInt $db.id}}
{{$money := toInt $db.money}}
{{$sign := toInt $db.sign}}
{{$player := sdict (or $db.player sdict)}}
{{$list := (cslice).AppendSlice (or $db.list cslice)}}
{{$indexFrom := $db.indexFrom}}
{{$playerBet := or $db.playerBet sdict}}
{{$hasLeft := or $db.hasLeft cslice}}
{{$allCard := or $db.allCard sdict}}
{{$symbol := sdict
"a" "<:club:850392281679659018>"
"b" "<:diamond:850392281744015361>"
"c" "<:heart:850392281668124683>"
"d" "<:spade:850392281852018748>"}}
{{if and $db (eq .Message.ID $msgID) (eq $reactionID 898294390181736529) (eq $sign 1) .ReactionAdded}} {{/* Join the game */}}
{{if le $donut $basicBet}}
{{print "<@" .User.ID "> You don't have enough donut (`" $basicBet "`) to join the game."}}
{{else if (in $hasLeft .User.ID)}}
{{print "<@" .User.ID "> You can't rejoin the game after you leave."}}
{{else}}
{{$card := print (index $list $indexFrom) " | " (index $list (add 1 $indexFrom))}}
{{$indexFrom = add $indexFrom 2}}
{{$temp := reFindAllSubmatches `(a|b|c|d)([2-9]|10|A|J|Q|K)` $card}}
{{$c := ""}}
{{- range $temp -}}
{{- $c = print $c ($symbol.Get (index . 1)) (index . 2) " " -}}
{{- end -}}
{{sendDM (print "Your cards are: " $c)}}
{{$allCard.Set (str .User.ID) $c}}
{{$db.Set "allCard" $allCard}}
{{$player.Set (str .User.ID) (cslice $basicBet $card)}}
{{$db.Set "indexFrom" $indexFrom}}
{{$playerBet.Set (str .User.ID) $basicBet}}
{{$db.Set "playerBet" $playerBet}}
{{print "**" .User.Username "** has joined the game."}}
{{end}}
{{else if and $db (eq .Message.ID $msgID) (eq $reactionID 898294390181736529) (eq $sign 1) (not .ReactionAdded)}} {{/* Leave the game */}}
{{$card := index ($player.Get (str .User.ID)) 1}}
{{$temp := reFindAll `(a|b|c|d)([2-9]|10|A|J|Q|K)` $card}}
{{$list = $list.AppendSlice (cslice (index $temp 0) (index $temp 1))}}
{{$hasLeft = $hasLeft.Append .User.ID}}
{{$allCard.Del (str .User.ID)}}
{{$db.Set "allCard" $allCard}}
{{$db.Set "hasLeft" $hasLeft}}
{{$db.Set "list" $list}}
{{$db.Set "playerBet" $playerBet}}
{{$player.Del (str .User.ID)}}
{{$playerBet.Del (str .User.ID)}}
{{print "**" .User.Username "** has left the game."}}
{{end}}
{{$db.Set "player" $player}}
{{dbSet 0 "Texas Hold'em" $db}}
In-game Action Command
Trigger type: Regex
Trigger: (?i)\A+(\d+|quit)\z
Case sensitive: NO
{{$cmd := index .Args 0|lower}}
{{$donut := (dbGet .User.ID "yag money").Value|toInt}}
{{$db := sdict (or (dbGet 0 "Texas Hold'em").Value sdict)}}
{{$sign := toInt $db.sign}}
{{$highest_add := toInt $db.highestAdd}}
{{$record := or $db.record ""}}
{{$hasAct := (cslice).AppendSlice (or $db.hasAct cslice)}}
{{$ID := .User.ID}}
{{$MAX := 10000}}
{{if and (gt $sign 1) (lt $sign 9) (not (in $hasAct $ID))}}
{{$player := sdict $db.player}}
{{$playerBet := or $db.playerBet sdict}}
{{if and $player ($player.Get (str $ID))}}
{{$player_data := (cslice).AppendSlice ($player.Get (str $ID))}}
{{$bet := $db.bet}}
{{$card := index $player_data 1}}
{{if eq $cmd "+quit"}}
{{$player.Del (str $ID)}}
{{$arg := print "**" .User.Username "** quits the game and loses **" $bet "** donut."}}
{{$record = print $record "\n" $arg}}
{{$a := dbIncr $ID "donut" $bet}}
{{$hasAct = $hasAct.Append $ID}}
{{addReactions ":gg:898294390190116875"}}
{{else if eq $sign 2 4 6 8}}
{{$add := toInt (slice $cmd 1)}}
{{if le $add $MAX}}
{{if lt $donut $add}}
{{print "<@" $ID "> You don't have enough donut."}}
{{addReactions ":yabai:898294390957670410"}}
{{else}}
{{$bet = add $bet $add}}
{{$player.Set (str $ID) (cslice $bet $card)}}
{{$hasAct = $hasAct.Append $ID}}
{{if gt $add $highest_add}}
{{$db.Set "highestAdd" $add}}
{{end}}
{{$record = print $record "\n**" .User.Username "** bets **" $bet "** donut in total"}}
{{addReactions ":oyes:898294390169149470"}}
{{end}}
{{else}}
{{print "<@" $ID "> You can only bet 10000 donut at most."}}
{{addReactions ":yabai:898294390957670410"}}
{{end}}
{{end}}
{{$db.Set "player" $player}}
{{$db.Set "record" $record}}
{{$db.Set "hasAct" $hasAct}}
{{dbSet 0 "Texas Hold'em" $db}}
{{end}}
{{end}}
Result Command
Trigger type: None
{{$data := .ExecData}}
{{$player := $data.player}}
{{$playerBet := $data.playerBet}}
{{$id := $data.id}}
{{$result := $data.r}}
{{$allCard := $data.allCard}}
{{$w := cslice}} {{/* Winner */}}
{{$we := cslice}} {{/* Winner's extra cards (when two players' types of the cards are the same, this will be used) */}}
{{$hs := 0}} {{/* Winner's card type */}}
{{$prize := 0}}
{{$D_winner := ""}} {/* Description about the winner(s) */}}
{{$D_donut := ""}} {{/* Description about the donut */}}
{{if $result}}
{{/* Determine the winner(s) */}}
{{- range $k, $v := $result -}}
{{- $t := index $v 0 -}} {{/* A player's score */}}
{{- $e := index $v 1 -}} {{/* A player's extra cards */}}
{{- if gt $t $hs -}} {{/* The player is the new winner */}}
{{- $w = cslice $k -}}
{{- $we = $e -}}
{{- $hs = $t -}}
{{- else if eq $t $hs -}} {{/* Same score. Compare the extra cards */}}
{{- $s := 1 -}}
{{- range seq 0 (len $e) -}}
{{- if lt (index $e .) (index $we .) -}} {{/* Smaller than the current winner */}}
{{- $s = 0 -}}
{{- else if gt (index $e .) (index $we .) -}} {{/* Bigger than the current winner */}}
{{- $s = 2 -}}
{{- end -}}
{{- end -}}
{{- if eq $s 1 -}} {{/* Still same score. The player is also the winner */}}
{{- $w = $w.Append $k -}}
{{- else if eq $s 2 -}} {{/* The player is the new winner */}}
{{- $w = cslice $k -}}
{{- $we = $e -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{else}} {{/* There is only one player left in the game, so the player is the winner */}}
{{- range $k, $v := $player -}}
{{- $w = cslice $k -}}
{{- end -}}
{{end}}
{{/* Calculate the total prize */}}
{{- range $k, $v := $playerBet -}}
{{- $prize = add $prize $v -}}
{{- $playerBet.Set $k (mult -1 $v) -}}
{{- end -}}
{{/* Calculate the prize that each winner can get */}}
{{$prize = div $prize (len $w)}}
{{/* Add the prize to the winners */}}
{{- range $k, $v := $playerBet -}}
{{- $user := userArg (toInt $k) -}}
{{- if in $w $k -}} {{/* The player is on the winner list */}}
{{- $D_winner = print $D_winner "\n" $user.Username -}}
{{- $v = add $prize $v -}}
{{- end -}}
{{- $s := "+" -}}
{{- if lt $v 0 -}} {{/* The player is not the winner */}}
{{- $s = "" -}}
{{- end -}}
{{- $D_donut = print $D_donut "\n**" $user.Username "**: `" $s $v "` donut." -}}
{{- $a := dbIncr $user.ID "yag money" $v -}}
{{- end -}}
{{$msg := getMessage nil $id}}
{{$embed := structToSdict (index $msg.Embeds 0)}}
{{$D := print "Table:\n" $embed.Description "\nPlayer(s):"}}
{{/* Print the cards */}}
{{- range $k, $v := $allCard -}}
{{- $user := userArg $k -}}
{{- $D = print $D "\n**" $user.Username "**: " $v -}}
{{- end -}}
{{$embed.Set "Title" (print $embed.Title " - Game Result")}}
{{$embed.Set "Description" $D}}
{{$embed.Set "fields" (cslice
(sdict "name" "Winner" "value" $D_winner "inline" false)
(sdict "name" "Prize" "value" $D_donut "inline" false)
)}}
{{$embed.Set "footer" (sdict "text" "☠️ ~ game ends")}}
{{sendMessage nil (cembed $embed)}}
Result Command (pure code)
{{$data := .ExecData}}
{{$player := $data.player}}
{{$playerBet := $data.playerBet}}
{{$id := $data.id}}
{{$result := $data.r}}
{{$allCard := $data.allCard}}
{{$w := cslice}}
{{$we := cslice}}
{{$hs := 0}}
{{$prize := 0}}
{{$D_winner := ""}}
{{$D_donut := ""}}
{{if $result}}
{{- range $k, $v := $result -}}
{{- $t := index $v 0 -}}
{{- $e := index $v 1 -}}
{{- if gt $t $hs -}}
{{- $w = cslice $k -}}
{{- $we = $e -}}
{{- $hs = $t -}}
{{- else if eq $t $hs -}}
{{- $s := 1 -}}
{{- range seq 0 (len $e) -}}
{{- if lt (index $e .) (index $we .) -}}
{{- $s = 0 -}}
{{- else if gt (index $e .) (index $we .) -}}
{{- $s = 2 -}}
{{- end -}}
{{- end -}}
{{- if eq $s 1 -}}
{{- $w = $w.Append $k -}}
{{- else if eq $s 2 -}}
{{- $w = cslice $k -}}
{{- $we = $e -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{else}}
{{- range $k, $v := $player -}}
{{- $w = cslice $k -}}
{{- end -}}
{{end}}
{{- range $k, $v := $playerBet -}}
{{- $prize = add $prize $v -}}
{{- $playerBet.Set $k (mult -1 $v) -}}
{{- end -}}
{{$prize = div $prize (len $w)}}
{{- range $k, $v := $playerBet -}}
{{- $user := userArg (toInt $k) -}}
{{- if in $w $k -}}
{{- $D_winner = print $D_winner "\n" $user.Username -}}
{{- $v = add $prize $v -}}
{{- end -}}
{{- $s := "+" -}}
{{- if lt $v 0 -}}
{{- $s = "" -}}
{{- end -}}
{{- $D_donut = print $D_donut "\n**" $user.Username "**: `" $s $v "` donut." -}}
{{- $a := dbIncr $user.ID "yag money" $v -}}
{{- end -}}
{{$msg := getMessage nil $id}}
{{$embed := structToSdict (index $msg.Embeds 0)}}
{{$D := print "Table:\n" $embed.Description "\nPlayer(s):"}}
{{- range $k, $v := $allCard -}}
{{- $user := userArg $k -}}
{{- $D = print $D "\n**" $user.Username "**: " $v -}}
{{- end -}}
{{$embed.Set "Title" (print $embed.Title " - Game Result")}}
{{$embed.Set "Description" $D}}
{{$embed.Set "fields" (cslice
(sdict "name" "Winner" "value" $D_winner "inline" false)
(sdict "name" "Prize" "value" $D_donut "inline" false)
)}}
{{$embed.Set "footer" (sdict "text" "☠️ ~ game ends")}}
{{sendMessage nil (cembed $embed)}}
Last updated
Was this helpful?