Пример #1
0
        /// <summary>
        /// An event handler which is fired when a role has been updated
        /// It manages the CommandList as appropriate if the name has been changed
        /// </summary>
        /// <param name="oldRole"></param>
        /// <param name="newRole"></param>
        /// <returns></returns>
        private void roleUpdated(SocketRole oldRole, SocketRole newRole)
        {
            // If the role updated was in the whitelist and the name was updated, update the commandlist
            if (WhitelistedRoles.Contains(oldRole.Id.ToString()) && oldRole.Name != newRole.Name)
            {
                string oldRoleName = GetRoleNameCommand(oldRole.Name);

                // Remove the old role from the list so we can check if there are other roles with the same name
                WhitelistedRoles.Remove(oldRole.Id.ToString());

                // If none exist with the same name, we can safely remove the command
                if (WhitelistedRoles.All((id) => GetRoleNameCommand(GetRoleByID(id)?.Name) != oldRoleName))
                {
                    server.Commandlist.Remove(oldRoleName);
                }

                // Readding the role because the ID didn't change, and it was just for the check above
                WhitelistedRoles.Add(oldRole.Id.ToString());

                // We might be trying to add the same command twice, because of roles that share the same first word
                // For example: Stable Dweller exists, now trying to add Stable Pony.
                if (!server.Commandlist.ContainsKey(GetRoleNameCommand(newRole.Name)))
                {
                    server.Commandlist.Add(GetRoleNameCommand(newRole.Name), new Command(server, GetRoleNameCommand(newRole.Name), ModifyRolesByCommandName, PrivilegeLevel.Everyone, new HelpMsgStrings("", "")));
                }

                Console.WriteLine("The role " + oldRole.Name + " has been updated to the role " + newRole);
            }
        }
Пример #2
0
        /// <summary>
        /// Adds/removes whitelisted roles the users can't get via the !role command
        /// </summary>
        /// <param name="e"></param>
        /// <param name="roleName"></param>
        private void ModifyWhitelistedRole(ServerMessage e, string roleName)
        {
            if (!on)
            {
                return;
            }

            var specifiedRole = server.getServer().Roles.FirstOrDefault((r) => r.Name.ToLower() == roleName.ToLower());

            if (specifiedRole == null)
            {
                server.safeSendMessage(e.Channel, "The role " + roleName + " does not exist!");
            }
            // Add the role to the whitelist
            else if (!WhitelistedRoles.Contains(specifiedRole.Id.ToString()))
            {
                WhitelistedRoles.Add(specifiedRole.Id.ToString());

                // We might be trying to add the same command twice, because of roles that share the same first word
                // For example: Stable Dweller exists, now trying to add Stable Pony.
                if (!server.Commandlist.ContainsKey(GetRoleNameCommand(specifiedRole.Name)))
                {
                    server.Commandlist.Add(GetRoleNameCommand(specifiedRole.Name), new Command(server, GetRoleNameCommand(specifiedRole.Name), ModifyRolesByCommandName, PrivilegeLevel.Everyone, new HelpMsgStrings("", "")));
                }

                server.safeSendMessage(e.Channel, "The role " + specifiedRole.Name + " has been added to the list of whitelisted roles users could get via the !role command, or by writing !<role name>");
            }
            // Remove the role from the whitelist
            else
            {
                WhitelistedRoles.Remove(specifiedRole.Id.ToString());

                string realRoleName = GetRoleNameCommand(specifiedRole.Name);

                // If none exist with the same name, we can safely remove the command
                if (WhitelistedRoles.All((id) => GetRoleNameCommand(GetRoleByID(id)?.Name) != realRoleName))
                {
                    server.Commandlist.Remove(realRoleName);
                }

                server.safeSendMessage(e.Channel, "The role " + specifiedRole.Name + " has been removed from the list of whitelisted roles users could get via the !role command, or by writing !<role_name>");
            }
        }