From 86a140f8bb1fbb96a762bd799d46683d68cd476c Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 6 Mar 2016 11:53:45 +0100 Subject: [PATCH] saving rotating playing status and state. --- NadekoBot/Classes/JSONModels/Configuration.cs | 13 ++++--- NadekoBot/Commands/PlayingRotate.cs | 34 +++++++++++-------- NadekoBot/bin/Debug/data/config_example.json | 2 ++ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/NadekoBot/Classes/JSONModels/Configuration.cs b/NadekoBot/Classes/JSONModels/Configuration.cs index 217e6a33..1ab910f6 100644 --- a/NadekoBot/Classes/JSONModels/Configuration.cs +++ b/NadekoBot/Classes/JSONModels/Configuration.cs @@ -3,15 +3,18 @@ using System.Collections.Generic; namespace NadekoBot.Classes.JSONModels { public class Configuration { - public bool DontJoinServers = false; - public bool ForwardMessages = true; - public HashSet ServerBlacklist = new HashSet(); - public HashSet ChannelBlacklist = new HashSet(); - public HashSet UserBlacklist = new HashSet() { + public bool DontJoinServers { get; set; } = false; + public bool ForwardMessages { get; set; } = true; + public bool IsRotatingStatus { get; set; } = false; + public List RotatingStatuses { get; set; } = new List(); + public HashSet ServerBlacklist { get; set; } = new HashSet(); + public HashSet ChannelBlacklist { get; set; } = new HashSet(); + public HashSet UserBlacklist { get; set; } = new HashSet() { 105309315895693312, 119174277298782216, 143515953525817344 }; + public string[] CryResponses { get; } = { "http://i.imgur.com/Xg3i1Qy.gif", "http://i.imgur.com/3K8DRrU.gif", diff --git a/NadekoBot/Commands/PlayingRotate.cs b/NadekoBot/Commands/PlayingRotate.cs index 36935fc2..8cd5384e 100644 --- a/NadekoBot/Commands/PlayingRotate.cs +++ b/NadekoBot/Commands/PlayingRotate.cs @@ -9,8 +9,6 @@ using NadekoBot.Modules; namespace NadekoBot.Commands { internal class PlayingRotate : IDiscordCommand { - - private static readonly List rotatingStatuses = new List(); private static readonly Timer timer = new Timer(12000); public static Dictionary> PlayingPlaceholders { get; } = @@ -48,7 +46,7 @@ namespace NadekoBot.Commands { i = -1; return; } - status = rotatingStatuses[i]; + status = NadekoBot.Config.RotatingStatuses[i]; status = PlayingPlaceholders.Aggregate(status, (current, kvp) => current.Replace(kvp.Key, kvp.Value())); } @@ -57,13 +55,19 @@ namespace NadekoBot.Commands { Task.Run(() => { NadekoBot.Client.SetGame(status); }); } catch { } }; + + timer.Enabled = NadekoBot.Config.IsRotatingStatus; } public Func DoFunc() => async e => { - if (timer.Enabled) - timer.Stop(); - else - timer.Start(); + lock (playingPlaceholderLock) { + if (timer.Enabled) + timer.Stop(); + else + timer.Start(); + NadekoBot.Config.IsRotatingStatus = timer.Enabled; + NadekoBot.SaveConfig(); + } await e.Channel.SendMessage($"❗`Rotating playing status has been {(timer.Enabled ? "enabled" : "disabled")}.`"); }; @@ -85,7 +89,8 @@ namespace NadekoBot.Commands { if (string.IsNullOrWhiteSpace(arg)) return; lock (playingPlaceholderLock) { - rotatingStatuses.Add(arg); + NadekoBot.Config.RotatingStatuses.Add(arg); + NadekoBot.SaveConfig(); } await e.Channel.SendMessage("🆗 `Added a new playing string.`"); }); @@ -95,12 +100,12 @@ namespace NadekoBot.Commands { .Description("Lists all playing statuses with their corresponding number.") .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly()) .Do(async e => { - if (rotatingStatuses.Count == 0) + if (NadekoBot.Config.RotatingStatuses.Count == 0) await e.Channel.SendMessage("`There are no playing strings. " + "Add some with .addplaying [text] command.`"); var sb = new StringBuilder(); - for (var i = 0; i < rotatingStatuses.Count; i++) { - sb.AppendLine($"`{i + 1}.` {rotatingStatuses[i]}"); + for (var i = 0; i < NadekoBot.Config.RotatingStatuses.Count; i++) { + sb.AppendLine($"`{i + 1}.` {NadekoBot.Config.RotatingStatuses[i]}"); } await e.Channel.SendMessage(sb.ToString()); }); @@ -115,10 +120,11 @@ namespace NadekoBot.Commands { int num; string str; lock (playingPlaceholderLock) { - if (!int.TryParse(arg.Trim(), out num) || num <= 0 || num > rotatingStatuses.Count) + if (!int.TryParse(arg.Trim(), out num) || num <= 0 || num > NadekoBot.Config.RotatingStatuses.Count) return; - str = rotatingStatuses[num - 1]; - rotatingStatuses.RemoveAt(num - 1); + str = NadekoBot.Config.RotatingStatuses[num - 1]; + NadekoBot.Config.RotatingStatuses.RemoveAt(num - 1); + NadekoBot.SaveConfig(); } await e.Channel.SendMessage($"🆗 `Removed playing string #{num}`({str})"); }); diff --git a/NadekoBot/bin/Debug/data/config_example.json b/NadekoBot/bin/Debug/data/config_example.json index efe8ee65..185bca8d 100644 --- a/NadekoBot/bin/Debug/data/config_example.json +++ b/NadekoBot/bin/Debug/data/config_example.json @@ -1,6 +1,8 @@ { "DontJoinServers": false, "ForwardMessages": true, + "IsRotatingStatus": false, + "RotatingStatuses": [], "ServerBlacklist": [], "ChannelBlacklist": [], "UserBlacklist": [