public async Task Wiki([Remainder] string text) { WikipediaClient client = new WikipediaClient(); client.Limit = 1; QueryResult results = client.Search(text); var builder = new EmbedBuilder() { Color = new Color(114, 137, 218), }; foreach (Search s in results.Search) { PageResult pages = client.GetPage(s.Title); string value = "\n"; string name = s.Title; foreach (Page page in pages.Pages) { value = page.Extract; } if (value.Length > 1017 - s.Url.AbsoluteUri.Length) { value = value.Remove(1017 - s.Url.AbsoluteUri.Length); value += "...\n\n"; } else { value += "\n\n"; } value += s.Url.AbsoluteUri; builder.AddField(x => { x.Name = name; x.IsInline = false; x.Value = value; }); } await ReplyAsync("", false, builder.Build()); }
public async Task Wiki(string querry) { try { WikipediaClient wkclient = new WikipediaClient(); string arg = querry; if (arg != null) { string cont = await wkclient.Search(arg); string clncont = Regex.Replace(cont, @"([^a-zA-Z0-9_]|^\s)", string.Empty); string res = String.Format("You asked for :{0 }\n Answer: \n {1}", arg, cont); //await e.Channel.SendMessage(String.Format("You asked for :{0}\n",arg)); //await e.Channel.SendMessage(String.Format("Answer: \n {0}", cont)); string temp = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Temp"); if (Directory.Exists(temp) == true) { Directory.Delete(temp, true); } Directory.CreateDirectory(temp); string path = Path.Combine(temp, arg + ".txt"); File.WriteAllText(path, cont); Stream fil = File.OpenRead(path); // var stat =await e.Channel.SendMessage(res); if (cont.Length > 2000) { await Context.Channel.SendFileAsync(fil, path, String.Format("{0} You asked for :{1} " + "\n The answer exceeds the 2000 characters limit so it is saved on a plain text file" , Context.User.Mention, arg)); File.Delete(path); } else { await ReplyAsync(res); } } } catch (Exception ex) { CommonTools.ErrorReporting(ex); } // Console.WriteLine("Message State : {0} \n Message Text {1}", stat.State.ToString(), stat.Text); }
private static async Task Main() { //Default language is English WikipediaClient client = new WikipediaClient(); //Use HTTPS instead of HTTP client.UseTls = true; //We would like 5 results client.Limit = 5; //We would like to search inside the articles client.What = What.Text; const string searchText = "Microsoft C#"; QueryResult results = await client.SearchAsync(searchText); Console.WriteLine("Searching for {0}:{1}", searchText, Environment.NewLine); Console.WriteLine("Found " + results.Search.Count + " English results:"); foreach (Search s in results.Search) { Console.WriteLine(s.Title); } Console.WriteLine(); Console.WriteLine(); //We change the language to Spanish client.Language = Language.Spanish; results = client.Search("Microsoft C#"); Console.WriteLine("Found " + results.Search.Count + " Spanish results:"); foreach (Search s in results.Search) { Console.WriteLine(s.Title); } }
public static QueryResult GetWikipediaDataAsync(string query) { var wikipedia = new WikipediaClient(); return(wikipedia.Search(query)); }