saving rotating playing status and state.

This commit is contained in:
Master Kwoth 2016-03-06 11:53:45 +01:00
parent c75676e7f5
commit 86a140f8bb
3 changed files with 30 additions and 19 deletions

View File

@ -3,15 +3,18 @@ using System.Collections.Generic;
namespace NadekoBot.Classes.JSONModels { namespace NadekoBot.Classes.JSONModels {
public class Configuration { public class Configuration {
public bool DontJoinServers = false; public bool DontJoinServers { get; set; } = false;
public bool ForwardMessages = true; public bool ForwardMessages { get; set; } = true;
public HashSet<ulong> ServerBlacklist = new HashSet<ulong>(); public bool IsRotatingStatus { get; set; } = false;
public HashSet<ulong> ChannelBlacklist = new HashSet<ulong>(); public List<string> RotatingStatuses { get; set; } = new List<string>();
public HashSet<ulong> UserBlacklist = new HashSet<ulong>() { public HashSet<ulong> ServerBlacklist { get; set; } = new HashSet<ulong>();
public HashSet<ulong> ChannelBlacklist { get; set; } = new HashSet<ulong>();
public HashSet<ulong> UserBlacklist { get; set; } = new HashSet<ulong>() {
105309315895693312, 105309315895693312,
119174277298782216, 119174277298782216,
143515953525817344 143515953525817344
}; };
public string[] CryResponses { get; } = { public string[] CryResponses { get; } = {
"http://i.imgur.com/Xg3i1Qy.gif", "http://i.imgur.com/Xg3i1Qy.gif",
"http://i.imgur.com/3K8DRrU.gif", "http://i.imgur.com/3K8DRrU.gif",

View File

@ -9,8 +9,6 @@ using NadekoBot.Modules;
namespace NadekoBot.Commands { namespace NadekoBot.Commands {
internal class PlayingRotate : IDiscordCommand { internal class PlayingRotate : IDiscordCommand {
private static readonly List<string> rotatingStatuses = new List<string>();
private static readonly Timer timer = new Timer(12000); private static readonly Timer timer = new Timer(12000);
public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } = public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } =
@ -48,7 +46,7 @@ namespace NadekoBot.Commands {
i = -1; i = -1;
return; return;
} }
status = rotatingStatuses[i]; status = NadekoBot.Config.RotatingStatuses[i];
status = PlayingPlaceholders.Aggregate(status, status = PlayingPlaceholders.Aggregate(status,
(current, kvp) => current.Replace(kvp.Key, kvp.Value())); (current, kvp) => current.Replace(kvp.Key, kvp.Value()));
} }
@ -57,13 +55,19 @@ namespace NadekoBot.Commands {
Task.Run(() => { NadekoBot.Client.SetGame(status); }); Task.Run(() => { NadekoBot.Client.SetGame(status); });
} catch { } } catch { }
}; };
timer.Enabled = NadekoBot.Config.IsRotatingStatus;
} }
public Func<CommandEventArgs, Task> DoFunc() => async e => { public Func<CommandEventArgs, Task> DoFunc() => async e => {
lock (playingPlaceholderLock) {
if (timer.Enabled) if (timer.Enabled)
timer.Stop(); timer.Stop();
else else
timer.Start(); timer.Start();
NadekoBot.Config.IsRotatingStatus = timer.Enabled;
NadekoBot.SaveConfig();
}
await e.Channel.SendMessage($"❗`Rotating playing status has been {(timer.Enabled ? "enabled" : "disabled")}.`"); await e.Channel.SendMessage($"❗`Rotating playing status has been {(timer.Enabled ? "enabled" : "disabled")}.`");
}; };
@ -85,7 +89,8 @@ namespace NadekoBot.Commands {
if (string.IsNullOrWhiteSpace(arg)) if (string.IsNullOrWhiteSpace(arg))
return; return;
lock (playingPlaceholderLock) { lock (playingPlaceholderLock) {
rotatingStatuses.Add(arg); NadekoBot.Config.RotatingStatuses.Add(arg);
NadekoBot.SaveConfig();
} }
await e.Channel.SendMessage("🆗 `Added a new playing string.`"); 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.") .Description("Lists all playing statuses with their corresponding number.")
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly()) .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e => {
if (rotatingStatuses.Count == 0) if (NadekoBot.Config.RotatingStatuses.Count == 0)
await e.Channel.SendMessage("`There are no playing strings. " + await e.Channel.SendMessage("`There are no playing strings. " +
"Add some with .addplaying [text] command.`"); "Add some with .addplaying [text] command.`");
var sb = new StringBuilder(); var sb = new StringBuilder();
for (var i = 0; i < rotatingStatuses.Count; i++) { for (var i = 0; i < NadekoBot.Config.RotatingStatuses.Count; i++) {
sb.AppendLine($"`{i + 1}.` {rotatingStatuses[i]}"); sb.AppendLine($"`{i + 1}.` {NadekoBot.Config.RotatingStatuses[i]}");
} }
await e.Channel.SendMessage(sb.ToString()); await e.Channel.SendMessage(sb.ToString());
}); });
@ -115,10 +120,11 @@ namespace NadekoBot.Commands {
int num; int num;
string str; string str;
lock (playingPlaceholderLock) { 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; return;
str = rotatingStatuses[num - 1]; str = NadekoBot.Config.RotatingStatuses[num - 1];
rotatingStatuses.RemoveAt(num - 1); NadekoBot.Config.RotatingStatuses.RemoveAt(num - 1);
NadekoBot.SaveConfig();
} }
await e.Channel.SendMessage($"🆗 `Removed playing string #{num}`({str})"); await e.Channel.SendMessage($"🆗 `Removed playing string #{num}`({str})");
}); });

View File

@ -1,6 +1,8 @@
{ {
"DontJoinServers": false, "DontJoinServers": false,
"ForwardMessages": true, "ForwardMessages": true,
"IsRotatingStatus": false,
"RotatingStatuses": [],
"ServerBlacklist": [], "ServerBlacklist": [],
"ChannelBlacklist": [], "ChannelBlacklist": [],
"UserBlacklist": [ "UserBlacklist": [