2017-04-08 19:03:07 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
2017-04-08 19:03:07 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Administration.Services;
|
2017-04-08 19:03:07 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
|
|
|
|
public partial class Administration
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public class GameChannelCommands : NadekoSubmodule<GameVoiceChannelService>
|
2017-04-08 19:03:07 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
2017-04-08 19:03:07 +00:00
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public GameChannelCommands(DbService db)
|
2017-04-08 19:03:07 +00:00
|
|
|
|
{
|
2017-05-27 17:42:23 +00:00
|
|
|
|
_db = db;
|
2017-04-08 19:03:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
|
|
|
|
[RequireBotPermission(GuildPermission.MoveMembers)]
|
|
|
|
|
public async Task GameVoiceChannel()
|
|
|
|
|
{
|
|
|
|
|
var vch = ((IGuildUser)Context.User).VoiceChannel;
|
|
|
|
|
|
|
|
|
|
if (vch == null)
|
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("not_in_voice").ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ulong? id;
|
2017-05-27 17:42:23 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-04-08 19:03:07 +00:00
|
|
|
|
{
|
|
|
|
|
var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set);
|
|
|
|
|
|
|
|
|
|
if (gc.GameVoiceChannel == vch.Id)
|
|
|
|
|
{
|
2017-05-27 17:42:23 +00:00
|
|
|
|
_service.GameVoiceChannels.TryRemove(vch.Id);
|
2017-04-08 19:03:07 +00:00
|
|
|
|
id = gc.GameVoiceChannel = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(gc.GameVoiceChannel != null)
|
2017-05-27 17:42:23 +00:00
|
|
|
|
_service.GameVoiceChannels.TryRemove(gc.GameVoiceChannel.Value);
|
|
|
|
|
_service.GameVoiceChannels.Add(vch.Id);
|
2017-04-08 19:03:07 +00:00
|
|
|
|
id = gc.GameVoiceChannel = vch.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("gvc_disabled").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-27 17:42:23 +00:00
|
|
|
|
_service.GameVoiceChannels.Add(vch.Id);
|
2017-04-08 19:03:07 +00:00
|
|
|
|
await ReplyConfirmLocalized("gvc_enabled", Format.Bold(vch.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|