Skip to content

Commit

Permalink
Item expiry (#30)
Browse files Browse the repository at this point in the history
* Feat: Add item expirey to create item

* feat: Add support for displaying duration in embeds

* Add expiry support to iteminfo and format code

* Item expiry if value is given in create-item

* Chore: Set expiry to nil on skip

* Add expires at time to buyitem

* Add expires at time to inventory

* feat: Adds expiry to  edititem

* Empty-Commit

* Empty-Commit

---------

Co-authored-by: Ranger4297 <a.rhykerw.com>
  • Loading branch information
Ranger-4297 authored Jul 23, 2023
1 parent afabe21 commit bdd105f
Show file tree
Hide file tree
Showing 5 changed files with 306 additions and 216 deletions.
187 changes: 104 additions & 83 deletions Economy/Shop/buy-item.cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,113 +30,134 @@
{{$bal := or (dbGet $userID "cash").Value 0 | toInt}}
{{$userdata := or (dbGet $userID "userEconData").Value (sdict "inventory" sdict "streaks" (sdict "daily" 0 "weekly" 0 "monthly" 0))}}
{{$inventory := $userdata.inventory}}
{{with (dbGet 0 "store")}}
{{$shop := sdict .Value}}
{{$items := sdict}}
{{if ($shop.Get "items")}}
{{$items = sdict ($shop.Get "items")}}
{{with $.CmdArgs}}
{{$name := (index . 0)}}
{{if $items.Get $name}}
{{$item := $items.Get $name}}
{{$price := $item.Get "price"}}
{{$shopQuantity := $item.Get "quantity"}}
{{$userQuantity := 0}}
{{if ($inventory.Get $name)}}
{{$invitem := ($inventory.Get $name)}}
{{$userQuantity = ($invitem.Get "quantity")}}
{{end}}
{{$buyQuantity := 1}}
{{$cont := false}}
{{if gt (len $.CmdArgs) 1}}
{{$buyQuantity = (index . 1)}}
{{if toInt $buyQuantity}}
{{if ge (toInt $buyQuantity) 1}}
{{if not (eq (toString $shopQuantity) "inf")}}
{{if le (toInt $buyQuantity) (toInt $shopQuantity)}}
{{$cont = true}}
{{$shopQuantity = sub $shopQuantity $buyQuantity}}
{{if not $.ExecData}}
{{with (dbGet 0 "store")}}
{{$shop := sdict .Value}}
{{$items := sdict}}
{{if ($shop.Get "items")}}
{{$items = sdict ($shop.Get "items")}}
{{with $.CmdArgs}}
{{$name := (index . 0)}}
{{if $items.Get $name}}
{{$item := $items.Get $name}}
{{$price := $item.Get "price"}}
{{$shopQuantity := $item.Get "quantity"}}
{{$userQuantity := 0}}
{{if ($inventory.Get $name)}}
{{$invitem := ($inventory.Get $name)}}
{{$userQuantity = ($invitem.Get "quantity")}}
{{end}}
{{$buyQuantity := 1}}
{{$cont := false}}
{{if gt (len $.CmdArgs) 1}}
{{$buyQuantity = (index . 1)}}
{{if toInt $buyQuantity}}
{{if ge (toInt $buyQuantity) 1}}
{{if not (eq (toString $shopQuantity) "inf")}}
{{if le (toInt $buyQuantity) (toInt $shopQuantity)}}
{{$cont = true}}
{{$shopQuantity = sub $shopQuantity $buyQuantity}}
{{else}}
{{$embed.Set "description" (print "There's not enough of this in the shop to buy that much!")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "There's not enough of this in the shop to buy that much!")}}
{{$embed.Set "color" $errorColor}}
{{$cont = true}}
{{end}}
{{else}}
{{$cont = true}}
{{$embed.Set "description" (print "Invalid quantity argument provided :(\nSyntax is `" $.Cmd " " $name " [Quantity:Int/All]`")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "Invalid quantity argument provided :(\nSyntax is `" $.Cmd " " $name " [Quantity:Int/All]`")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$buyQuantity = lower $buyQuantity}}
{{if eq (toString $buyQuantity) "all"}}
{{if eq (toString $shopQuantity) "inf"}}
{{$buyQuantity = div (toInt $bal) $price}}
{{$cont = true}}
{{$buyQuantity = lower $buyQuantity}}
{{if eq (toString $buyQuantity) "all"}}
{{if eq (toString $shopQuantity) "inf"}}
{{$buyQuantity = div (toInt $bal) $price}}
{{$cont = true}}
{{else}}
{{$buyQuantity = $shopQuantity}}
{{$shopQuantity = sub $shopQuantity $buyQuantity}}
{{$cont = true}}
{{end}}
{{else}}
{{$buyQuantity = $shopQuantity}}
{{$shopQuantity = sub $shopQuantity $buyQuantity}}
{{$cont = true}}
{{$embed.Set "description" (print "Invalid quantity argument provided :(\nSyntax is `" $.Cmd " " $name " [Quantity:Int/All[`")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "Invalid quantity argument provided :(\nSyntax is `" $.Cmd " " $name " [Quantity:Int/All[`")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{if not (eq (toString $shopQuantity) "inf")}}
{{$shopQuantity = sub $shopQuantity 1}}
{{end}}
{{$buyQuantity = 1}}
{{$cont = true}}
{{end}}
{{else}}
{{if not (eq (toString $shopQuantity) "inf")}}
{{$shopQuantity = sub $shopQuantity 1}}
{{end}}
{{$buyQuantity = 1}}
{{$cont = true}}
{{end}}
{{if $cont}}
{{if not (and (eq $name "chicken") (gt (toInt $buyQuantity) 1))}}
{{$price = mult $buyQuantity $price}}
{{if ge $bal $price}}
{{$userQuantity = add $userQuantity $buyQuantity}}
{{$bal = sub $bal $price}}
{{if not $shopQuantity}}
{{$items.Del $name}}
{{else}}
{{$item.Set "quantity" $shopQuantity}}
{{$items.Set $name $item}}
{{end}}
{{$shop.Set "items" $items}}
{{dbSet 0 "store" $shop}}
{{if $inventory.Get $name}}
{{$item = $inventory.Get $name}}
{{$item.Set "quantity" $userQuantity}}
{{$inventory.Set $name $item}}
{{if $cont}}
{{if not (and (eq $name "chicken") (gt (toInt $buyQuantity) 1))}}
{{$price = mult $buyQuantity $price}}
{{if ge $bal $price}}
{{$userQuantity = add $userQuantity $buyQuantity}}
{{$bal = sub $bal $price}}
{{if not $shopQuantity}}
{{$items.Del $name}}
{{else}}
{{$item.Set "quantity" $shopQuantity}}
{{$items.Set $name $item}}
{{end}}
{{$exp := $item.expiry}}
{{$expires := "never"}}
{{if (toDuration $exp)}}
{{$timeSeconds := toDuration (humanizeDurationSeconds (mult $exp $.TimeSecond))}}
{{$expires = (print "<t:" (currentTime.Add $timeSeconds).Unix ":f>")}}
{{end}}
{{$shop.Set "items" $items}}
{{dbSet 0 "store" $shop}}
{{if $inventory.Get $name}}
{{$item = $inventory.Get $name}}
{{$item.Set "quantity" $userQuantity}}
{{$inventory.Set $name $item}}
{{else}}
{{$inventory.Set $name (sdict "desc" $item.desc "quantity" $userQuantity "role" $item.role "replyMsg" $item.replyMsg "expiry" $exp "expires" $expires)}}
{{end}}
{{$embed.Set "description" (print "You've bought " $buyQuantity " of " $name " for " $symbol $price "!")}}
{{$embed.Set "color" $successColor}}
{{if $exp}}
{{scheduleUniqueCC $.CCID nil $exp $name (sdict "user" $.User.ID "itemName" $name "expiry" $exp)}}
{{end}}
{{else}}
{{$inventory.Set $name (sdict "desc" $item.desc "quantity" $userQuantity "role" $item.role "replyMsg" $item.replyMsg)}}
{{$embed.Set "description" (print "You don't have enough to buy this :(")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{$embed.Set "description" (print "You've bought " $buyQuantity " of " $name " for " $symbol $price "!")}}
{{$embed.Set "color" $successColor}}
{{else}}
{{$embed.Set "description" (print "You don't have enough to buy this :(")}}
{{$embed.Set "description" (print "You can only buy 1 of the item " $name)}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "You can only buy 1 of the item " $name)}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "This item doesn't exist :( Create it with `" $prefix "create-item " $name "`\n\nTo view all items, run the `" $prefix "shop` command.")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "This item doesn't exist :( Create it with `" $prefix "create-item " $name "`\n\nTo view all items, run the `" $prefix "shop` command.")}}
{{$embed.Set "description" (print "No item argument provided :(\nSyntax is `" $.Cmd " <Name> [Quantity:Int/All]`\n\nTo view all items, run the `" $prefix "shop` command.")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "No item argument provided :(\nSyntax is `" $.Cmd " <Name> [Quantity:Int/All]`\n\nTo view all items, run the `" $prefix "shop` command.")}}
{{$embed.Set "description" (print "There are no items :(\nAdd some items with `" $prefix "create-item <Name> <Price:Int> <Quantity:Int/Inf> <Description:String>`")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{else}}
{{$embed.Set "description" (print "There are no items :(\nAdd some items with `" $prefix "create-item <Name> <Price:Int> <Quantity:Int/Inf> <Description:String>`")}}
{{$embed.Set "color" $errorColor}}
{{end}}
{{dbSet $userID "userEconData" $userdata}}
{{dbSet $userID "cash" $bal}}
{{else}}
{{$userData := (dbGet $.ExecData.user "userEconData").Value}}
{{$item := $.ExecData.itemName}}
{{$inventory := $userData.inventory}}
{{if $inventory.Get $item}}
{{$inventory.Del $item}}
{{end}}
{{dbSet $.ExecData.user "userEconData" $userData}}
{{cancelScheduledUniqueCC $.CCID $.ExecData.itemName}}
{{return}}
{{end}}
{{dbSet $userID "userEconData" $userdata}}
{{dbSet $userID "cash" $bal}}
{{else}}
{{$embed.Set "description" (print "No `Settings` database found.\nPlease set it up with the default values using `" $prefix "server-set default`")}}
{{$embed.Set "color" $errorColor}}
Expand Down
Loading

0 comments on commit bdd105f

Please sign in to comment.