internal bool ContainsTableAlias(string tableName, string[] additionalSearchTerms) { var temp1 = this.Name.Contains(tableName, StringComparison.OrdinalIgnoreCase) || this.Aliases?.Any(alias => alias.Contains(tableName, StringComparison.OrdinalIgnoreCase)) == true; var temp2 = additionalSearchTerms.Any(s => Name.Contains(s) || Aliases?.Contains(s) == true); return(temp1 && temp2); }
public bool CheckCommand(string[] input, Command parent) { if (Parent == parent && input.Length > 0) { return(Name == input[0] || Aliases.Contains(input[0])); } return(false); }
/// <summary> /// Get string argument from <c>Command line arguments</c> /// </summary> /// <param name="array">Array with command line arguments</param> /// <param name="ArgumentName">Searched argument name</param> /// <param name="DefaultValue">Default value of argument</param> /// <param name="Aliases">Aliases of this argument</param> /// <exception cref="ArgumentNullException">Occurs when value or argument not found</exception> /// <returns></returns> public static string GetStringArgument(this string[] array, string ArgumentName, string DefaultValue = null, params string[] Aliases) { int index = Array.FindIndex(array, x => Aliases.Contains(x.ToLower())); if (index > 0 && index < array.Length) { return(array[index].Replace("'", "").Replace("\"", "")); } else { return(DefaultValue); } }
/// <summary> /// Get int argument from <c>Command line arguments</c> /// </summary> /// <param name="array">Array with command line arguments</param> /// <param name="ArgumentName">Searched argument name</param> /// <param name="DefaultValue">Default value of argument</param> /// <param name="Aliases">Aliases of this argument</param> /// <exception cref="ArgumentNullException">Occurs when value or argument not found</exception> /// <returns></returns> public static int GetIntArgument(this string[] array, string ArgumentName, int?DefaultValue = null, params string[] Aliases) { int index = Array.FindIndex(array, x => Aliases.Contains(x.ToLower())) + 1; if (index > 0 && index < array.Length && int.TryParse(array[index], out int i)) { return(i); } else if (DefaultValue.HasValue) { return(DefaultValue.Value); } throw new ArgumentNullException(ArgumentName); }
public Task <string> Execute(Message msg) { var split = msg.Text.Split(' ', 2); // [команда, параметры] if (split.Length < 2) { return(Task.FromResult("Не все параметры указаны!")); } if (Aliases.Contains(split[1].Trim().ToLower())) { return(Task.FromResult(Description)); } foreach (var command in Commands) { if (command.Aliases.Contains(split[1].Trim().ToLower())) { return(Task.FromResult(command.Description)); } } return(Task.FromResult($"Команда {split[1]} не найдена.")); }
private bool MatchesTfsUrl(string tfsUrl) { return(TfsUrl.Equals(tfsUrl, StringComparison.OrdinalIgnoreCase) || Aliases.Contains(tfsUrl, StringComparison.OrdinalIgnoreCase)); }
public XElement SerializeToXml() { var rootElem = new XElement("LEGOPrimitive", new XAttribute("versionMajor", FileVersion.Major), new XAttribute("versionMinor", FileVersion.Minor)); var annotations = rootElem.AddElement("Annotations"); if (!Aliases.Contains(ID) && ID > 0) { Aliases.Add(ID); } if (Aliases.Any()) { annotations.Add(new XElement("Annotation", new XAttribute("aliases", string.Join(";", Aliases)))); } annotations.Add(new XElement("Annotation", new XAttribute("designname", Name))); if (MainGroup != null) { annotations.Add(new XElement("Annotation", new XAttribute("maingroupid", MainGroup.ID))); annotations.Add(new XElement("Annotation", new XAttribute("maingroupname", MainGroup.Name))); } if (Platform != null) { annotations.Add(new XElement("Annotation", new XAttribute("platformid", Platform.ID))); annotations.Add(new XElement("Annotation", new XAttribute("platformname", Platform.Name))); } annotations.Add(new XElement("Annotation", new XAttribute("version", PartVersion))); foreach (var extra in ExtraAnnotations) { annotations.Add(new XElement("Annotation", new XAttribute(extra.Key, extra.Value))); } if (Collisions.Any()) { rootElem.Add(new XElement("Collision", Collisions.Select(x => x.SerializeToXml()))); } if (Connectors.Any()) { rootElem.Add(new XElement("Connectivity", Connectors.Select(x => x.SerializeToXml()))); } if (FlexBones.Any()) { rootElem.Add(new XElement("Flex", FlexBones.Select(x => x.SerializeToXml()))); } if (PhysicsAttributes != null && !PhysicsAttributes.IsEmpty) { rootElem.Add(PhysicsAttributes.SerializeToXml()); } if (Bounding != null) { var boundingElem = rootElem.AddElement("Bounding"); boundingElem.Add(Bounding.SerializeToXml("AABB")); } if (GeometryBounding != null) { var boundingElem = rootElem.AddElement("GeometryBounding"); boundingElem.Add(GeometryBounding.SerializeToXml("AABB")); } if (SubMaterials != null) { var decorationElem = rootElem.AddElement("Decoration"); decorationElem.Add(new XAttribute("faces", SubMaterials.Length)); decorationElem.Add(new XAttribute("subMaterialRedirectLookupTable", string.Join(",", SubMaterials))); } if (DefaultOrientation != null) { rootElem.Add(new XElement("DefaultOrientation", DefaultOrientation.ToXmlAttributes())); } if (DefaultCamera != null) { rootElem.Add(XmlHelper.DefaultSerialize(DefaultCamera, "DefaultCamera")); } foreach (var elem in rootElem.Descendants("Custom2DField")) { int depth = elem.AncestorsAndSelf().Count(); elem.Value = elem.Value.Indent(depth, " "); elem.Value += StringExtensions.Tab(depth - 1, " "); //fixes the closing tag indentation } if (ExtraElements != null) { foreach (var elem in ExtraElements) { if (elem.Parent != null) { var parentElem = rootElem.Descendants().FirstOrDefault(x => x.Name.LocalName == elem.Parent.Name.LocalName); //if (parentElem != null) // parentElem.Add(elem.) } else { rootElem.Add(elem); } } } return(rootElem); }
/// <summary> /// True if the token matches the command, otherwise false. /// </summary> /// <param name="token"></param> /// <returns></returns> public virtual bool IsIdentifiedBy(string token) { return(token == Name || Aliases.Contains(token)); }
public bool Validate(string symbol) { var trim = symbol.Trim(':'); return(trim == Name || Aliases.Contains(trim)); }
/// <summary> /// Does the specified name match this ability's name or aliases? /// </summary> /// <param name="name"></param> /// <returns></returns> public bool Matches(string name) { return(name == Name || Aliases.Contains(name)); }
// check if a commandname is this command public bool CheckIfCommand(string name, List <string> args, CommandContext ctx) { if (MainAlias.ToLower() == name || Aliases.Contains(name)) { if (args.Count() != Parameters.Count()) { if (Parameters.Count() > 0) { if (Parameters.Last().IsRemainder == false) { return(false); } } else { return(false); } } if (args.Count() == 0 && Parameters.Count() > 0) { return(false); } for (int i = 0; i < Parameters.Count(); i++) { try { TypeConverter typeConverter = TypeDescriptor.GetConverter(Parameters[i].Type); typeConverter.ConvertFromString(args[i]); } catch { return(false); } } // check OnlyRoles if (OnlyRoles != null) { foreach (string RoleName in OnlyRoles) { if (ctx.Member.Roles.Any(x => x.Name == RoleName) != true) { EventService.UserLacksTheRolesToUseACommand(this, ctx); return(false); } } } // check Eepect Roles if (ExpectRoles != null) { foreach (string RoleName in ExpectRoles) { if (ctx.Member.Roles.Any(x => x.Name == RoleName) == true) { return(false); } } } return(true); } else { return(false); } }
public bool HasCommandName(string testName) { testName = testName.ToLower(); return(PrimaryName == testName || Aliases.Contains(testName)); }
public bool HasAlias(string name) { return(Aliases.Contains(name)); }
public override IList <Response> Execute(SenderSettings senderDetail, IMessageDetail args) { StringBuilder output = new StringBuilder(); ServerSettings serverSettings = senderDetail.ServerSettings; CommandMessageHelper command = new CommandMessageHelper(serverSettings.CommandSymbol, args.Message); bool handled = false; string toParse = command.CommandLower; string commandDetail = command.CommandDetail; if (Aliases.Contains(toParse)) { if (Regex.IsMatch(commandDetail, D_REGEX, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.Multiline)) { // Ignore the command entered because the full command is in the detail. toParse = commandDetail; } else { // Convert the command into a d6 command. string timesToRollStr = "1"; string adjustmentStr = "+0"; // If number of times to roll is specified. if (!string.IsNullOrEmpty(commandDetail)) { // If adjustments are specified. if (commandDetail.Contains("-") || commandDetail.Contains("+")) { int index = commandDetail.LastIndexOf("+"); if (index == -1) { index = commandDetail.LastIndexOf("-"); } if (index > 0) { adjustmentStr = commandDetail.Substring(index, commandDetail.Length - index).Trim(); timesToRollStr = commandDetail.Substring(0, index).Trim(); } } else { timesToRollStr = commandDetail; } } toParse = $"{timesToRollStr}d6{adjustmentStr}"; } } else { // Parse the whole thing toParse += " " + commandDetail; } if (Regex.IsMatch(toParse, D_REGEX, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.Multiline)) { handled = true; string[] diceParams = toParse.Split('d', 'D'); string rollsStr = string.IsNullOrEmpty(diceParams[0]) ? "1" : diceParams[0]; string diceTypeStr = string.IsNullOrEmpty(diceParams[1]) ? "6" : diceParams[1]; string adjustmentStr = "0"; if (diceTypeStr.Contains("-") || diceTypeStr.Contains("+")) { int index = diceTypeStr.LastIndexOf("+"); if (index == -1) { index = diceTypeStr.LastIndexOf("-"); } if (index > 0) { adjustmentStr = diceTypeStr.Substring(index, diceTypeStr.Length - index).Trim(); diceTypeStr = diceTypeStr.Substring(0, index).Trim(); } } bool validNumberOfRolls = ushort.TryParse(rollsStr, out ushort rolls); bool validDiceType = byte.TryParse(diceTypeStr, out byte diceType) || diceTypeStr == "F" || diceTypeStr == "f"; bool validAdjustmentDice = int.TryParse(adjustmentStr, NumberStyles.Any, CultureInfo.InvariantCulture, out int adjustment); if (validNumberOfRolls && validDiceType && validAdjustmentDice) { if (diceTypeStr == "F" || diceTypeStr == "f") { RollFudgeDice(rolls, adjustment, languageHandler, serverSettings.Language, ref output); } else { RollDice(rolls, diceType, adjustment, languageHandler, serverSettings.Language, ref output); } if (diceType == 1) { output.AppendLine($"_{languageHandler.GetPhrase(serverSettings.Language, "WhatDidYouExpect")}_"); } } else { if (!validNumberOfRolls) { output.AppendLine($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(serverSettings.Language, Errors.ErrorCode.IncorrectParameter)}: {rollsStr} [0-65535]"); } if (!validDiceType) { output.AppendLine($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(serverSettings.Language, Errors.ErrorCode.IncorrectParameter)}: {diceTypeStr} [0-255]"); } if (!validAdjustmentDice) { output.AppendLine($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(serverSettings.Language, Errors.ErrorCode.IncorrectParameter)}: {adjustmentStr} [+-F]"); } } } if (handled) { string retVal = output.ToString(); Response response = new Response { Embed = Utility.EmbedUtility.ToEmbed(retVal), Message = retVal, ResponseType = ResponseType.Default }; return(new[] { response }); } else { // Not handled. return(Response.NoResponse); } }