saving rotating playing status and state.
This commit is contained in:
parent
c75676e7f5
commit
86a140f8bb
@ -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<ulong> ServerBlacklist = new HashSet<ulong>();
|
||||
public HashSet<ulong> ChannelBlacklist = new HashSet<ulong>();
|
||||
public HashSet<ulong> UserBlacklist = new HashSet<ulong>() {
|
||||
public bool DontJoinServers { get; set; } = false;
|
||||
public bool ForwardMessages { get; set; } = true;
|
||||
public bool IsRotatingStatus { get; set; } = false;
|
||||
public List<string> RotatingStatuses { get; set; } = new List<string>();
|
||||
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,
|
||||
119174277298782216,
|
||||
143515953525817344
|
||||
};
|
||||
|
||||
public string[] CryResponses { get; } = {
|
||||
"http://i.imgur.com/Xg3i1Qy.gif",
|
||||
"http://i.imgur.com/3K8DRrU.gif",
|
||||
|
@ -9,8 +9,6 @@ using NadekoBot.Modules;
|
||||
|
||||
namespace NadekoBot.Commands {
|
||||
internal class PlayingRotate : IDiscordCommand {
|
||||
|
||||
private static readonly List<string> rotatingStatuses = new List<string>();
|
||||
private static readonly Timer timer = new Timer(12000);
|
||||
|
||||
public static Dictionary<string, Func<string>> 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<CommandEventArgs, Task> DoFunc() => async e => {
|
||||
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})");
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
{
|
||||
"DontJoinServers": false,
|
||||
"ForwardMessages": true,
|
||||
"IsRotatingStatus": false,
|
||||
"RotatingStatuses": [],
|
||||
"ServerBlacklist": [],
|
||||
"ChannelBlacklist": [],
|
||||
"UserBlacklist": [
|
||||
|
Loading…
Reference in New Issue
Block a user