From bdd105f0f28a7612f0c39b9a25f9afb742fbb754 Mon Sep 17 00:00:00 2001 From: Ranger Date: Sun, 23 Jul 2023 21:54:40 +0100 Subject: [PATCH] Item expiry (#30) * 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 --- Economy/Shop/buy-item.cc.go | 187 ++++++++++++----------- Economy/Shop/create-item.cc.go | 265 ++++++++++++++++++--------------- Economy/Shop/edit-item.cc.go | 41 ++++- Economy/Shop/inventory.cc.go | 3 +- Economy/Shop/item-info.cc.go | 26 +++- 5 files changed, 306 insertions(+), 216 deletions(-) diff --git a/Economy/Shop/buy-item.cc.go b/Economy/Shop/buy-item.cc.go index f36bc22..30fd0ee 100644 --- a/Economy/Shop/buy-item.cc.go +++ b/Economy/Shop/buy-item.cc.go @@ -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 "")}} + {{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 " [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 " [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 `")}} {{$embed.Set "color" $errorColor}} {{end}} - {{else}} - {{$embed.Set "description" (print "There are no items :(\nAdd some items with `" $prefix "create-item `")}} - {{$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}} diff --git a/Economy/Shop/create-item.cc.go b/Economy/Shop/create-item.cc.go index e121648..120d6c9 100644 --- a/Economy/Shop/create-item.cc.go +++ b/Economy/Shop/create-item.cc.go @@ -15,189 +15,212 @@ {{/* Only edit below if you know what you're doing (: rawr */}} {{/* Initiates variables */}} -{{$userID := .User.ID}} -{{$errorColor := 0xFF0000}} -{{$dbVal := toInt (dbGet .User.ID "waitResponse").Value}} -{{$cmdStage := 0}} -{{$trigger := print `(` .ServerPrefix `|<@!?204255221017214977>\s*)((create|new)-?item)`}} +{{$uI := .User.ID}} +{{$eC := 0xFF0000}} +{{$dV := toInt (dbGet .User.ID "waitResponse").Value}} +{{$cS := 0}} +{{$t := print `(` .ServerPrefix `|<@!?204255221017214977>\s*)((create|new)-?item)`}} {{/* Create item */}} {{/* Response */}} -{{$embed := sdict "title" "Item info" "footer" (sdict "text" "Type cancel to cancel the setup") "color" 0x00ff7b "timestamp" currentTime}} -{{$shop := or (dbGet 0 "store").Value (sdict "items" sdict)}} -{{$items := $shop.items}} -{{$itemData := sdict "desc" "" "price" 0 "quantity" 0 "role" 0 "reply-msg" ""}} -{{$perms := split (index (split (exec "viewperms") "\n") 2) ", "}} +{{$e := sdict "title" "Item info" "footer" (sdict "text" "Type cancel to cancel the setup") "color" 0x00ff7b "timestamp" currentTime}} +{{$s := or (dbGet 0 "store").Value (sdict "items" sdict)}} +{{$i := $s.items}} +{{$iD := sdict "desc" "" "price" 0 "quantity" 0 "role" 0 "reply-msg" ""}} +{{$p := split (index (split (exec "viewperms") "\n") 2) ", "}} {{if not .ExecData}} {{with $eco := (dbGet 0 "EconomySettings").Value}} - {{$symbol := $eco.symbol}} - {{if not $dbVal}} + {{$sB := $eco.symbol}} + {{if not $dV}} {{/* checks if message matches regex to begin tutorial */}} - {{if reFind (print `\A(?i)` $trigger `(\s+|\z)`) $.Message.Content}} - {{if or (in $perms "Administrator") (in $perms "ManageServer")}} - {{$embed.Set "fields" (cslice (sdict "name" "Name" "value" "⠀⠀"))}} - {{$cmdStage = 1}} - {{$embed := sendMessageRetID nil (complexMessage "content" "Please enter a name for the item (under 60 characters)" "embed" (cembed $embed))}} - {{dbSet 0 "createItem" (sdict "embed" (toString $embed) "item" (sdict "name" "" "data" $itemData) "user" (toString $userID))}} + {{if reFind (print `\A(?i)` $t `(\s+|\z)`) $.Message.Content}} + {{if or (in $p "Administrator") (in $p "ManageServer")}} + {{$e.Set "fields" (cslice (sdict "name" "Name" "value" "⠀⠀"))}} + {{$cS = 1}} + {{$e := sendMessageRetID nil (complexMessage "content" "Please enter a name for the item (under 60 characters)" "embed" (cembed $e))}} + {{dbSet 0 "createItem" (sdict "embed" (toString $e) "item" (sdict "name" "" "data" $iD) "user" (toString $uI))}} {{scheduleUniqueCC $.CCID nil 120 1 1}} {{else}} - {{$embed.Del "footer"}}{{$embed.Del "title"}} - {{$embed.Set "author" (sdict "name" $.User.Username "icon_url" ($.User.AvatarURL "1024"))}} - {{$embed.Set "description" (print "Insufficient permissions.\nTo use this command you need to have either `Administrator` or `ManageServer` permissions")}} - {{$embed.Set "color" $errorColor}} - {{sendMessage nil (cembed $embed)}} + {{$e.Del "footer"}}{{$e.Del "title"}} + {{$e.Set "author" (sdict "name" $.User.Username "icon_url" ($.User.AvatarURL "1024"))}} + {{$e.Set "description" (print "Insufficient permissions.\nTo use this command you need to have either `Administrator` or `ManageServer` permissions")}} + {{$e.Set "color" $eC}} + {{sendMessage nil (cembed $e)}} {{end}} {{end}} {{else}} - {{$createItem := (dbGet 0 "createItem").Value}} - {{if and $createItem.user (eq (toString $createItem.user) (toString $userID))}} - {{if eq $dbVal 1}} + {{$cE := (dbGet 0 "createItem").Value}} + {{if and $cE.user (eq (toString $cE.user) (toString $uI))}} + {{if eq $dV 1}} {{if and (le (len (toRune $.Message.Content)) 60) (not (eq $.Message.Content "cancel"))}} {{$name := $.Message.Content}} - {{$item := $createItem.item}} - {{$item.Set "name" $name}} - {{dbSet 0 "createItem" $createItem}} - {{$embed.Set "fields" (cslice (sdict "name" "Name" "value" $name "inline" true))}} - {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "Please enter a price for the item" "embed" (cembed $embed))}} - {{$cmdStage = 1}} + {{$im := $cE.item}} + {{$im.Set "name" $name}} + {{dbSet 0 "createItem" $cE}} + {{$e.Set "fields" (cslice (sdict "name" "Name" "value" $name "inline" true))}} + {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "Please enter a price for the item" "embed" (cembed $e))}} + {{$cS = 1}} {{else if not (eq $.Message.Content "cancel")}} - {{$msg := sendMessageRetID nil "Please try again and enter name under 60 characters"}} + {{$m := sendMessageRetID nil "Please try again and enter name under 60 characters"}} {{deleteTrigger 0}} - {{deleteMessage nil $msg 10}} - {{$cmdStage = 0}} + {{deleteMessage nil $m 10}} + {{$cS = 0}} {{end}} {{scheduleUniqueCC $.CCID nil 120 1 2}} - {{else if eq $dbVal 2}} + {{else if eq $dV 2}} {{with toInt $.Message.Content}} {{if gt . 0}} {{$price := .}} - {{$item := $createItem.item}} - {{$item.data.Set "price" $price}} - {{dbSet 0 "createItem" $createItem}} - {{$msg := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} - {{$field := sdict "name" "Price" "value" (print $symbol .) "inline" true}} - {{$embed.Set "fields" ((cslice.AppendSlice $msg.Fields).Append $field)}} - {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "Please enter a description for the item (under 200 characters)" "embed" (cembed $embed))}} - {{$cmdStage = 1}} + {{$im := $cE.item}} + {{$im.data.Set "price" $price}} + {{dbSet 0 "createItem" $cE}} + {{$m := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} + {{$f := sdict "name" "Price" "value" (print $sB .) "inline" true}} + {{$e.Set "fields" ((cslice.AppendSlice $m.Fields).Append $f)}} + {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "Please enter a description for the item (under 200 characters)" "embed" (cembed $e))}} + {{$cS = 1}} {{else}} - {{$msg := sendMessageRetID nil "Please try again and enter a valid number"}} + {{$m := sendMessageRetID nil "Please try again and enter a valid number"}} {{deleteTrigger 0}} - {{deleteMessage nil $msg 10}} - {{$cmdStage = 0}} + {{deleteMessage nil $m 10}} + {{$cS = 0}} {{end}} {{else if not (eq (lower $.Message.Content) "cancel")}} - {{$msg := sendMessageRetID nil "Please try again and enter a valid number"}} + {{$m := sendMessageRetID nil "Please try again and enter a valid number"}} {{deleteTrigger 0}} - {{deleteMessage nil $msg 10}} - {{$cmdStage = 0}} + {{deleteMessage nil $m 10}} + {{$cS = 0}} {{end}} {{scheduleUniqueCC $.CCID nil 120 1 3}} - {{else if or (eq $dbVal 3) (eq $dbVal 6)}} + {{else if or (eq $dV 3) (eq $dV 6)}} {{if and (le (len (toRune $.Message.Content)) 200) (not (eq $.Message.Content "cancel"))}} - {{$option := ""}} - {{$fieldValue := ""}} - {{if eq $dbVal 3}} - {{$option = "desc"}} - {{$fieldValue = "description"}} + {{$o := ""}} + {{$fV := ""}} + {{if eq $dV 3}} + {{$o = "desc"}} + {{$fV = "description"}} {{else}} - {{$option = "replyMsg"}} - {{$fieldValue = "reply"}} + {{$o = "replyMsg"}} + {{$fV = "reply"}} {{end}} - {{$item := $createItem.item}} - {{$item.data.Set $option $.Message.Content}} - {{$msg := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} - {{$field := sdict "name" $fieldValue "value" $.Message.Content}} - {{$embed.Set "fields" ((cslice.AppendSlice $msg.Fields).Append $field)}} - {{if eq $dbVal 3}} - {{dbSet 0 "createItem" $createItem}} - {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "How much of this item should the store stock?\nIf unlimited just reply `skip` or `inf`" "embed" (cembed $embed))}} - {{scheduleUniqueCC $.CCID nil 120 1 4}} + {{$im := $cE.item}} + {{$im.data.Set $o $.Message.Content}} + {{$m := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} + {{$f := sdict "name" $fV "value" $.Message.Content}} + {{$e.Set "fields" ((cslice.AppendSlice $m.Fields).Append $f)}} + {{if eq $dV 3}} + {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "How much of this item should the store stock?\nIf unlimited just reply `skip` or `inf`" "embed" (cembed $e))}} {{else}} - {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "Item created! ✅" "embed" (cembed $embed))}} - {{$items.Set $createItem.item.name $createItem.item.data}} - {{dbSet 0 "store" $shop}} - {{dbDel 0 "createItem"}} - {{dbDel $userID "waitResponse"}} - {{cancelScheduledUniqueCC $.CCID 1}} + {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "When should this item expire from the users inventory if not used\nIf never just reply `skip` or `inf`" "embed" (cembed $e))}} {{end}} - {{$cmdStage = 1}} + {{dbSet 0 "createItem" $cE}} + {{$cS = 1}} + {{scheduleUniqueCC $.CCID nil 120 1 4}} {{else if not (eq $.Message.Content "cancel")}} - {{$msg := sendMessageRetID nil "Please try again and enter name under 60 characters"}} + {{$m := sendMessageRetID nil "Please try again and enter name under 60 characters"}} {{deleteTrigger 0}} - {{deleteMessage nil $msg 10}} - {{$cmdStage = 0}} + {{deleteMessage nil $m 10}} + {{$cS = 0}} {{scheduleUniqueCC $.CCID nil 120 1 5}} {{end}} - {{else if eq $dbVal 4}} + {{else if eq $dV 4}} {{if or (gt (toInt $.Message.Content) 0) (eq (lower $.Message.Content) "inf" "skip")}} - {{$quantity := $.Message.Content}} - {{if eq $quantity "skip"}} - {{$quantity = "inf"}} + {{$qty := $.Message.Content}} + {{if eq $qty "skip" "inf"}} + {{$qty = "inf"}} {{end}} - {{$item := $createItem.item}} - {{$item.data.Set "quantity" $quantity}} - {{$msg := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} - {{$field := sdict "name" "Stock" "value" (toString $quantity) "inline" true}} - {{$embed.Set "fields" ((cslice.AppendSlice $msg.Fields).Append $field)}} - {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "What role do you want to be given when this item is used?\nType `skip` to skip this." "embed" (cembed $embed))}} - {{$cmdStage = 1}} - {{dbSet 0 "createItem" $createItem}} + {{$im := $cE.item}} + {{$im.data.Set "quantity" $qty}} + {{$m := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} + {{$f := sdict "name" "Stock" "value" (toString $qty) "inline" true}} + {{$e.Set "fields" ((cslice.AppendSlice $m.Fields).Append $f)}} + {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "What role do you want to be given when this item is used?\nType `skip` to skip this." "embed" (cembed $e))}} + {{$cS = 1}} + {{dbSet 0 "createItem" $cE}} {{else if not (eq $.Message.Content "cancel")}} - {{$msg := sendMessageRetID nil "Please try again and enter a valid number"}} + {{$m := sendMessageRetID nil "Please try again and enter a valid number"}} {{deleteTrigger 0}} - {{deleteMessage nil $msg 10}} - {{$cmdStage = 0}} + {{deleteMessage nil $m 10}} + {{$cS = 0}} {{end}} {{scheduleUniqueCC $.CCID nil 120 1 6}} - {{else if eq $dbVal 5}} - {{$role := $.Message.Content}} - {{if or ($.Guild.GetRole (toInt64 $role)) (eq $role "skip")}} - {{if eq $role "skip"}} - {{$role = 0}} + {{else if eq $dV 5}} + {{$r := $.Message.Content}} + {{if or ($.Guild.GetRole (toInt64 $r)) (eq (lower $r) "skip")}} + {{if eq $r "skip"}} + {{$r = 0}} {{end}} - {{$item := $createItem.item}} - {{$item.data.Set "role" $role}} - {{dbSet 0 "createItem" $createItem}} - {{if not $role}} - {{$role = "none"}} + {{$im := $cE.item}} + {{$im.data.Set "role" $r}} + {{dbSet 0 "createItem" $cE}} + {{if not $r}} + {{$r = "none"}} {{else}} - {{$role = print "<@&" $role ">"}} + {{$r = print "<@&" $r ">"}} {{end}} - {{$msg := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} - {{$field := sdict "name" "Role-given" "value" (toString $role) "inline" true}} - {{$embed.Set "fields" ((cslice.AppendSlice $msg.Fields).Append $field)}} - {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "What message should I reply with when the item is used? (under 200 character)" "embed" (cembed $embed))}} - {{$cmdStage = 1}} - {{else if not (eq (lower $role) "cancel")}} - {{$msg := sendMessageRetID nil "Please try again with a valid roleID"}} + {{$m := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} + {{$f := sdict "name" "Role-given" "value" (toString $r) "inline" true}} + {{$e.Set "fields" ((cslice.AppendSlice $m.Fields).Append $f)}} + {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "What message should I reply with when the item is used? (under 200 character)" "embed" (cembed $e))}} + {{$cS = 1}} + {{else if not (eq (lower $r) "cancel")}} + {{$m := sendMessageRetID nil "Please try again with a valid roleID"}} {{deleteTrigger 0}} - {{deleteMessage nil $msg 10}} - {{$cmdStage = 0}} + {{deleteMessage nil $m 10}} + {{$cS = 0}} {{end}} {{scheduleUniqueCC $.CCID nil 120 1 7}} + {{else if eq $dV 7}} + {{scheduleUniqueCC $.CCID nil 120 1 7}} + {{$d := $.Message.Content}} + {{if or (toDuration $d) (eq (lower $d) "skip" "inf")}} + {{$eV := "none"}} + {{if (toDuration $d)}} + {{$d = (toDuration $d).Seconds}} + {{$eV = humanizeDurationSeconds (mult $d $.TimeSecond)}} + {{else}} + {{$d = ""}} + {{end}} + {{$im := $cE.item}} + {{$im.data.Set "expiry" $d}} + {{$i.Set $cE.item.name $cE.item.data}} + {{$m := structToSdict (index (getMessage nil (dbGet 0 "createItem").Value.embed).Embeds 0)}} + {{$f := sdict "name" "Inventory expiry" "value" (toString $eV) "inline" true}} + {{$e.Set "fields" ((cslice.AppendSlice $m.Fields).Append $f)}} + {{editMessage nil (dbGet 0 "createItem").Value.embed (complexMessageEdit "content" "Item created! ✅" "embed" (cembed $e))}} + {{dbSet 0 "store" $s}} + {{dbDel 0 "createItem"}} + {{dbDel $uI "waitResponse"}} + {{cancelScheduledUniqueCC $.CCID 1}} + {{else}} + {{$m := sendMessageRetID nil "Please try again with a valid duration"}} + {{deleteTrigger 0}} + {{deleteMessage nil $m 10}} + {{$cS = 0}} + {{end}} {{end}} {{if eq (lower $.Message.Content) "cancel"}} {{sendMessage nil "Create-item was cancelled"}} - {{dbDel $userID "waitResponse"}} + {{dbDel $uI "waitResponse"}} {{dbDel 0 "createItem"}} - {{$cmdStage = 0}} + {{$cS = 0}} {{cancelScheduledUniqueCC $.CCID 1}} {{end}} {{end}} {{end}} {{else}} - {{$embed.Del "footer"}}{{$embed.Del "title"}} - {{$embed.Set "author" (sdict "name" $.User.Username "icon_url" ($.User.AvatarURL "1024"))}} - {{$embed.Set "description" (print "No `Settings` database found.\nPlease set it up with the default values using `" $.ServerPrefix "server-set default`")}} - {{$embed.Set "color" $errorColor}} - {{sendMessage nil (cembed $embed)}} + {{$e.Del "footer"}}{{$e.Del "title"}} + {{$e.Set "author" (sdict "name" $.User.Username "icon_url" ($.User.AvatarURL "1024"))}} + {{$e.Set "description" (print "No `Settings` database found.\nPlease set it up with the default values using `" $.ServerPrefix "server-set default`")}} + {{$e.Set "color" $eC}} + {{sendMessage nil (cembed $e)}} {{end}} {{else}} {{sendMessage nil "Create-item was cancelled"}} {{dbDel .User.ID "waitResponse"}} {{dbDel 0 "createItem"}} {{end}} -{{if $cmdStage}} - {{dbSetExpire .User.ID "waitResponse" (str (add $dbVal 1)) 120}} +{{if $cS}} + {{dbSetExpire .User.ID "waitResponse" (str (add $dV 1)) 120}} {{end}} \ No newline at end of file diff --git a/Economy/Shop/edit-item.cc.go b/Economy/Shop/edit-item.cc.go index 887c2f5..094eeb1 100644 --- a/Economy/Shop/edit-item.cc.go +++ b/Economy/Shop/edit-item.cc.go @@ -37,7 +37,7 @@ {{with $.CmdArgs}} {{$name := (index . 0)}} {{if $items.Get $name}} - {{$options := cslice "description" "role" "name" "price" "quantity"}} + {{$options := cslice "description" "role" "name" "price" "quantity" "expiry"}} {{if gt (len $.CmdArgs) 1}} {{$option := (index . 1) | lower}} {{if in $options $option}} @@ -107,11 +107,16 @@ {{$embed.Set "description" (print "No price argument provided :(\nSyntax is `" $.Cmd " " $name " " $option " `")}} {{$embed.Set "color" $errorColor}} {{end}} - {{else if eq $option "description"}} + {{else if eq $option "description" "replymsg"}} {{if gt (len $.CmdArgs) 2}} {{$value = (joinStr " " (slice $.CmdArgs 2))}} {{$item := $items.Get $name}} - {{$item.Set "desc" $value}} + {{if eq $option "description"}} + {{$option = "desc"}} + {{else}} + {{$option = "replyMsg"}} + {{end}} + {{$item.Set $option $value}} {{$items.Set $name $item}} {{$store.Set "items" $items}} {{dbSet 0 "store" $store}} @@ -140,17 +145,43 @@ {{$embed.Set "description" (print "No role argument provided :(\nSyntax is `" $.Cmd " " $name " " $option " `")}} {{$embed.Set "color" $errorColor}} {{end}} + {{else if eq $option "expiry"}} + {{if gt (len $.CmdArgs) 2}} + {{$value = (index . 2)}} + {{if or (toDuration $value) (eq (lower $value) "none" "remove")}} + {{if (toDuration $value)}} + {{$value = (toDuration $value).Seconds}} + {{else}} + {{$value = "none"}} + {{end}} + {{$item := $items.Get $name}} + {{$item.Set "expiry" $value}} + {{$items.Set $name $item}} + {{$store.Set "items" $items}} + {{dbSet 0 "store" $store}} + {{if (toDuration $value)}} + {{$value = humanizeDurationSeconds (mult $value $.TimeSecond)}} + {{end}} + {{$cont = 1}} + {{else}} + {{$embed.Set "description" (print "Invalid duration argument provided :(\nSyntax is `" $.Cmd " " $name " " $option " `")}} + {{$embed.Set "color" $errorColor}} + {{end}} + {{else}} + {{$embed.Set "description" (print "No duration argument provided :(\nSyntax is `" $.Cmd " " $name " " $option " `")}} + {{$embed.Set "color" $errorColor}} + {{end}} {{end}} {{if $cont}} {{$embed.Set "description" (print $name "'s `" $option "` has been changed to " $value)}} {{$embed.Set "color" $successColor}} {{end}} {{else}} - {{$embed.Set "description" (print "Invalid option argument provided :(\nSyntax is `" $.Cmd " `\nAvailable options are: `name`, `description`, `price`, `quantity` and `role``")}} + {{$embed.Set "description" (print "Invalid option argument provided :(\nSyntax is `" $.Cmd " `\nAvailable options are: `name`, `description`, `price`, `quantity`, `expiry` and `role``")}} {{$embed.Set "color" $errorColor}} {{end}} {{else}} - {{$embed.Set "description" (print "No option argument provided :(\nSyntax is `" $.Cmd " `\nAvailable options are: `name`, `description`, `price`, `quantity` and `role`")}} + {{$embed.Set "description" (print "No option argument provided :(\nSyntax is `" $.Cmd " `\nAvailable options are: `name`, `description`, `price`, `quantity`, `expiry` and `role`")}} {{$embed.Set "color" $errorColor}} {{end}} {{else}} diff --git a/Economy/Shop/inventory.cc.go b/Economy/Shop/inventory.cc.go index d67ca6b..3e62ae0 100644 --- a/Economy/Shop/inventory.cc.go +++ b/Economy/Shop/inventory.cc.go @@ -49,7 +49,8 @@ {{else}} {{$role = "none"}} {{end}} - {{$entry = $entry.Append (sdict "Name" $item "value" (joinStr "\n" (print "Description: " $desc) (print "Quantity: " (humanizeThousands $qty)) (print "Role given: " $role)) "inline" false)}} + {{$expires := $v.expires}} + {{$entry = $entry.Append (sdict "Name" $item "value" (joinStr "\n" (print "Description: " $desc) (print "Quantity: " (humanizeThousands $qty)) (print "Role given: " $role) (print "Expiry: " $expires)) "inline" false)}} {{end}} {{$page := ""}} {{if $.CmdArgs}} diff --git a/Economy/Shop/item-info.cc.go b/Economy/Shop/item-info.cc.go index 20572c9..678eac3 100644 --- a/Economy/Shop/item-info.cc.go +++ b/Economy/Shop/item-info.cc.go @@ -36,18 +36,32 @@ {{if $items.Get $name}} {{$item := $items.Get (index . 0)}} {{$price := $item.Get "price"}} - {{$role := "none"}} - {{if ($item.Get "role-given")}} - {{$role = ($item.Get "role-given")}} - {{end}} + {{$desc := $item.Get "desc"}} {{$qty := $item.quantity}} {{if not $qty}} {{$qty = "inf"}} {{end}} + {{$role := "none"}} + {{if ($item.Get "role-given")}} + {{$role = ($item.Get "role-given")}} + {{end}} {{$reply := $item.replyMsg}} - {{$desc := $item.Get "desc"}} + {{$exp := $item.expiry}} + {{if (toDuration $exp)}} + {{$exp = humanizeDurationSeconds (mult $exp $.TimeSecond)}} + {{end}} {{$embed.Set "title" (print "**Item info**")}} - {{$embed.Set "fields" (cslice (sdict "name" "Name" "value" (print $name) "inline" true) (sdict "name" (print "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀") "value" (print "⠀⠀") "inline" true) (sdict "name" "Price" "value" (print $symbol (humanizeThousands $price)) "inline" true) (sdict "name" "Description" "value" (print $desc) "inline" true) (sdict "name" (print "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀") "value" (print "⠀⠀") "inline" true) (sdict "name" "Shop quantity" "value" (print $qty) "inline" true) (sdict "name" "Role given" "value" (print $role)) (sdict "name" "Reply message" "Value" $reply))}} + {{$embed.Set "fields" (cslice + (sdict "name" "Name" "value" (print $name) "inline" true) + (sdict "name" (print "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀") "value" (print "⠀⠀") "inline" true) + (sdict "name" "Price" "value" (print $symbol (humanizeThousands $price)) "inline" true) + (sdict "name" "Description" "value" (print $desc) "inline" true) + (sdict "name" (print "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀") "value" (print "⠀⠀") "inline" true) + (sdict "name" "Shop quantity" "value" (print $qty) "inline" true) + (sdict "name" "Role given" "value" (print $role) "inline" true) + (sdict "name" "Reply message" "value" $reply) + (sdict "name" "Inventory expiry" "value" $exp) + )}} {{$embed.Set "color" $successColor}} {{else}} {{$embed.Set "description" (print "Invalid item argument provided :(\nSyntax is `" $.Cmd " `")}}