Exemplo n.º 1
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
}
Exemplo n.º 2
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
}
Exemplo n.º 3
0
func showBits(cmd *modulebase.ModuleCommand) (string, error) {
	w := &tabwriter.Writer{}
	buf := &bytes.Buffer{}
	w.Init(buf, 0, 3, 0, ' ', 0)
	fmt.Fprint(w, "```\n")

	if len(cmd.Args) == 0 {
		for _, b := range bits.GetBitsLeaderboard(cmd.Guild.ID, 10) {
			name := utils.GetPreferredName(cmd.Guild, b.UserID)
			if b.Value != nil && *b.Value != 0 {
				fmt.Fprintf(w, "%s: \t %d bits\n", name, *b.Value)
			}
		}
		fmt.Fprint(w, "```\n")
		w.Flush()
		return buf.String(), nil
	}

	var userId string
	if cmd.Args[0] == "me" {
		userId = cmd.Message.Author.ID
	} else if cmd.Args[0] == "help" {
		return showBitsHelpString, nil
	} else {
		return showBitsHelpString, nil
	}

	b := bits.GetBits(cmd.Guild.ID, userId)

	name := utils.GetPreferredName(cmd.Guild, userId)
	fmt.Fprintf(w, "%s: \t %d bits\n", name, b)

	fmt.Fprint(w, "```\n")
	w.Flush()
	return buf.String(), nil
}
Exemplo n.º 4
0
func store(cmd *modulebase.ModuleCommand) (string, error) {
	storeHelpString := `**BIT STORE**

    `
	var bitstring string
	user := cmd.Message.Author
	storeHelpString = storeHelpString + `**SILENCE SOUND EFFECTS**
    **usage:** !!s silence *duration*
    Prevents any sound clips from being played for *duration* minutes

    **COST:** `
	if bits.GetBits(cmd.Guild.ID, user.ID) < 100 {
		bitstring = "~~100 Bits per minute~~\n\n"
	} else {
		bitstring = "100 Bits per minute\n**YOU CAN AFFORD:** " + fmt.Sprintf("%v", bits.GetBits(cmd.Guild.ID, user.ID)/100) + " Minutes\n\n"
	}
	storeHelpString = storeHelpString + bitstring

	storeHelpString = storeHelpString + `**SET CUSTOM WELCOME MESSAGE**
    **usage:** !!greet myvoice *action* *<collection>* *<sound>*
    sets your greeting sound to *<collection>* *<sound>* (see !!s help)

    **COST:** `
	if bits.GetBits(cmd.Guild.ID, user.ID) < 150 {
		bitstring = "~~150 Bits~~\n\n"
	} else {
		bitstring = "150 Bits\n\n"
	}
	storeHelpString = storeHelpString + bitstring

	storeHelpString = storeHelpString + `**CHANGE NICKNAME**
    **usage:** !!nick *nickname*
    Changes user's nickname to *nickname*

    **COST:** `
	if bits.GetBits(cmd.Guild.ID, user.ID) < 200 {
		bitstring = "~~200 Bits~~\n\n"
	} else {
		bitstring = "200 Bits\n\n"
	}
	storeHelpString = storeHelpString + bitstring

	storeHelpString = storeHelpString + `**UPLOAD CUSTOM SOUND EFFECT**
    **usage:** put !!s upload *collection* *soundname* in the comments of an audio file attachment
    Processes the attached soundfile and adds it to the soundboard as *soundname* in the collection *collection*

    **COST:** `
	if bits.GetBits(cmd.Guild.ID, user.ID) < 300 {
		bitstring = "~~300 Bits~~\n\n"
	} else {
		bitstring = "300 Bits\n\n"
	}
	storeHelpString = storeHelpString + bitstring

	storeHelpString = storeHelpString + `**ADD CUSTOM TITLE**
    **usage:** !!role create *rolename* *color*
    Creates role with name *rolename* and color indicated by *color*. Then, gives user that role.
        **color names:** red, orange, yellow, green, blue, purple

    **COST:** `
	if bits.GetBits(cmd.Guild.ID, user.ID) < 650 {
		bitstring = "~~650 Bits~~\n\n"
	} else {
		bitstring = "650 Bits\n\n"
	}
	storeHelpString = storeHelpString + bitstring

	return storeHelpString, nil
}
Exemplo n.º 5
0
func voiceStateUpdateCallback(s *discordgo.Session, v *discordgo.VoiceStateUpdate) {
	log.Debugf("Voice bonus On voice state update: %v", v.VoiceState)

	// Check if it was a part
	if v.ChannelID == "" {
		return
	}

	guild, _ := s.State.Guild(v.GuildID)
	if guild == nil {
		log.WithFields(log.Fields{
			"guild": v.GuildID,
		}).Warning("Failed to grab guild")
		return
	}

	member, _ := s.State.Member(v.GuildID, v.UserID)
	if member == nil {
		log.WithFields(log.Fields{
			"member": member,
		}).Warning("Failed to grab member")
		return
	}

	if member.User.Bot {
		return
	}

	c := voicebonusCollection{ramendb.GetCollection(v.GuildID, ConfigName)}
	if !c.Enabled() {
		return
	}

	span := c.Timespan()
	if span == nil {
		log.Error("Timespan was nil for %v", guild.ID)
		return
	}

	log.Debugf("Timespan is: %v", span)

	currentTime := time.Now().UTC()

	year, month, day := currentTime.Date()
	weekday := currentTime.Weekday()
	nextDay := day + utils.GetDaysTillWeekday(int(weekday), span.Weekday)
	startDate := time.Date(year, month, nextDay, span.Hour, span.Minute, 0, 0, time.UTC)
	previousDate := time.Date(year, month, nextDay-7, span.Hour, span.Minute, 0, 0, time.UTC)

	log.Debugf("Start Date is: %v", startDate)
	log.Debugf("Previous Date is: %v", previousDate)

	lastJoinTime := time.Unix(getUserLastJoin(v.GuildID, v.UserID), 0)

	log.Debugf("Last join date: %v, now: %v", lastJoinTime, currentTime)

	if currentTime.Before(startDate) {
		// Check for previous week parts. Needed if timespan crosses UTC midnight
		if time.Since(previousDate).Hours() > float64(span.Duration) ||
			lastJoinTime.After(previousDate) {

			log.Debugf("Previous time status: %v %v",
				time.Since(previousDate).Hours() > float64(span.Duration),
				lastJoinTime.After(previousDate))
			return
		}
	} else if time.Since(startDate).Hours() > float64(span.Duration) ||
		lastJoinTime.After(startDate) {

		log.Debugf("Current time status: %v %v",
			time.Since(startDate).Hours() > float64(span.Duration),
			lastJoinTime.After(startDate))
		return
	}

	log.Debug("Giving bits for join")
	bits.AddBits(s, v.GuildID, v.UserID, c.Amount(), "Voice join bonus", true)

	username := utils.GetPreferredName(guild, v.UserID)
	message := fmt.Sprintf(joinMessage, username, c.Amount(),
		bits.GetBits(v.GuildID, v.UserID))

	channel, _ := s.UserChannelCreate(v.UserID)
	s.ChannelMessageSend(channel.ID, message)

	updateUserLastJoin(v.GuildID, v.UserID, currentTime.Unix())
}