NadekoBot/NadekoBot.Core/Modules/Administration/GameChannelCommands.cs

69 lines
2.2 KiB
C#
Raw Normal View History

2017-04-08 19:03:07 +00:00
using Discord;
using Discord.Commands;
using NadekoBot.Services;
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
{
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
{
_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;
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)
{
_service.GameVoiceChannels.TryRemove(vch.Id);
2017-04-08 19:03:07 +00:00
id = gc.GameVoiceChannel = null;
}
else
{
if(gc.GameVoiceChannel != null)
_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
{
_service.GameVoiceChannels.Add(vch.Id);
2017-04-08 19:03:07 +00:00
await ReplyConfirmLocalized("gvc_enabled", Format.Bold(vch.Name)).ConfigureAwait(false);
}
}
}
}
}