default volume
This commit is contained in:
parent
260f57372a
commit
2e3fbc3411
@ -42,9 +42,11 @@ namespace NadekoBot.Classes.Music {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public MusicControls(Channel voiceChannel, CommandEventArgs e) : this() {
|
public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
|
||||||
if (voiceChannel == null)
|
if (voiceChannel == null)
|
||||||
throw new ArgumentNullException(nameof(voiceChannel));
|
throw new ArgumentNullException(nameof(voiceChannel));
|
||||||
|
if (vol != null)
|
||||||
|
Volume = (float)vol;
|
||||||
VoiceChannel = voiceChannel;
|
VoiceChannel = voiceChannel;
|
||||||
_e = e;
|
_e = e;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ namespace NadekoBot.Modules {
|
|||||||
class Music : DiscordModule {
|
class Music : DiscordModule {
|
||||||
|
|
||||||
public static ConcurrentDictionary<Server, MusicControls> musicPlayers = new ConcurrentDictionary<Server, MusicControls>();
|
public static ConcurrentDictionary<Server, MusicControls> musicPlayers = new ConcurrentDictionary<Server, MusicControls>();
|
||||||
|
public static ConcurrentDictionary<ulong, float> musicVolumes = new ConcurrentDictionary<ulong, float>();
|
||||||
|
|
||||||
internal static string GetMusicStats() {
|
internal static string GetMusicStats() {
|
||||||
var stats = musicPlayers.Where(kvp => kvp.Value?.SongQueue.Count > 0 || kvp.Value?.CurrentSong != null);
|
var stats = musicPlayers.Where(kvp => kvp.Value?.SongQueue.Count > 0 || kvp.Value?.CurrentSong != null);
|
||||||
@ -109,6 +110,21 @@ namespace NadekoBot.Modules {
|
|||||||
await e.Send($"🎵 `Volume set to {volume}%`");
|
await e.Send($"🎵 `Volume set to {volume}%`");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand("dv")
|
||||||
|
.Alias("defvol")
|
||||||
|
.Description("Sets the default music volume when music playback is started (0-100). Does not persist through restarts.\n**Usage**: !m dv 80")
|
||||||
|
.Parameter("val", ParameterType.Required)
|
||||||
|
.Do(async e => {
|
||||||
|
var arg = e.GetArg("val");
|
||||||
|
float volume;
|
||||||
|
if (!float.TryParse(arg, out volume) || volume < 0 || volume > 100) {
|
||||||
|
await e.Send("Volume number invalid.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
musicVolumes.AddOrUpdate(e.Server.Id, volume / 100, (key, newval) => volume / 100);
|
||||||
|
await e.Send($"🎵 `Default volume set to {volume}%`");
|
||||||
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("min").Alias("mute")
|
cgb.CreateCommand("min").Alias("mute")
|
||||||
.Description("Sets the music volume to 0%")
|
.Description("Sets the music volume to 0%")
|
||||||
.Do(e => {
|
.Do(e => {
|
||||||
@ -241,11 +257,17 @@ namespace NadekoBot.Modules {
|
|||||||
await e.Send("💢 You need to be in the voice channel on this server.");
|
await e.Send("💢 You need to be in the voice channel on this server.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (musicPlayers.ContainsKey(e.Server) == false)
|
if (musicPlayers.ContainsKey(e.Server) == false) {
|
||||||
if (!musicPlayers.TryAdd(e.Server, new MusicControls(e.User.VoiceChannel, e))) {
|
float? vol = null;
|
||||||
|
float throwAway;
|
||||||
|
if (musicVolumes.TryGetValue(e.Server.Id, out throwAway))
|
||||||
|
vol = throwAway;
|
||||||
|
|
||||||
|
if (!musicPlayers.TryAdd(e.Server, new MusicControls(e.User.VoiceChannel, e, vol))) {
|
||||||
await e.Send("Failed to create a music player for this server.");
|
await e.Send("Failed to create a music player for this server.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (query == null || query.Length < 3)
|
if (query == null || query.Length < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user