Exemplo n.º 1
0
// Execute executes the command with the given user and arguments.
// Return value descriptions:
//    string: A message to be returned to the user upon successful execution.
//    bool:   Whether the message should be private or not. true = private,
//            false = public (sent to whole channel).
//    error:  An error message to be returned upon unsuccessful execution.
//            If no error has occurred, pass nil instead.
// Example return statement:
//    return "This is a private message!", true, nil
func (c *VolumeCommand) Execute(user *gumble.User, args ...string) (string, bool, error) {
	if len(args) == 0 {
		// Send the user the current volume level.
		return fmt.Sprintf(viper.GetString("commands.volume.messages.current_volume"), DJ.Volume), true, nil
	}

	newVolume, err := strconv.ParseFloat(args[0], 32)
	if err != nil {
		return "", true, errors.New(viper.GetString("commands.volume.messages.parsing_error"))
	}

	if newVolume <= viper.GetFloat64("volume.lowest") || newVolume >= viper.GetFloat64("volume.highest") {
		return "", true, fmt.Errorf(viper.GetString("commands.volume.messages.out_of_range_error"),
			viper.GetFloat64("volume.lowest"), viper.GetFloat64("volume.highest"))
	}

	newVolume32 := float32(newVolume)

	if DJ.AudioStream != nil {
		DJ.AudioStream.Volume = newVolume32
	}
	DJ.Volume = newVolume32

	return fmt.Sprintf(viper.GetString("commands.volume.messages.volume_changed"),
		user.Name, newVolume32), false, nil
}
Exemplo n.º 2
0
// OnConnect event. First moves MumbleDJ into the default channel if one exists.
// The configuration is loaded and the audio stream is initialized.
func (dj *MumbleDJ) OnConnect(e *gumble.ConnectEvent) {
	dj.AudioStream = nil
	logrus.WithFields(logrus.Fields{
		"volume": fmt.Sprintf("%.2f", viper.GetFloat64("volume.default")),
	}).Infoln("Setting default volume...")
	dj.Volume = float32(viper.GetFloat64("volume.default"))

	if viper.GetBool("cache.enabled") {
		logrus.Infoln("Caching enabled.")
		dj.Cache.UpdateStatistics()
		go dj.Cache.CleanPeriodically()
	} else {
		logrus.Infoln("Caching disabled.")
	}
}
Exemplo n.º 3
0
// Run is the function to be run for the cli
func Run() {
	data, err := Near(
		viper.GetString("collection"),
		viper.GetFloat64("longitude"),
		viper.GetFloat64("latitude"),
		viper.GetFloat64("radius"),
	)
	if err != nil {
		log.Println("ERROR getting near", err)
		return
	}
	dump, err := json.MarshalIndent(data, "", "    ")
	if err != nil {
		log.Println("ERROR dumping near", err)
		return
	}
	fmt.Println(string(dump))
}
Exemplo n.º 4
0
func shouldCheckURLVersion(filePath string) bool {
	if !viper.GetBool(config.WantUpdateNotification) {
		return false
	}
	lastUpdateTime := getTimeFromFileIfExists(filePath)
	if time.Since(lastUpdateTime).Hours() < viper.GetFloat64(config.ReminderWaitPeriodInHours) {
		return false
	}
	return true
}
Exemplo n.º 5
0
func (s *SkipTracker) evaluatePlaylistSkips() {
	s.playlistMutex.RLock()
	skipRatio := viper.GetFloat64("queue.playlist_skip_ratio")
	DJ.Client.Do(func() {
		if float64(len(s.PlaylistSkips))/float64(len(DJ.Client.Self.Channel.Users)) >= skipRatio {
			DJ.Queue.SkipPlaylist()
		}
	})
	s.playlistMutex.RUnlock()
}
Exemplo n.º 6
0
func (s *SkipTracker) evaluateTrackSkips() {
	s.trackMutex.RLock()
	skipRatio := viper.GetFloat64("queue.track_skip_ratio")
	DJ.Client.Do(func() {
		if float64(len(s.TrackSkips))/float64(len(DJ.Client.Self.Channel.Users)) >= skipRatio {
			// Stopping an audio stream triggers a skip.
			DJ.Queue.StopCurrent()
		}
	})
	s.trackMutex.RUnlock()
}
Exemplo n.º 7
0
// CleanPeriodically loops forever, deleting expired cached audio files as necessary.
func (c *Cache) CleanPeriodically() {
	for range time.Tick(time.Duration(viper.GetInt("cache.check_interval")) * time.Minute) {
		logrus.Infoln("Checking cache for expired files...")
		files, _ := ioutil.ReadDir(os.ExpandEnv(viper.GetString("cache.directory")))
		for _, file := range files {
			// It is safe to check the modification time because when audio files are
			// played their modification time is updated. This ensures that audio
			// files will not get deleted while they are playing, assuming a reasonable
			// expiry time is set in the configuration.
			hours := time.Since(file.ModTime()).Hours()
			if hours >= viper.GetFloat64("cache.expire_time") {
				logrus.WithFields(logrus.Fields{
					"expired_file": file.Name(),
				}).Infoln("Removing expired cache entry.")
				os.Remove(fmt.Sprintf("%s/%s", os.ExpandEnv(viper.GetString("cache.directory")), file.Name()))
			}
		}
	}
}
Exemplo n.º 8
0
func createDriver(scheduler *eremeticScheduler) (*sched.MesosSchedulerDriver, error) {
	publishedAddr := net.ParseIP(viper.GetString("messenger_address"))
	bindingPort := uint16(viper.GetInt("messenger_port"))

	return sched.NewMesosSchedulerDriver(sched.DriverConfig{
		Master: viper.GetString("master"),
		Framework: &mesos.FrameworkInfo{
			Id:              getFrameworkID(),
			Name:            proto.String(viper.GetString("name")),
			User:            proto.String(viper.GetString("user")),
			Checkpoint:      proto.Bool(viper.GetBool("checkpoint")),
			FailoverTimeout: proto.Float64(viper.GetFloat64("failover_timeout")),
		},
		Scheduler:        scheduler,
		BindingAddress:   net.ParseIP("0.0.0.0"),
		PublishedAddress: publishedAddr,
		BindingPort:      bindingPort,
	})
}
Exemplo n.º 9
0
				return
			}

			var (
				smallest   bool
				complement bool
				items      []uint32
			)

			if q.Smallest {
				smallest = true
			} else if r.URL.Query().Get("smallest") != "" {
				smallest = true
			}

			var thres = viper.GetFloat64("main.smallest-threshold")

			if smallest && !res.Smallest(float32(thres)) {
				items = res.Complement()
				complement = true
			} else {
				items = res.Items()
			}

			resp := map[string]interface{}{
				"items":      items,
				"complement": complement,
			}

			if err = json.NewEncoder(w).Encode(resp); err != nil {
				w.WriteHeader(http.StatusInternalServerError)
Exemplo n.º 10
0
func (suite *VolumeCommandTestSuite) SetupTest() {
	DJ.Volume = float32(viper.GetFloat64("volume.default"))
}