2016-12-13 03:49:44 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
2016-12-13 03:49:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Administration.Services;
|
2016-12-13 03:49:44 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
|
|
|
|
public partial class Administration
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public class MuteCommands : NadekoSubmodule<MuteService>
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
2016-12-13 03:49:44 +00:00
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public MuteCommands(DbService db)
|
2017-03-10 22:06:22 +00:00
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
_db = db;
|
2017-03-10 22:06:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-13 03:49:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(0)]
|
2016-12-21 08:33:47 +00:00
|
|
|
|
public async Task SetMuteRole([Remainder] string name)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
|
|
|
|
name = name.Trim();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
2016-12-16 21:44:26 +00:00
|
|
|
|
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
config.MuteRoleName = name;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
_service.GuildMuteRoles.AddOrUpdate(Context.Guild.Id, name, (id, old) => name);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("mute_role_set").ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(1)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public Task SetMuteRole([Remainder] IRole role)
|
2016-12-21 08:33:47 +00:00
|
|
|
|
=> SetMuteRole(role.Name);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.MuteMembers)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(0)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task Mute(IGuildUser user)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _service.MuteUser(user).ConfigureAwait(false);
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("user_muted", Format.Bold(user.ToString())).ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 22:06:22 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.MuteMembers)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(1)]
|
2017-03-10 22:06:22 +00:00
|
|
|
|
public async Task Mute(int minutes, IGuildUser user)
|
|
|
|
|
{
|
2017-03-10 22:10:42 +00:00
|
|
|
|
if (minutes < 1 || minutes > 1440)
|
2017-03-10 22:06:22 +00:00
|
|
|
|
return;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _service.TimedMute(user, TimeSpan.FromMinutes(minutes)).ConfigureAwait(false);
|
2017-03-10 22:06:22 +00:00
|
|
|
|
await ReplyConfirmLocalized("user_muted_time", Format.Bold(user.ToString()), minutes).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_log.Warn(ex);
|
|
|
|
|
await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-13 03:49:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.MuteMembers)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task Unmute(IGuildUser user)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _service.UnmuteUser(user).ConfigureAwait(false);
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("user_unmuted", Format.Bold(user.ToString())).ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task ChatMute(IGuildUser user)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _service.MuteUser(user, MuteType.Chat).ConfigureAwait(false);
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("user_chat_mute", Format.Bold(user.ToString())).ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task ChatUnmute(IGuildUser user)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _service.UnmuteUser(user, MuteType.Chat).ConfigureAwait(false);
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("user_chat_unmute", Format.Bold(user.ToString())).ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.MuteMembers)]
|
2017-05-27 08:19:27 +00:00
|
|
|
|
public async Task VoiceMute([Remainder] IGuildUser user)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _service.MuteUser(user, MuteType.Voice).ConfigureAwait(false);
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("user_voice_mute", Format.Bold(user.ToString())).ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.MuteMembers)]
|
2017-05-27 08:19:27 +00:00
|
|
|
|
public async Task VoiceUnmute([Remainder] IGuildUser user)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _service.UnmuteUser(user, MuteType.Voice).ConfigureAwait(false);
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("user_voice_unmute", Format.Bold(user.ToString())).ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-02-14 15:36:02 +00:00
|
|
|
|
await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|