2017-02-14 18:54:02 +00:00
|
|
|
|
using Discord.Commands;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
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;
|
2017-10-26 09:31:44 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2016-02-24 16:33:09 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2017-05-27 17:42:23 +00:00
|
|
|
|
private static readonly object _locker = new object();
|
2017-05-29 04:13:22 +00:00
|
|
|
|
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
|
|
|
|
{
|
2017-05-27 17:42:23 +00:00
|
|
|
|
_db = db;
|
2017-02-05 05:36:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[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-10-26 09:31:44 +00:00
|
|
|
|
var config = uow.BotConfig.GetOrCreate(set => set);
|
2016-02-24 16:33:09 +00:00
|
|
|
|
|
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);
|
2016-08-28 00:46:36 +00:00
|
|
|
|
else
|
2017-02-14 18:54:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("ropl_disabled").ConfigureAwait(false);
|
2016-08-27 00:41:41 +00:00
|
|
|
|
}
|
2016-03-06 10:53:45 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[OwnerOnly]
|
2016-12-21 08:33:47 +00:00
|
|
|
|
public async Task AddPlaying([Remainder] string status)
|
2016-08-27 00:41:41 +00:00
|
|
|
|
{
|
2017-05-27 17:42:23 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-08-27 00:41:41 +00:00
|
|
|
|
{
|
2017-10-26 09:31:44 +00:00
|
|
|
|
var config = uow.BotConfig.GetOrCreate(set => set.Include(x => x.RotatingStatusMessages));
|
2016-10-14 23:20:06 +00:00
|
|
|
|
var toAdd = new PlayingStatus { Status = status };
|
|
|
|
|
config.RotatingStatusMessages.Add(toAdd);
|
2016-08-27 00:41:41 +00:00
|
|
|
|
await uow.CompleteAsync();
|
|
|
|
|
}
|
2016-02-24 16:33:09 +00:00
|
|
|
|
|
2017-02-14 18:54:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("ropl_added").ConfigureAwait(false);
|
2016-08-27 00:41:41 +00:00
|
|
|
|
}
|
2016-02-24 16:33:09 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[OwnerOnly]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task ListPlaying()
|
2016-08-27 00:41:41 +00:00
|
|
|
|
{
|
2017-06-28 00:44:30 +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",
|
2017-06-28 00:44:30 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[OwnerOnly]
|
2016-12-21 08:33:47 +00:00
|
|
|
|
public async Task RemovePlaying(int index)
|
2016-08-27 00:41:41 +00:00
|
|
|
|
{
|
2016-08-28 00:46:36 +00:00
|
|
|
|
index -= 1;
|
2016-08-27 00:41:41 +00:00
|
|
|
|
|
2017-02-14 18:54:02 +00:00
|
|
|
|
string msg;
|
2017-05-27 17:42:23 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-08-27 00:41:41 +00:00
|
|
|
|
{
|
2017-10-26 09:31:44 +00:00
|
|
|
|
var config = uow.BotConfig.GetOrCreate(set => set.Include(x => x.RotatingStatusMessages));
|
2016-08-27 00:41:41 +00:00
|
|
|
|
|
|
|
|
|
if (index >= config.RotatingStatusMessages.Count)
|
|
|
|
|
return;
|
2016-08-28 00:46:36 +00:00
|
|
|
|
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
|
|
|
|
}
|