Example #1
0
func giveBits(cmd *modulebase.ModuleCommand) (string, error) {
	if len(cmd.Args) < 2 {
		return giveBitsHelpString, nil
	}

	amount, err := strconv.Atoi(cmd.Args[0])
	if err != nil {
		return "Invalid amount", nil
	}

	if amount <= 0 {
		return "Amount must be a positive nonzero integer", nil
	}

	userName := strings.Join(cmd.Args[1:], " ")
	user, err := utils.FindUser(cmd.Guild, userName)
	if err != nil {
		return "Unable to find user", nil
	}

	gifter := cmd.Message.Author
	if bits.GetBits(cmd.Guild.ID, gifter.ID) < amount {
		return "Not enough bits", nil
	}

	bits.RemoveBits(cmd.Session, cmd.Guild.ID, gifter.ID, amount, "Gift")
	bits.AddBits(cmd.Session, cmd.Guild.ID, user.ID, amount, "Gift", false)

	message := fmt.Sprintf("Transferred %d bits from %v to %v",
		amount,
		utils.GetPreferredName(cmd.Guild, gifter.ID),
		utils.GetPreferredName(cmd.Guild, user.ID))

	return message, nil
}
Example #2
0
func takeBits(cmd *modulebase.ModuleCommand) (string, error) {
	if len(cmd.Args) < 2 {
		return takeBitsHelpString, nil
	}

	amount, err := strconv.Atoi(cmd.Args[0])
	if err != nil {
		return "Invalid amount", nil
	}

	if amount <= 0 {
		return "Amount must be a positive nonzero integer", nil
	}

	userName := strings.Join(cmd.Args[1:], " ")
	user, err := utils.FindUser(cmd.Guild, userName)
	if err != nil {
		return "Unable to find user", nil
	}

	bits.RemoveBits(cmd.Session, cmd.Guild.ID, user.ID, amount, "Took bits")

	message := fmt.Sprintf("Took %d bits from %v",
		amount,
		utils.GetPreferredName(cmd.Guild, user.ID))

	return message, nil
}