github.com/starshine-sys/bcr@v0.21.0/parsers_greedy.go (about)

     1  package bcr
     2  
     3  import "github.com/diamondburned/arikawa/v3/discord"
     4  
     5  // GreedyChannelParser parses all arguments until it finds an error.
     6  // Returns the parsed channels and the position at which it stopped.
     7  // If all arguments were parsed as channels, returns -1.
     8  func (ctx *Context) GreedyChannelParser(args []string) (channels []*discord.Channel, n int) {
     9  	for i, a := range args {
    10  		c, err := ctx.ParseChannel(a)
    11  		if err != nil {
    12  			return channels, i
    13  		}
    14  		channels = append(channels, c)
    15  	}
    16  	return channels, -1
    17  }
    18  
    19  // GreedyMemberParser parses all arguments until it finds an error.
    20  // Returns the parsed members and the position at which it stopped.
    21  // If all arguments were parsed as members, returns -1.
    22  func (ctx *Context) GreedyMemberParser(args []string) (members []*discord.Member, n int) {
    23  	for i, a := range args {
    24  		c, err := ctx.ParseMember(a)
    25  		if err != nil {
    26  			return members, i
    27  		}
    28  		members = append(members, c)
    29  	}
    30  	return members, -1
    31  }
    32  
    33  // GreedyRoleParser parses all arguments until it finds an error.
    34  // Returns the parsed roles and the position at which it stopped.
    35  // If all arguments were parsed as roles, returns -1.
    36  func (ctx *Context) GreedyRoleParser(args []string) (roles []*discord.Role, n int) {
    37  	for i, a := range args {
    38  		c, err := ctx.ParseRole(a)
    39  		if err != nil {
    40  			return roles, i
    41  		}
    42  		roles = append(roles, c)
    43  	}
    44  	return roles, -1
    45  }
    46  
    47  // GreedyUserParser parses all arguments until it finds an error.
    48  // Returns the parsed users and the position at which it stopped.
    49  // If all arguments were parsed as users, returns -1.
    50  func (ctx *Context) GreedyUserParser(args []string) (users []*discord.User, n int) {
    51  	for i, a := range args {
    52  		c, err := ctx.ParseUser(a)
    53  		if err != nil {
    54  			return users, i
    55  		}
    56  		users = append(users, c)
    57  	}
    58  	return users, -1
    59  }