Fixed some stuff in rotating statuses, more optimal too
This commit is contained in:
parent
fd56e14fd3
commit
4001cf2e41
@ -22,6 +22,18 @@ namespace NadekoBot.Modules.Administration
|
|||||||
public class PlayingRotateCommands
|
public class PlayingRotateCommands
|
||||||
{
|
{
|
||||||
private Logger _log { get; }
|
private Logger _log { get; }
|
||||||
|
public static List<PlayingStatus> RotatingStatusMessages { get; }
|
||||||
|
public static bool RotatingStatuses { get; private set; } = false;
|
||||||
|
|
||||||
|
static PlayingRotateCommands()
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
var conf = uow.BotConfig.GetOrCreate();
|
||||||
|
RotatingStatusMessages = conf.RotatingStatusMessages;
|
||||||
|
RotatingStatuses = conf.RotatingStatuses;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PlayingRotateCommands()
|
public PlayingRotateCommands()
|
||||||
{
|
{
|
||||||
@ -33,22 +45,16 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BotConfig conf;
|
if (!RotatingStatuses)
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
|
||||||
conf = uow.BotConfig.GetOrCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!conf.RotatingStatuses)
|
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (index >= conf.RotatingStatusMessages.Count)
|
if (index >= RotatingStatusMessages.Count)
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
if (!conf.RotatingStatusMessages.Any())
|
if (!RotatingStatusMessages.Any())
|
||||||
continue;
|
continue;
|
||||||
var status = conf.RotatingStatusMessages[index++].Status;
|
var status = RotatingStatusMessages[index++].Status;
|
||||||
if (string.IsNullOrWhiteSpace(status))
|
if (string.IsNullOrWhiteSpace(status))
|
||||||
continue;
|
continue;
|
||||||
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
|
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
|
||||||
@ -95,15 +101,14 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
bool status;
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
var config = uow.BotConfig.GetOrCreate();
|
var config = uow.BotConfig.GetOrCreate();
|
||||||
|
|
||||||
status = config.RotatingStatuses = !config.RotatingStatuses;
|
RotatingStatuses = config.RotatingStatuses = !config.RotatingStatuses;
|
||||||
await uow.CompleteAsync();
|
await uow.CompleteAsync();
|
||||||
}
|
}
|
||||||
if (status)
|
if (RotatingStatuses)
|
||||||
await channel.SendMessageAsync("`Rotating playing status enabled.`");
|
await channel.SendMessageAsync("`Rotating playing status enabled.`");
|
||||||
else
|
else
|
||||||
await channel.SendMessageAsync("`Rotating playing status disabled.`");
|
await channel.SendMessageAsync("`Rotating playing status disabled.`");
|
||||||
@ -119,7 +124,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
var config = uow.BotConfig.GetOrCreate();
|
var config = uow.BotConfig.GetOrCreate();
|
||||||
config.RotatingStatusMessages.Add(new PlayingStatus { Status = status });
|
var toAdd = new PlayingStatus { Status = status };
|
||||||
|
config.RotatingStatusMessages.Add(toAdd);
|
||||||
|
RotatingStatusMessages.Add(toAdd);
|
||||||
await uow.CompleteAsync();
|
await uow.CompleteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,18 +140,13 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
List<PlayingStatus> statuses;
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
|
||||||
statuses = uow.BotConfig.GetOrCreate().RotatingStatusMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!statuses.Any())
|
if (!RotatingStatusMessages.Any())
|
||||||
await channel.SendMessageAsync("`No rotating playing statuses set.`");
|
await channel.SendMessageAsync("`No rotating playing statuses set.`");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var i = 1;
|
var i = 1;
|
||||||
await channel.SendMessageAsync($"{umsg.Author.Mention} `Here is a list of rotating statuses:`\n\n\t" + string.Join("\n\t", statuses.Select(rs => $"`{i++}.` {rs.Status}")));
|
await channel.SendMessageAsync($"{umsg.Author.Mention} `Here is a list of rotating statuses:`\n\n\t" + string.Join("\n\t", RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -166,6 +168,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
return;
|
return;
|
||||||
msg = config.RotatingStatusMessages[index].Status;
|
msg = config.RotatingStatusMessages[index].Status;
|
||||||
config.RotatingStatusMessages.RemoveAt(index);
|
config.RotatingStatusMessages.RemoveAt(index);
|
||||||
|
RotatingStatusMessages.RemoveAt(index);
|
||||||
await uow.CompleteAsync();
|
await uow.CompleteAsync();
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"`Removed the the playing message:` {msg}").ConfigureAwait(false);
|
await channel.SendMessageAsync($"`Removed the the playing message:` {msg}").ConfigureAwait(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user