clean MuteCommands.cs
This commit is contained in:
		@@ -22,9 +22,6 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
    [NadekoModule("Administration", ".")]
 | 
			
		||||
    public partial class Administration : NadekoModule
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        private static ConcurrentDictionary<ulong, string> GuildMuteRoles { get; } = new ConcurrentDictionary<ulong, string>();
 | 
			
		||||
 | 
			
		||||
        private static ConcurrentHashSet<ulong> DeleteMessagesOnCommand { get; } = new ConcurrentHashSet<ulong>();
 | 
			
		||||
 | 
			
		||||
        private new static Logger _log { get; }
 | 
			
		||||
@@ -206,7 +203,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            var roleName = args[0].ToUpperInvariant();
 | 
			
		||||
            var role = Context.Guild.Roles.Where(r => r.Name.ToUpperInvariant() == roleName).FirstOrDefault();
 | 
			
		||||
            var role = Context.Guild.Roles.FirstOrDefault(r => r.Name.ToUpperInvariant() == roleName);
 | 
			
		||||
 | 
			
		||||
            if (role == null)
 | 
			
		||||
            {
 | 
			
		||||
@@ -513,7 +510,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            await Context.Channel.SendMessageAsync(send).ConfigureAwait(false);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        IGuild nadekoSupportServer;
 | 
			
		||||
        IGuild _nadekoSupportServer;
 | 
			
		||||
        [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
        public async Task Donators()
 | 
			
		||||
        {
 | 
			
		||||
@@ -525,16 +522,13 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            }
 | 
			
		||||
            await Context.Channel.SendConfirmAsync("Thanks to the people listed below for making this project happen!", string.Join("⭐", donatorsOrdered.Select(d => d.Name))).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
            nadekoSupportServer = nadekoSupportServer ?? NadekoBot.Client.GetGuild(117523346618318850);
 | 
			
		||||
            _nadekoSupportServer = _nadekoSupportServer ?? NadekoBot.Client.GetGuild(117523346618318850);
 | 
			
		||||
 | 
			
		||||
            if (nadekoSupportServer == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            var patreonRole = nadekoSupportServer.GetRole(236667642088259585);
 | 
			
		||||
            var patreonRole = _nadekoSupportServer?.GetRole(236667642088259585);
 | 
			
		||||
            if (patreonRole == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            var usrs = (await nadekoSupportServer.GetUsersAsync()).Where(u => u.RoleIds.Contains(236667642088259585u));
 | 
			
		||||
            var usrs = (await _nadekoSupportServer.GetUsersAsync()).Where(u => u.RoleIds.Contains(236667642088259585u));
 | 
			
		||||
            await Context.Channel.SendConfirmAsync("Patreon supporters", string.Join("⭐", usrs.Select(d => d.Username))).ConfigureAwait(false);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,6 @@ using NadekoBot.Services.Database.Models;
 | 
			
		||||
using NLog;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
@@ -20,9 +18,8 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
        [Group]
 | 
			
		||||
        public class MuteCommands : NadekoSubmodule
 | 
			
		||||
        {
 | 
			
		||||
            private static ConcurrentDictionary<ulong, string> GuildMuteRoles { get; } = new ConcurrentDictionary<ulong, string>();
 | 
			
		||||
 | 
			
		||||
            private static ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> MutedUsers { get; } = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>();
 | 
			
		||||
            private static ConcurrentDictionary<ulong, string> guildMuteRoles { get; }
 | 
			
		||||
            private static ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> mutedUsers { get; }
 | 
			
		||||
 | 
			
		||||
            public static event Action<IGuildUser, MuteType> UserMuted = delegate { };
 | 
			
		||||
            public static event Action<IGuildUser, MuteType> UserUnmuted = delegate { };
 | 
			
		||||
@@ -37,11 +34,11 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            static MuteCommands()
 | 
			
		||||
            {
 | 
			
		||||
                var configs = NadekoBot.AllGuildConfigs;
 | 
			
		||||
                GuildMuteRoles = new ConcurrentDictionary<ulong, string>(configs
 | 
			
		||||
                guildMuteRoles = new ConcurrentDictionary<ulong, string>(configs
 | 
			
		||||
                        .Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName))
 | 
			
		||||
                        .ToDictionary(c => c.GuildId, c => c.MuteRoleName));
 | 
			
		||||
 | 
			
		||||
                MutedUsers = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(configs.ToDictionary(
 | 
			
		||||
                mutedUsers = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(configs.ToDictionary(
 | 
			
		||||
                    k => k.GuildId,
 | 
			
		||||
                    v => new ConcurrentHashSet<ulong>(v.MutedUsers.Select(m => m.UserId))
 | 
			
		||||
                ));
 | 
			
		||||
@@ -54,7 +51,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    ConcurrentHashSet<ulong> muted;
 | 
			
		||||
                    MutedUsers.TryGetValue(usr.Guild.Id, out muted);
 | 
			
		||||
                    mutedUsers.TryGetValue(usr.Guild.Id, out muted);
 | 
			
		||||
 | 
			
		||||
                    if (muted == null || !muted.Contains(usr.Id))
 | 
			
		||||
                        return;
 | 
			
		||||
@@ -79,7 +76,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                        UserId = usr.Id
 | 
			
		||||
                    });
 | 
			
		||||
                    ConcurrentHashSet<ulong> muted;
 | 
			
		||||
                    if (MutedUsers.TryGetValue(usr.Guild.Id, out muted))
 | 
			
		||||
                    if (mutedUsers.TryGetValue(usr.Guild.Id, out muted))
 | 
			
		||||
                        muted.Add(usr.Id);
 | 
			
		||||
                    
 | 
			
		||||
                    await uow.CompleteAsync().ConfigureAwait(false);
 | 
			
		||||
@@ -99,7 +96,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                        UserId = usr.Id
 | 
			
		||||
                    });
 | 
			
		||||
                    ConcurrentHashSet<ulong> muted;
 | 
			
		||||
                    if (MutedUsers.TryGetValue(usr.Guild.Id, out muted))
 | 
			
		||||
                    if (mutedUsers.TryGetValue(usr.Guild.Id, out muted))
 | 
			
		||||
                        muted.TryRemove(usr.Id);
 | 
			
		||||
                    await uow.CompleteAsync().ConfigureAwait(false);
 | 
			
		||||
                }
 | 
			
		||||
@@ -110,7 +107,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            {
 | 
			
		||||
                const string defaultMuteRoleName = "nadeko-mute";
 | 
			
		||||
 | 
			
		||||
                var muteRoleName = GuildMuteRoles.GetOrAdd(guild.Id, defaultMuteRoleName);
 | 
			
		||||
                var muteRoleName = guildMuteRoles.GetOrAdd(guild.Id, defaultMuteRoleName);
 | 
			
		||||
 | 
			
		||||
                var muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName);
 | 
			
		||||
                if (muteRole == null)
 | 
			
		||||
@@ -132,7 +129,10 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                            await toOverwrite.AddPermissionOverwriteAsync(muteRole, new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny))
 | 
			
		||||
                                    .ConfigureAwait(false);
 | 
			
		||||
                        }
 | 
			
		||||
                        catch { }
 | 
			
		||||
                        catch
 | 
			
		||||
                        {
 | 
			
		||||
                            // ignored
 | 
			
		||||
                        }
 | 
			
		||||
                        await Task.Delay(200).ConfigureAwait(false);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
@@ -145,7 +145,6 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            [Priority(1)]
 | 
			
		||||
            public async Task SetMuteRole([Remainder] string name)
 | 
			
		||||
            {
 | 
			
		||||
                //var channel = (ITextChannel)Context.Channel;
 | 
			
		||||
                name = name.Trim();
 | 
			
		||||
                if (string.IsNullOrWhiteSpace(name))
 | 
			
		||||
                    return;
 | 
			
		||||
@@ -154,7 +153,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                {
 | 
			
		||||
                    var config = uow.GuildConfigs.For(Context.Guild.Id, set => set);
 | 
			
		||||
                    config.MuteRoleName = name;
 | 
			
		||||
                    GuildMuteRoles.AddOrUpdate(Context.Guild.Id, name, (id, old) => name);
 | 
			
		||||
                    guildMuteRoles.AddOrUpdate(Context.Guild.Id, name, (id, old) => name);
 | 
			
		||||
                    await uow.CompleteAsync().ConfigureAwait(false);
 | 
			
		||||
                }
 | 
			
		||||
                await Context.Channel.SendConfirmAsync("☑️ **New mute role set.**").ConfigureAwait(false);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@ using System.Collections.Generic;
 | 
			
		||||
using NadekoBot.Modules.Permissions;
 | 
			
		||||
using NadekoBot.TypeReaders;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using NadekoBot.Modules.Music;
 | 
			
		||||
using NadekoBot.Services.Database.Models;
 | 
			
		||||
@@ -44,7 +45,7 @@ namespace NadekoBot
 | 
			
		||||
        public static ConcurrentDictionary<string, string> ModulePrefixes { get; private set; }
 | 
			
		||||
        public static bool Ready { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public static IEnumerable<GuildConfig> AllGuildConfigs { get; }
 | 
			
		||||
        public static ImmutableArray<GuildConfig> AllGuildConfigs { get; }
 | 
			
		||||
        public static BotConfig BotConfig { get; }
 | 
			
		||||
 | 
			
		||||
        static NadekoBot()
 | 
			
		||||
@@ -54,7 +55,7 @@ namespace NadekoBot
 | 
			
		||||
 | 
			
		||||
            using (var uow = DbHandler.UnitOfWork())
 | 
			
		||||
            {
 | 
			
		||||
                AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs();
 | 
			
		||||
                AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs().ToImmutableArray();
 | 
			
		||||
                BotConfig = uow.BotConfig.GetOrCreate();
 | 
			
		||||
                OkColor = new Color(Convert.ToUInt32(BotConfig.OkColor, 16));
 | 
			
		||||
                ErrorColor = new Color(Convert.ToUInt32(BotConfig.ErrorColor, 16));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								src/NadekoBot/NadekoBot.xproj.DotSettings
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/NadekoBot/NadekoBot.xproj.DotSettings
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
 | 
			
		||||
	<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Cadministration_005Ccommands/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
 | 
			
		||||
		Reference in New Issue
	
	Block a user