public async Task Script([Summary("Script command name")] string name) { if (!rAthenaBot.instance.IsChannelWhitelisted(Context.Channel)) { return; } if (!available) { await ReplyAsync("This command is not available."); return; } bool shouldReprocess = await RefreshScriptCommandsTxt(); if (shouldReprocess) { await ProcessScriptCommands(); } ScriptCommand cmd = scriptCommands.FirstOrDefault(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if (cmd == null) { await ReplyAsync("Command not found. Do you meant any of these: " + String.Join(" ", scriptCommands.Where(x => x.Name.Contains(name)).Select(y => y.Name))); } else { EmbedBuilder builder = new EmbedBuilder(); builder.WithTitle("Script Command - " + cmd.Name); builder.AddInlineField(cmd.Descriptions.FirstOrDefault(), String.Join(Environment.NewLine, cmd.Descriptions.Skip(1))); builder.WithThumbnailUrl("https://dac.cssnr.com/static/images/logo.png"); builder.Url = string.Format("https://github.com/rathena/rathena/blob/master/doc/script_commands.txt#L{0}-L{1}", cmd.LineNumberStart, cmd.LineNumberEnd); builder.WithColor(Color.LightGrey); await ReplyAsync(string.Empty, false, builder, RequestOptions.Default); } }
public bool Parse() { bool enableParse = false; bool skip = false; ScriptCommand sc = null; int nullCount = 0; int lineNumber = 0; foreach (string line in content) { lineNumber++; if (!enableParse) { if (line.StartsWith("1.- Basic commands.")) { enableParse = true; } } else { if (line.Equals("---------------------------------------")) { if (sc != null && !String.IsNullOrEmpty(sc.Name)) { sc.LineNumberEnd = lineNumber; commands.Add(sc); } sc = new ScriptCommand(); nullCount = 0; skip = false; } else { if (sc == null || skip) { continue; } if (!string.IsNullOrWhiteSpace(line)) { sc.Descriptions.Add(line); } else { nullCount++; if (nullCount > 2) { skip = true; } } if (line.StartsWith("*")) { Regex rgx = new Regex(@"\*(\w+)"); if (rgx.IsMatch(line)) { Match match = rgx.Match(line); Group g = match.Groups[1]; if (g.Success) { sc.Name = g.Value; sc.LineNumberStart = lineNumber; } } } } } } return(commands.Count > 0); }