NadekoBot/NadekoBot.Core/Modules/Administration/PlayingRotateCommands.cs

94 lines
3.2 KiB
C#
Raw Normal View History

2017-02-14 18:54:02 +00:00
using Discord.Commands;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
2016-08-27 00:41:41 +00:00
using System.Linq;
using System.Threading.Tasks;
2017-07-17 19:42:36 +00:00
using NadekoBot.Common.Attributes;
using NadekoBot.Modules.Administration.Services;
2016-08-27 00:41:41 +00:00
namespace NadekoBot.Modules.Administration
{
public partial class Administration
{
[Group]
2017-07-15 16:34:34 +00:00
public class PlayingRotateCommands : NadekoSubmodule<PlayingRotateService>
2016-08-27 00:41:41 +00:00
{
private static readonly object _locker = new object();
private readonly DbService _db;
2017-02-05 05:36:07 +00:00
2017-07-15 16:34:34 +00:00
public PlayingRotateCommands(DbService db)
2017-02-05 05:36:07 +00:00
{
_db = db;
2017-02-05 05:36:07 +00:00
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
2016-12-16 18:43:57 +00:00
public async Task RotatePlaying()
2016-08-27 00:41:41 +00:00
{
2017-06-30 03:40:17 +00:00
bool enabled;
using (var uow = _db.UnitOfWork)
2016-08-27 00:41:41 +00:00
{
2017-06-30 03:40:17 +00:00
var config = uow.BotConfig.GetOrCreate();
2017-06-30 03:40:17 +00:00
enabled = config.RotatingStatuses = !config.RotatingStatuses;
uow.Complete();
2016-08-27 00:41:41 +00:00
}
2017-06-30 03:40:17 +00:00
if (enabled)
2017-02-14 18:54:02 +00:00
await ReplyConfirmLocalized("ropl_enabled").ConfigureAwait(false);
else
2017-02-14 18:54:02 +00:00
await ReplyConfirmLocalized("ropl_disabled").ConfigureAwait(false);
2016-08-27 00:41:41 +00:00
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task AddPlaying([Remainder] string status)
2016-08-27 00:41:41 +00:00
{
using (var uow = _db.UnitOfWork)
2016-08-27 00:41:41 +00:00
{
var config = uow.BotConfig.GetOrCreate();
var toAdd = new PlayingStatus { Status = status };
config.RotatingStatusMessages.Add(toAdd);
2016-08-27 00:41:41 +00:00
await uow.CompleteAsync();
}
2017-02-14 18:54:02 +00:00
await ReplyConfirmLocalized("ropl_added").ConfigureAwait(false);
2016-08-27 00:41:41 +00:00
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
2016-12-16 18:43:57 +00:00
public async Task ListPlaying()
2016-08-27 00:41:41 +00:00
{
if (!_service.BotConfig.RotatingStatusMessages.Any())
2017-02-14 18:54:02 +00:00
await ReplyErrorLocalized("ropl_not_set").ConfigureAwait(false);
2016-08-27 00:41:41 +00:00
else
{
var i = 1;
2017-02-14 18:54:02 +00:00
await ReplyConfirmLocalized("ropl_list",
string.Join("\n\t", _service.BotConfig.RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}")))
2017-02-14 18:54:02 +00:00
.ConfigureAwait(false);
2016-08-27 00:41:41 +00:00
}
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task RemovePlaying(int index)
2016-08-27 00:41:41 +00:00
{
index -= 1;
2016-08-27 00:41:41 +00:00
2017-02-14 18:54:02 +00:00
string msg;
using (var uow = _db.UnitOfWork)
2016-08-27 00:41:41 +00:00
{
var config = uow.BotConfig.GetOrCreate();
2016-08-27 00:41:41 +00:00
if (index >= config.RotatingStatusMessages.Count)
return;
msg = config.RotatingStatusMessages[index].Status;
2016-08-27 00:41:41 +00:00
config.RotatingStatusMessages.RemoveAt(index);
await uow.CompleteAsync();
}
2017-02-14 18:54:02 +00:00
await ReplyConfirmLocalized("reprm", msg).ConfigureAwait(false);
2016-08-27 00:41:41 +00:00
}
}
}
2017-01-23 01:04:15 +00:00
}