Ejemplo n.º 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
}
Ejemplo n.º 2
0
func handleNickChange(cmd *modulebase.ModuleCommand) (string, error) {
	nicknames := nickCollection{ramendb.GetCollection(cmd.Guild.ID, nickCollName)}
	user := cmd.Message.Author
	guild := cmd.Guild
	s := cmd.Session
	if bits.GetBits(guild.ID, user.ID) < 200 {
		return "**FAILED TO CHANGE NICKNAME:** Insufficient bits.", nil
	}
	if (len(cmd.Args) < 1) || (cmd.Args[0] == "help") {
		return nickHelpString, nil
	}
	nickname := getNickName(cmd.Message.Content)
	upsertdata := bson.M{"$set": nicknameConfig{
		UserID:   user.ID,
		Nickname: nickname,
	}}
	nicknames.Upsert(nicknameConfig{UserID: user.ID}, upsertdata)
	err := s.GuildMemberNickname(guild.ID, user.ID, nickname)
	if err != nil {
		log.Errorf("Failed to update user's nickname: %v", err)
		return "**Failed to update user's nickname**", nil
	}
	bits.RemoveBits(s, guild.ID, user.ID, 200, "Changed nickname to "+nickname)
	return "", nil
}
Ejemplo n.º 3
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
}