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