Skip to content

Commit

Permalink
fix: ensure choices set to argument (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f authored Jan 9, 2025
1 parent 3b1394f commit 744f989
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/engine/command/calculator/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *CalculatorCmd) GetCommand() *command.Command {
subCmdCalcReward := &command.Command{
Name: "reward",
Help: "Calculate the PAC coins you can earn based on your validator stake",
Args: []command.Args{
Args: []*command.Args{
{
Name: "stake",
Desc: "The amount of stake in your validator",
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type Command struct {
Emoji string `yaml:"emoji"`
Name string `yaml:"name"`
Help string `yaml:"help"`
Args []Args `yaml:"args"`
Args []*Args `yaml:"args"`
SubCommands []*Command `yaml:"sub_commands"`
ResultTemplate string `yaml:"result_template"`
Middlewares []MiddlewareFunc `yaml:"-"`
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/command/crowdfund/crowdfund.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions internal/engine/command/crowdfund/crowdfund.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ func (c *CrowdfundCmd) activeCampaign() *entity.CrowdfundCampaign {
func (c *CrowdfundCmd) GetCommand() *command.Command {
cmd := c.crowdfundCommand()

subCmdCreate.AppIDs = []entity.PlatformID{entity.PlatformIDCLI, entity.PlatformIDDiscord}
subCmdDisable.AppIDs = []entity.PlatformID{entity.PlatformIDCLI, entity.PlatformIDDiscord}
subCmdReport.AppIDs = entity.AllAppIDs()
subCmdInfo.AppIDs = entity.AllAppIDs()
subCmdPurchase.AppIDs = entity.AllAppIDs()
subCmdClaim.AppIDs = entity.AllAppIDs()

subCmdCreate.TargetFlag = command.TargetMaskModerator
subCmdDisable.TargetFlag = command.TargetMaskModerator
subCmdReport.TargetFlag = command.TargetMaskMainnet
subCmdInfo.TargetFlag = command.TargetMaskMainnet
subCmdPurchase.TargetFlag = command.TargetMaskMainnet
subCmdClaim.TargetFlag = command.TargetMaskMainnet

activeCampaign := c.activeCampaign()
if activeCampaign != nil {
purchaseChoices := []command.Choice{}
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/crowdfund/crowdfund.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sub_commands:
Packages:
{{range .campaign.Packages}}
- {{.Name}}
- {{.Name}}: {{.USDAmount}} USDT to {{.PACAmount}} PAC
{{- end}}
- name: purchase
help: Make a purchase in a crowdfunding campaign
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/market/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (m *MarketCmd) GetCommand() *command.Command {
subCmdPrice := &command.Command{
Name: "price",
Help: "Shows the latest price of PAC coin across different markets",
Args: []command.Args{},
Args: []*command.Args{},
SubCommands: nil,
AppIDs: entity.AllAppIDs(),
Handler: m.priceHandler,
Expand Down
6 changes: 3 additions & 3 deletions internal/engine/command/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (n *NetworkCmd) GetCommand() *command.Command {
subCmdNodeInfo := &command.Command{
Name: "node-info",
Help: "View information about a specific node",
Args: []command.Args{
Args: []*command.Args{
{
Name: "validator_address",
Desc: "The validator address",
Expand All @@ -71,7 +71,7 @@ func (n *NetworkCmd) GetCommand() *command.Command {
subCmdHealth := &command.Command{
Name: "health",
Help: "Check the network health status",
Args: []command.Args{},
Args: []*command.Args{},
SubCommands: nil,
AppIDs: entity.AllAppIDs(),
Handler: n.healthHandler,
Expand All @@ -81,7 +81,7 @@ func (n *NetworkCmd) GetCommand() *command.Command {
subCmdStatus := &command.Command{
Name: "status",
Help: "View network statistics",
Args: []command.Args{},
Args: []*command.Args{},
SubCommands: nil,
AppIDs: entity.AllAppIDs(),
Handler: n.statusHandler,
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/phoenix/phoenix.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (p *PhoenixCmd) GetCommand() *command.Command {
subCmdFaucet := &command.Command{
Name: "faucet",
Help: fmt.Sprintf("Get %f tPAC Coins on Phoenix Testnet for Testing your code or project", p.faucetAmount.ToPAC()),
Args: []command.Args{
Args: []*command.Args{
{
Name: "address",
Desc: "your testnet address [example: tpc1z...]",
Expand Down
8 changes: 4 additions & 4 deletions internal/engine/command/voucher/voucher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (v *VoucherCmd) GetCommand() *command.Command {
subCmdClaim := &command.Command{
Name: "claim",
Help: "Claim voucher coins and bond them to a validator",
Args: []command.Args{
Args: []*command.Args{
{
Name: "code",
Desc: "The voucher code",
Expand All @@ -52,7 +52,7 @@ func (v *VoucherCmd) GetCommand() *command.Command {
subCmdCreateOne := &command.Command{
Name: "create-one",
Help: "Generate a single voucher code",
Args: []command.Args{
Args: []*command.Args{
{
Name: "amount",
Desc: "The amount of PAC to bond",
Expand Down Expand Up @@ -88,7 +88,7 @@ func (v *VoucherCmd) GetCommand() *command.Command {
subCmdCreateBulk := &command.Command{
Name: "create-bulk",
Help: "Generate multiple voucher codes by importing a file",
Args: []command.Args{
Args: []*command.Args{
{
Name: "file",
Desc: "File containing a list of voucher recipients",
Expand All @@ -112,7 +112,7 @@ func (v *VoucherCmd) GetCommand() *command.Command {
subCmdStatus := &command.Command{
Name: "status",
Help: "View the status of vouchers or a specific voucher",
Args: []command.Args{
Args: []*command.Args{
{
Name: "code",
Desc: "The voucher code (8 characters)",
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/zealy/zealy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (z *ZealyCmd) GetCommand() *command.Command {
subCmdClaim := &command.Command{
Name: "claim",
Help: "Claim your Zealy reward",
Args: []command.Args{
Args: []*command.Args{
{
Name: "address",
Desc: "The Pactus address where the reward will be claimed",
Expand Down
2 changes: 1 addition & 1 deletion internal/platforms/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (bot *Bot) parsTextMessage(ctx tele.Context) error {
return ctx.Send(fmt.Sprintf("Please Enter %s", cmd.Args[currentArgsIndex+1].Name))
}

func (bot *Bot) handleArgCommand(ctx tele.Context, commands []string, args []command.Args) error {
func (bot *Bot) handleArgCommand(ctx tele.Context, commands []string, args []*command.Args) error {
msgCtx := &BotContext{Commands: commands}
argsContext[ctx.Sender().ID] = msgCtx
argsValue[ctx.Sender().ID] = nil
Expand Down

0 comments on commit 744f989

Please sign in to comment.