From 112cf972ac386cd94dfdbe27d1c69059ecf01140 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 29 Jun 2016 03:12:38 +0200 Subject: [PATCH] default volume persists restarts --- NadekoBot/Classes/ServerSpecificConfig.cs | 13 +++++++++++++ NadekoBot/Modules/Music/MusicModule.cs | 9 +++------ NadekoBot/NadekoBot.csproj | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/NadekoBot/Classes/ServerSpecificConfig.cs b/NadekoBot/Classes/ServerSpecificConfig.cs index 47384bfd..e7e7437e 100644 --- a/NadekoBot/Classes/ServerSpecificConfig.cs +++ b/NadekoBot/Classes/ServerSpecificConfig.cs @@ -66,6 +66,7 @@ namespace NadekoBot.Classes get { return voicePlusTextEnabled; } set { voicePlusTextEnabled = value; + if (!SpecificConfigurations.Instantiated) return; OnPropertyChanged(); } } @@ -76,6 +77,7 @@ namespace NadekoBot.Classes get { return sendPrivateMessageOnMention; } set { sendPrivateMessageOnMention = value; + if (!SpecificConfigurations.Instantiated) return; OnPropertyChanged(); } } @@ -133,6 +135,17 @@ namespace NadekoBot.Classes } } + [JsonIgnore] + private float defaultMusicVolume = 1f; + public float DefaultMusicVolume { + get { return defaultMusicVolume; } + set { + defaultMusicVolume = value; + if (!SpecificConfigurations.Instantiated) return; + OnPropertyChanged(); + } + } + public ServerSpecificConfig() { ListOfSelfAssignableRoles = new ObservableCollection(); diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index 0241b870..bf88a5a6 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -19,7 +19,6 @@ namespace NadekoBot.Modules.Music { public static ConcurrentDictionary MusicPlayers = new ConcurrentDictionary(); - public static ConcurrentDictionary DefaultMusicVolumes = new ConcurrentDictionary(); public MusicModule() { @@ -200,7 +199,8 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage("Volume number invalid.").ConfigureAwait(false); return; } - DefaultMusicVolumes.AddOrUpdate(e.Server.Id, volume / 100, (key, newval) => volume / 100); + var conf = SpecificConfigurations.Default.Of(e.Server.Id); + conf.DefaultMusicVolume = volume / 100; await e.Channel.SendMessage($"🎵 `Default volume set to {volume}%`").ConfigureAwait(false); }); @@ -709,10 +709,7 @@ namespace NadekoBot.Modules.Music var musicPlayer = MusicPlayers.GetOrAdd(textCh.Server, server => { - float? vol = null; - float throwAway; - if (DefaultMusicVolumes.TryGetValue(server.Id, out throwAway)) - vol = throwAway; + float vol = SpecificConfigurations.Default.Of(server.Id).DefaultMusicVolume; var mp = new MusicPlayer(voiceCh, vol); diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 069d0758..3d57402e 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -136,7 +136,7 @@ - +