示例#1
0
        public static List <string> ListToLowerCase(string[] upperCaseList)
        {
            List <string> res = new List <string>();

            foreach (string el in upperCaseList)
            {
                res.Add(RoleHighlighting.FirstToLowercase(el));
            }
            return(res);
        }
示例#2
0
        private Dictionary <ulong, RoleHighlighting> individualHLs; // An individual highlighter for each guild, indexed by the guild ID.

        /// <summary>
        /// A constructor that may only be called once the connection with the Discord API is made and we can pass the full list
        /// of all Discord guilds.
        /// </summary>
        /// <param name="allGuilds"></param>
        public MainHighlighter(DiscordGuilds allGuilds)
        {
            individualHLs = new Dictionary <ulong, RoleHighlighting>();
            _guilds       = allGuilds;

            foreach ((var guildID, var guild) in _guilds.byID)
            {
                RoleHighlighting singleHL = new RoleHighlighting(guild);
                individualHLs.Add(guildID, singleHL);
            }

            fullInit = true;
        }
示例#3
0
        public List <string> RolesToHighlight(string haystack)
        {
            List <string> ret             = new List <string>();
            var           matchCollection = Regex.Matches(haystack, RegexMatcher);

            foreach (Match m in matchCollection)
            {
                string canonicalForm = RoleHighlighting.FirstToUppercase(m.Groups[1].Value);
                Console.WriteLine($"Canonical form of match is: {canonicalForm}");
                ret.Add(canonicalForm);
            }

            return(ret);
        }
示例#4
0
        public RoleHighlighting(DiscordGuild dg)
        {
            _dg           = dg;
            _roleNameToID = new Dictionary <string, ulong>();
            // Initialize internal list of roles.
            _upperCaseLoudDigitRoles = new List <string>(Ranking.LoudDigitRoles);
            _upperCaseLoudMetalRoles = new List <string>(Ranking.LoudMetalRoles);
            _lowerCaseLoudDigitRoles = RoleHighlighting.ListToLowerCase(Ranking.LoudDigitRoles);
            _lowerCaseLoudMetalRoles = RoleHighlighting.ListToLowerCase(Ranking.LoudMetalRoles);

            // Build the regex matching string from the roleset in Settings.
            StringBuilder sb = new StringBuilder();

            // The order is important here, so that Plat 3 will be matched before Plat itself.
            RoleHighlighting.ConcatenateWithOr(sb, _upperCaseLoudDigitRoles, _lowerCaseLoudDigitRoles, _upperCaseLoudMetalRoles, _lowerCaseLoudMetalRoles);
            RoleHighlighting.AppendSpecialOrEndline(sb);
            RegexMatcher = sb.ToString();


            // Populate _roleNameToID.
            foreach (string name in Ranking.LoudMetalRoles)
            {
                SocketRole role = _dg._socket.Roles.FirstOrDefault(x => x.Name == name);
                if (role == null)
                {
                    Console.WriteLine($"The role {name} has not been found in server {_dg.GetName()}. Populate the Discord server with roles before you start this extension.");
                    throw new Exception();
                }
                else
                {
                    _roleNameToID.Add(name, role.Id);
                }
            }

            foreach (string name in Ranking.LoudDigitRoles)
            {
                SocketRole role = _dg._socket.Roles.FirstOrDefault(x => x.Name == name);
                if (role == null)
                {
                    Console.WriteLine($"The role {name} has not been found in server {_dg.GetName()}. Populate the Discord server with roles before you start this extension.");
                    throw new Exception();
                }
                else
                {
                    _roleNameToID.Add(name, role.Id);
                }
            }
        }