diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index dc230866..fb31e9ba 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -52,6 +52,23 @@ namespace NadekoBot.Modules.Administration } } + private static async Task GetMuteRole(IGuild guild) + { + var muteRole = guild.Roles.FirstOrDefault(r => r.Name == "nadeko-mute"); + if (muteRole == null) + { + muteRole = await guild.CreateRoleAsync("nadeko-mute", GuildPermissions.None).ConfigureAwait(false); + + foreach (var toOverwrite in guild.GetTextChannels()) + { + await toOverwrite.AddPermissionOverwriteAsync(muteRole, new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny)) + .ConfigureAwait(false); + await Task.Delay(200).ConfigureAwait(false); + } + } + return muteRole; + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.Administrator)] @@ -257,9 +274,13 @@ namespace NadekoBot.Modules.Administration { msg = "No reason provided."; } - await (await user.CreateDMChannelAsync()).SendMessageAsync($"**You have been BANNED from `{channel.Guild.Name}` server.**\n" + - $"Reason: {msg}").ConfigureAwait(false); - await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt + try + { + await (await user.CreateDMChannelAsync()).SendMessageAsync($"**You have been BANNED from `{channel.Guild.Name}` server.**\n" + + $"Reason: {msg}").ConfigureAwait(false); + await Task.Delay(2000).ConfigureAwait(false); + } + catch { } try { await channel.Guild.AddBanAsync(user, 7).ConfigureAwait(false); @@ -282,13 +303,18 @@ namespace NadekoBot.Modules.Administration { msg = "No reason provided."; } - await user.SendMessageAsync($"**You have been SOFT-BANNED from `{channel.Guild.Name}` server.**\n" + - $"Reason: {msg}").ConfigureAwait(false); - await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt + try + { + await user.SendMessageAsync($"**You have been SOFT-BANNED from `{channel.Guild.Name}` server.**\n" + + $"Reason: {msg}").ConfigureAwait(false); + await Task.Delay(2000).ConfigureAwait(false); + } + catch { } try { await channel.Guild.AddBanAsync(user, 7).ConfigureAwait(false); - await channel.Guild.RemoveBanAsync(user).ConfigureAwait(false); + try { await channel.Guild.RemoveBanAsync(user).ConfigureAwait(false); } + catch { await channel.Guild.RemoveBanAsync(user).ConfigureAwait(false); } await channel.SendMessageAsync("Soft-Banned user " + user.Username + " Id: " + user.Id).ConfigureAwait(false); } @@ -312,9 +338,13 @@ namespace NadekoBot.Modules.Administration } if (!string.IsNullOrWhiteSpace(msg)) { - await user.SendMessageAsync($"**You have been KICKED from `{channel.Guild.Name}` server.**\n" + - $"Reason: {msg}").ConfigureAwait(false); - await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt + try + { + await user.SendMessageAsync($"**You have been KICKED from `{channel.Guild.Name}` server.**\n" + + $"Reason: {msg}").ConfigureAwait(false); + await Task.Delay(2000).ConfigureAwait(false); + } + catch { } } try { @@ -330,19 +360,51 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.MuteMembers)] - public async Task Mute(IUserMessage umsg, params IGuildUser[] users) + public async Task Mute(IUserMessage umsg, IGuildUser user) { var channel = (ITextChannel)umsg.Channel; - if (!users.Any()) - return; try { - foreach (var u in users) - { - await u.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false); - } - await channel.SendMessageAsync("Mute successful").ConfigureAwait(false); + await user.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false); + await user.AddRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); + await channel.SendMessageAsync($"**{user}** was text and voice muted successfully.").ConfigureAwait(false); + } + catch + { + await channel.SendMessageAsync("I most likely don't have the permission necessary for that.").ConfigureAwait(false); + } + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.MuteMembers)] + public async Task TextMute(IUserMessage umsg, IGuildUser user) + { + var channel = (ITextChannel)umsg.Channel; + + try + { + await user.AddRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); + await channel.SendMessageAsync($"**{user}** was text muted successfully.").ConfigureAwait(false); + } + catch + { + await channel.SendMessageAsync("I most likely don't have the permission necessary for that.").ConfigureAwait(false); + } + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.MuteMembers)] + public async Task VoiceMute(IUserMessage umsg, IGuildUser user) + { + var channel = (ITextChannel)umsg.Channel; + + try + { + await user.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false); + await channel.SendMessageAsync($"**{user}** was voice muted successfully.").ConfigureAwait(false); } catch { diff --git a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs index e358ef83..affbac7f 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs @@ -252,19 +252,6 @@ namespace NadekoBot.Modules.Administration .ConfigureAwait(false); } - private async Task GetMuteRole(IGuild guild) - { - var muteRole = guild.Roles.FirstOrDefault(r => r.Name == "nadeko-mute") ?? - await guild.CreateRoleAsync("nadeko-mute", GuildPermissions.None).ConfigureAwait(false); - foreach (var toOverwrite in guild.GetTextChannels()) - { - await toOverwrite.AddPermissionOverwriteAsync(muteRole, new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny)) - .ConfigureAwait(false); - await Task.Delay(200).ConfigureAwait(false); - } - return muteRole; - } - [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.Administrator)] diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index c0bdbdcd..0a05ffdb 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -4308,7 +4308,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Mutes a mentioned user in a voice channel.. + /// Looks up a localized string similar to Mutes a mentioned user both fom speaking and chatting.. /// public static string mute_desc { get { @@ -6755,6 +6755,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to textmute. + /// + public static string textmute_cmd { + get { + return ResourceManager.GetString("textmute_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Prevents a mentioned user from chatting in text channels.. + /// + public static string textmute_desc { + get { + return ResourceManager.GetString("textmute_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `.textmute @Someone`. + /// + public static string textmute_usage { + get { + return ResourceManager.GetString("textmute_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to tl. /// @@ -7457,6 +7484,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to voicemute. + /// + public static string voicemute_cmd { + get { + return ResourceManager.GetString("voicemute_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Prevents a mentioned user from speaking in voice channels.. + /// + public static string voicemute_desc { + get { + return ResourceManager.GetString("voicemute_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `.voicemute @Someone`. + /// + public static string voicemute_usage { + get { + return ResourceManager.GetString("voicemute_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to voice+text v+t. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 4c864ead..44c9e888 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -616,7 +616,7 @@ mute - Mutes a mentioned user in a voice channel. + Mutes a mentioned user both fom speaking and chatting. `.mute @Someone` @@ -2664,4 +2664,22 @@ `.antispam 3 Mute` or `.antispam 4 Kick` or `.antispam 6 Ban` + + textmute + + + Prevents a mentioned user from chatting in text channels. + + + `.textmute @Someone` + + + voicemute + + + Prevents a mentioned user from speaking in voice channels. + + + `.voicemute @Someone` + \ No newline at end of file