-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(blackjack): Add blackjack command * style(blackjack): Mobile support * fix(blackjack): Author icon not displaying on timeout * fix(blackjack): Prevent betting 0 as well as LESS THAN 0 * style(blackjack): Remove mistyped a
- Loading branch information
1 parent
5da5fd1
commit 0032bd9
Showing
4 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Blackjack | ||
|
||
> [!WARNING] | ||
> This feature is not compatibale with the current version of YAGPDB, pending PR [1619](https://github.com/botlabs-gg/yagpdb/pull/1619) it will be | ||
# Info | ||
- Blackjack | ||
- Timeout of 2 minutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
{{/* | ||
Made by ranger_4297 (765316548516380732) | ||
Trigger Type: `Regex` | ||
Trigger: `\A(-|<@!?204255221017214977>\s*)()(\s+|\z)` | ||
©️ RhykerWells 2020-Present | ||
GNU, GPLV3 License | ||
Repository: https://github.com/Ranger-4297/YAGPDB-ccs | ||
*/}} | ||
|
||
|
||
{{/* Only edit below if you know what you're doing (: rawr */}} | ||
|
||
{{/* Initiates variables */}} | ||
{{$userID := .User.ID}} | ||
{{$successColor := 0x00ff7b}} | ||
{{$errorColor := 0xFF0000}} | ||
{{$prefix := .ServerPrefix}} | ||
|
||
{{/* Blackjack */}} | ||
|
||
{{/* Response */}} | ||
{{$embed := sdict "author" (sdict "name" .User.Username "icon_url" (.User.AvatarURL "1024")) "timestamp" currentTime "color" $errorColor}} | ||
{{$economySettings := (dbGet 0 "EconomySettings").Value}} | ||
{{if not $economySettings}} | ||
{{$embed.Set "description" (print "No `Settings` database found.\nPlease set it up with the default values using `" .ServerPrefix "server-set default`")}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{return}} | ||
{{end}} | ||
{{$symbol := $economySettings.symbol}} | ||
{{$betMax := $economySettings.betMax}} | ||
{{if .ExecData}} | ||
{{$data := (dbGet 0 "bj").Value}} | ||
{{$embed := structToSdict (index (getMessage nil $data.embed).Embeds 0) }} | ||
{{range $k, $v := $embed }} | ||
{{- if eq (kindOf $v true) "struct"}} | ||
{{- $embed.Set $k (structToSdict $v)}} | ||
{{- end -}} | ||
{{end}} | ||
{{if $embed.Author}} | ||
{{$embed.Author.Set "Icon_URL" (.User.AvatarURL "1024")}} | ||
{{end}} | ||
{{$embed.Set "description" (print "Loss: " $symbol $data.bet)}} | ||
{{$embed.Set "color" $errorColor}} | ||
{{$components := (cslice (cbutton "label" "Hit" "custom_id" "bj_hit" "style" "primary" "disabled" true) (cbutton "label" "Stand" "custom_id" "bj_stand" "style" "success" "disabled" true) (cbutton "label" "Double Down" "custom_id" "bj_double" "style" "secondary" "disabled" true))}} | ||
{{editMessage nil $data.embed (complexMessageEdit "embed" (cembed $embed) "components" $components)}} | ||
{{return}} | ||
{{end}} | ||
{{if (dbGet 0 "bj")}} | ||
{{$embed.Set "description" (print "There is currently a blackjack game running. Please wait till the dealer isn't busy.")}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{return}} | ||
{{end}} | ||
{{if not .CmdArgs}} | ||
{{$embed.Set "description" (print "No `bet` argument provided.\nSyntax is `" .Cmd " <Bet:Amount>`")}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{return}} | ||
{{end}} | ||
{{$bal := toInt (dbGet $userID "cash").Value}} | ||
{{$bet := index .CmdArgs 0 | str | lower}} | ||
{{if not (or (toInt $bet) (eq $bet "all" "max"))}} | ||
{{$embed.Set "description" (print "Invalid `Bet` argument provided.\nSyntax is `" .Cmd " <Bet:Amount>`")}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{return}} | ||
{{end}} | ||
{{if eq $bet "all"}}{{$bet = $bal}}{{else if eq $bet "max"}}{{$bet = $betMax}}{{end}} | ||
{{if le ($bet = toInt $bet) 0}} | ||
{{$embed.Set "description" (print "Invalid `Bet` argument provided.\nSyntax is `" .Cmd " <Bet:Amount>`")}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{return}} | ||
{{end}} | ||
{{if gt $bet $bal}} | ||
{{$embed.Set "description" (print "You can't bet more than you have!")}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{return}} | ||
{{end}} | ||
{{if gt $bet $betMax}} | ||
{{$embed.Set "description" (print "You can't bet more than " $symbol $betMax)}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{return}} | ||
{{end}} | ||
{{define "cardSetup"}} | ||
{{$availableSuits := cslice "H" "D" "S" "C"}} | ||
{{$availableCards := cslice "A" "2" "3" "4" "5" "6" "7" "8" "9" "10" "J" "Q" "K"}} | ||
{{$return := sdict "player" (sdict "cardValue" 0 "cards" cslice "cardPrint" cslice) "dealer" (sdict "cardValue" 0 "cards" cslice "cardPrint" cslice "cardValueReal" 0 "cardPrintReal" cslice) "used" cslice}} | ||
{{$selectedCards := cslice}} | ||
{{$selectedEmojiCards := cslice}} | ||
{{range 4}} | ||
{{$returnValue := $return.player}}{{if eq . 2}}{{$returnValue = $return.dealer}}{{$selectedCards = cslice}}{{$selectedEmojiCards = cslice}}{{else if eq . 3}}{{$returnValue = $return.dealer}}{{end}} | ||
{{$card := ""}} | ||
{{while or (eq $card "") (in $return.used $card)}} | ||
{{$card = (print (index $availableCards (randInt (len $availableCards))) (index $availableSuits (randInt (len $availableSuits))))}} | ||
{{end}} | ||
{{- $selectedCards = $selectedCards.Append $card -}} | ||
{{$value := $returnValue.cardValue | toInt}} | ||
{{$cardValue := index (split $card "") 0}} | ||
{{if in (cslice "J" "Q" "K" "1") $cardValue}}{{$cardValue = 10}}{{end}} | ||
{{if eq "A" (str $cardValue)}} | ||
{{$cardValue = 11}} | ||
{{if eq . 0 2}} | ||
{{$returnValue.Set "aceStart" true}} | ||
{{end}} | ||
{{if eq (len $selectedCards) 2}} | ||
{{$cardOne := index (split (index $selectedCards 0) "") 0}} | ||
{{$cardTwo := index (split (index $selectedCards 1) "") 0}} | ||
{{if and (eq $cardOne "A") (eq $cardTwo "A")}}{{$cardValue = 1}}{{end}} | ||
{{end}} | ||
{{end}} | ||
{{$value = add $value $cardValue}} | ||
{{$cardGames := (dbGet 0 "cardGames").Value}} | ||
{{$emojiCard := $cardGames.cards.Get $card}} | ||
{{- $selectedEmojiCards = $selectedEmojiCards.Append $emojiCard}} | ||
{{if eq (len $selectedEmojiCards) 2}} | ||
{{$returnValue.Set "cardPrint" (print (index $selectedEmojiCards 0) " " (index $selectedEmojiCards 1))}} | ||
{{end}} | ||
{{if eq . 3}} | ||
{{$returnValue.Set "cardPrintReal" (print (index $selectedEmojiCards 0) " " (index $selectedEmojiCards 1))}} | ||
{{$returnValue.Set "cardValueReal" $value}} | ||
{{$returnValue.Set "cardPrint" (print (index $selectedEmojiCards 0) " " ($cardGames.cards.Get "CB"))}} | ||
{{$value = sub $value $cardValue}} | ||
{{end}} | ||
{{- $returnValue.Set "cards" $selectedCards -}} | ||
{{- $returnValue.Set "cardValue" $value -}} | ||
{{- $return.Set "used" ($return.used.Append $card) -}} | ||
{{end}} | ||
{{return $return}} | ||
{{end}} | ||
{{$bal = sub $bal $bet}} | ||
{{$cardSelection := execTemplate "cardSetup"}} | ||
{{$cardOne := index (split (index $cardSelection.player.cards 0) "") 0}} | ||
{{$cardTwo := index (split (index $cardSelection.player.cards 1) "") 0}} | ||
{{$components := cslice}} | ||
{{$embed.Set "fields" (cslice (sdict "name" "Your hand" "value" (print $cardSelection.player.cardPrint "\nValue: " $cardSelection.player.cardValue) "inline" true) (sdict "name" "Dealers hand" "value" (print $cardSelection.dealer.cardPrint "\nValue: " $cardSelection.dealer.cardValue) "inline" true))}} | ||
{{$dealerValue := $cardSelection.dealer.cardValueReal}} | ||
{{if eq $cardSelection.player.cardValue 21}} | ||
{{if eq $dealerValue 21}} | ||
{{$dealerValue = "Blackjack"}} | ||
{{$embed.Set "description" (print "Result: Push, money back")}} | ||
{{$embed.Set "color" 0xA25D2D}} | ||
{{$bal = add $bal $bet}} | ||
{{else}} | ||
{{$embed.Set "description" (print "Result: Win " $symbol $bet)}} | ||
{{$embed.Set "color" $successColor}} | ||
{{$bal = add $bal (mult $bet 2.5)}} | ||
{{end}} | ||
{{$embed.Set "fields" (cslice (sdict "name" "Your hand" "value" (print $cardSelection.player.cardPrint "\nValue: Blackjack") "inline" true) (sdict "name" "Dealers hand" "value" (print $cardSelection.dealer.cardPrintReal "\nValue: " $dealerValue) "inline" true))}} | ||
{{sendMessage nil (cembed $embed)}} | ||
{{dbSet $userID "cash" $bal}} | ||
{{return}} | ||
{{else}} | ||
{{$desc := print "`hit` - take another card\n`stand` - end your turn"}} | ||
{{$components = cslice (cbutton "label" "Hit" "custom_id" "bj_hit" "style" "primary") (cbutton "label" "Stand" "custom_id" "bj_stand" "style" "success")}} | ||
{{if and (gt $bal $bet)}} | ||
{{$desc = print $desc "\n`double down` - double your bet, hit once and stand"}} | ||
{{$components = $components.Append (cbutton "label" "Double Down" "custom_id" "bj_double" "style" "secondary")}} | ||
{{end}} | ||
{{$embed.Set "description" $desc}} | ||
{{end}} | ||
{{$embed.Set "color" $successColor}} | ||
{{$x := sendMessageRetID nil (complexMessage "embed" (cembed $embed) "components" $components)}} | ||
{{scheduleUniqueCC $.CCID nil 120 "cancel" "bj"}} | ||
{{dbSetExpire $userID "bj" (sdict "embed" $x "player" $cardSelection.player "dealer" $cardSelection.dealer "usedCards" $cardSelection.used "bet" $bet "user" $userID "ccID" .CCID) 125}} | ||
{{dbSet $userID "cash" $bal}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
{{/* | ||
Made by ranger_4297 (765316548516380732) | ||
Trigger Type: `Component` | ||
Trigger: `\Abj_` | ||
©️ RhykerWells 2020-Present | ||
GNU, GPLV3 License | ||
Repository: https://github.com/Ranger-4297/YAGPDB-ccs | ||
*/}} | ||
|
||
|
||
{{/* Only edit below if you know what you're doing (: rawr */}} | ||
|
||
{{/* Initiates variables */}} | ||
{{$userID := .User.ID}} | ||
{{$successColor := 0x00ff7b}} | ||
{{$errorColor := 0xFF0000}} | ||
{{$prefix := .ServerPrefix}} | ||
|
||
{{/* Blackjack component registry */}} | ||
|
||
{{/* Response */}} | ||
{{$data := (dbGet $userID "bj").Value}} | ||
{{if not $data}}{{return}}{{end}} | ||
{{if not (eq $data.user .User.ID)}}{{return}}{{end}} | ||
{{$embed := structToSdict (index (getMessage nil $data.embed).Embeds 0)}}{{range $k, $v := $embed }}{{- if eq (kindOf $v true) "struct"}}{{- $embed.Set $k (structToSdict $v)}}{{- end -}}{{end}} | ||
{{$embed.Author.Set "Icon_URL" (.User.AvatarURL "1024")}} | ||
{{$economySettings := (dbGet 0 "EconomySettings").Value}} | ||
{{if not $economySettings}}{{$embed.Set "description" (print "No `Settings` database found.\nPlease set it up with the default values using `" .ServerPrefix "server-set default`")}}{{sendMessage nil (cembed $embed)}}{{return}}{{end}} | ||
{{$symbol := $economySettings.symbol}} | ||
{{$bal := toInt (dbGet (toInt $userID) "cash").Value}} | ||
{{define "hit"}} | ||
{{$userData := .data.Get .user}} | ||
{{$userCards := $userData.cards}} | ||
{{$userPrintCards := cslice}} | ||
{{$suits := cslice "H" "D" "S" "C"}} | ||
{{$cards := cslice "A" "2" "3" "4" "5" "6" "7" "8" "9" "10" "J" "Q" "K"}} | ||
{{$card := ""}} | ||
{{$used := .data.usedCards}} | ||
{{while or (eq $card "") (in $used $card)}}{{$card = (print (index $cards (randInt (len $cards))) (index $suits (randInt (len $suits))))}}{{end}} | ||
{{$userCards = $userCards.Append $card}} | ||
{{$used = $used.Append $card}} | ||
{{$value := $userData.cardValue | toInt}} | ||
{{$cardValue := index (split $card "") 0}} | ||
{{if eq $cardValue "J" "Q" "K" "1"}}{{$cardValue = 10}}{{end}} | ||
{{if eq "A" (str $cardValue)}}{{$cardValue = 11}}{{end}} | ||
{{if and (eq (toInt $cardValue) 11) (gt (add $value $cardValue) 21)}}{{$cardValue = 1}}{{end}} | ||
{{if and (eq (len $userCards) 3) (or (eq (index (split (index $userCards 0) "") 0) "A") (eq (index (split (index $userCards 1) "") 0) "A"))}}{{$cardValue = sub $cardValue 10}}{{end}} | ||
{{$value = add $value $cardValue}} | ||
{{$emojiCards := (dbGet 0 "cardGames").Value.cards}} | ||
{{range $userCards}}{{$userPrintCards = $userPrintCards.Append ($emojiCards.Get .)}}{{end}} | ||
{{return (sdict "cardValue" $value "cards" $userCards "cardPrint" $userPrintCards "used" $used)}} | ||
{{end}} | ||
{{define "splitHit"}} | ||
{{return .hand}} | ||
{{end}} | ||
{{define "standCondition"}} | ||
{{$embed := structToSdict (index (getMessage nil .data.embed).Embeds 0)}}{{range $k, $v := $embed}}{{- if eq (kindOf $v true) "struct"}}{{- $embed.Set $k (structToSdict $v)}}{{- end -}}{{end}} | ||
{{$playerPrintCards := joinStr " " .data.player.cardPrint}}{{$playerValue := .data.player.cardValue}} | ||
{{$dealerPrintCards := joinStr " " .data.dealer.cardPrint}}{{$dealerValue := .data.dealer.cardValue}} | ||
{{if or (and (eq (len .data.dealer.cards) 3) (eq $dealerValue 21)) (and (lt $playerValue 21) (gt $dealerValue $playerValue) (lt $dealerValue 22))}} | ||
{{$embed.Set "description" (print "Result: Loss -" .symbol .data.bet)}} | ||
{{$embed.Set "color" 0xFF0000}} | ||
{{else if gt $playerValue 21}} | ||
{{$embed.Set "description" (print "Result: Bust -" .symbol .data.bet)}} | ||
{{$embed.Set "color" 0xFF0000}} | ||
{{else if or (gt $dealerValue 21) (and (gt $playerValue $dealerValue ) (lt $playerValue 22))}} | ||
{{$embed.Set "description" (print "Result: Win " .symbol .data.bet)}} | ||
{{dbSet .data.user "cash" (add .bal (mult .data.bet 2))}} | ||
{{else if (eq $dealerValue $playerValue)}} | ||
{{$embed.Set "description" (print "Result: Push, money back")}} | ||
{{$embed.Set "color" 0xA25D2D}} | ||
{{dbSet .data.user "cash" (add .bal .data.bet)}} | ||
{{end}} | ||
{{$embed.Set "fields" (cslice (sdict "name" "Your hand" "value" (print $playerPrintCards "\nValue: " $playerValue) "inline" true) (sdict "name" "Dealers hand" "value" (print $dealerPrintCards "\nValue: " (reReplace `21` (str $dealerValue) "Blackjack")) "inline" true))}} | ||
{{updateMessage (complexMessageEdit "embed" (cembed $embed))}} | ||
{{cancelScheduledUniqueCC .data.ccID "cancel"}}{{dbDel .data.user "bj"}} | ||
{{return}} | ||
{{end}} | ||
{{if eq .StrippedID "hit"}} | ||
{{$hit := execTemplate "hit" (sdict "data" $data "user" "player")}} | ||
{{$player := $data.player}}{{$data.Set "usedCards" $hit.Used}}{{$hit.Del "used"}}{{$player = $hit}}{{$data.Set "player" $player}} | ||
{{$playerPrintCards := joinStr " " $data.player.cardPrint}} | ||
{{$embed.Set "fields" (cslice (sdict "name" "Your hand" "value" (print $playerPrintCards "\nValue: " $data.player.cardValue) "inline" true) (sdict "name" "Dealers hand" "value" (print $data.dealer.cardPrint "\nValue: " $data.dealer.cardValue) "inline" true))}} | ||
{{if eq $hit.cardValue 21}} | ||
{{$dealer := $data.dealer}} | ||
{{$value := $dealer.cardValue | toInt}} | ||
{{$data.dealer.Set "cardValue" $data.dealer.cardValueReal}}{{$data.dealer.Del "cardValueReal"}}{{$data.dealer.Set "cardPrint" $data.dealer.cardPrintReal}}{{$data.dealer.Del "cardPrintReal"}} | ||
{{while le $value 17}}{{$hit = execTemplate "hit" (sdict "data" $data "user" "dealer")}}{{$data.Set "usedCards" $hit.Used}}{{$hit.Del "used"}}{{$dealer = $hit}}{{$data.Set "dealer" $dealer}}{{$value = add $value $hit.cardValue}}{{end}} | ||
{{$dealerPrintCards := joinStr " " $data.dealer.cardPrint}} | ||
{{$embed.Set "description" (print "Result: Win " $symbol $data.bet)}} | ||
{{$embed.Set "fields" (cslice (sdict "name" "Your hand" "value" (print $playerPrintCards "\nValue: " $data.player.cardValue) "inline" true) (sdict "name" "Dealers hand" "value" (print $dealerPrintCards "\nValue: " $data.dealer.cardValue) "inline" true))}} | ||
{{updateMessage (complexMessageEdit "embed" (cembed $embed))}} | ||
{{cancelScheduledUniqueCC $data.ccID "cancel"}}{{dbDel $userID "bj"}}{{dbSet $data.user "cash" (add .bal (mult .data.bet 2))}} | ||
{{return}} | ||
{{else if gt $hit.cardValue 21}} | ||
{{$embed.Set "description" (print "Result: bust -" $symbol $data.bet)}} | ||
{{$embed.Set "color" $errorColor}} | ||
{{updateMessage (complexMessageEdit "embed" (cembed $embed))}} | ||
{{cancelScheduledUniqueCC $data.ccID "cancel"}}{{dbDel $userID "bj"}} | ||
{{return}} | ||
{{end}} | ||
{{$components := (cslice (cbutton "label" "Hit" "custom_id" "bj_hit" "style" "primary") (cbutton "label" "Stand" "custom_id" "bj_stand" "style" "success") (cbutton "label" "Double Down" "custom_id" "bj_double" "style" "secondary" "disabled" true) (cbutton "label" "Split" "custom_id" "bj_split" "style" "secondary" "disabled" true))}} | ||
{{updateMessage (complexMessageEdit "embed" (cembed $embed) "components" $components)}} | ||
{{scheduleUniqueCC $data.ccID nil 120 "cancel" "bj"}}{{dbSetExpire $userID "bj" (sdict "embed" $data.embed "player" $data.player "dealer" $data.dealer "usedCards" $data.usedCards "bet" $data.bet "user" .User.ID "ccID" $data.ccID) 120}} | ||
{{else if eq .StrippedID "stand"}} | ||
{{$data.dealer.Set "cardValue" $data.dealer.cardValueReal}}{{$data.dealer.Del "cardValueReal"}}{{$data.dealer.Set "cardPrint" $data.dealer.cardPrintReal}}{{$data.dealer.Del "cardPrintReal"}} | ||
{{$dealer := $data.dealer}} | ||
{{$value := $dealer.cardValue | toInt}} | ||
{{while le $value 17}}{{$hit := execTemplate "hit" (sdict "data" $data "user" "dealer")}}{{$data.Set "usedCards" $hit.Used}}{{$hit.Del "used"}}{{$dealer = $hit}}{{$data.Set "dealer" $dealer}}{{$value = add $value $hit.cardValue}}{{end}} | ||
{{template "standCondition" (sdict "data" $data "symbol" $symbol "bal" $bal)}} | ||
{{else if eq .StrippedID "double"}} | ||
{{$data.Set "bet" (mult $data.bet 2)}} | ||
{{$hit := execTemplate "hit" (sdict "data" $data "user" "player")}} | ||
{{$player := $data.player}}{{$data.Set "usedCards" $hit.Used}}{{$hit.Del "used"}}{{$player = $hit}}{{$data.Set "player" $player}} | ||
{{if gt $data.player.cardValue 21}} | ||
{{template "standCondition" (sdict "data" $data "symbol" $symbol "bal" $bal)}} | ||
{{return}} | ||
{{end}} | ||
{{$data.dealer.Set "cardValue" $data.dealer.cardValueReal}}{{$data.dealer.Del "cardValueReal"}}{{$data.dealer.Set "cardPrint" $data.dealer.cardPrintReal}}{{$data.dealer.Del "cardPrintReal"}} | ||
{{$dealer := $data.dealer}} | ||
{{$value := $dealer.cardValue | toInt}} | ||
{{while lt $value 17}}{{$hit := execTemplate "hit" (sdict "data" $data "user" "dealer")}}{{$data.Set "usedCards" $hit.Used}}{{$hit.Del "used"}}{{$dealer = $hit}}{{$data.Set "dealer" $dealer}}{{$value = add $value $hit.cardValue}}{{end}} | ||
{{template "standCondition" (sdict "data" $data "symbol" $symbol "bal" $bal)}} | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters