Merge pull request #23 from cuken/master
Added Urban Dictionary Search Function
This commit is contained in:
		@@ -184,22 +184,51 @@ namespace NadekoBot.Modules {
 | 
				
			|||||||
                      }
 | 
					                      }
 | 
				
			||||||
                  });
 | 
					                  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                //todo when moved from parse
 | 
					
 | 
				
			||||||
                /*
 | 
					                cgb.CreateCommand("~ud")
 | 
				
			||||||
                cgb.CreateCommand("~osubind")
 | 
					                  .Description("Searches Urban Dictionary for a word\n**Usage**:~ud Pineapple")
 | 
				
			||||||
                    .Description("Bind discord user to osu name\n**Usage**: ~osubind My osu name")
 | 
					                  .Parameter("query", ParameterType.Unparsed)
 | 
				
			||||||
                    .Parameter("osu_name", ParameterType.Unparsed)
 | 
					                  .Do(async e => {
 | 
				
			||||||
                    .Do(async e => {
 | 
					                      var arg = e.GetArg("query");
 | 
				
			||||||
                        var userName = e.GetArg("user_name");
 | 
					                      if (string.IsNullOrWhiteSpace(arg))
 | 
				
			||||||
                        var osuName = e.GetArg("osu_name");
 | 
					                      {
 | 
				
			||||||
                        var usr = e.Server.FindUsers(userName).FirstOrDefault();
 | 
					                          await e.Send("💢 Please enter a search term.");
 | 
				
			||||||
                        if (usr == null) {
 | 
					                          return;
 | 
				
			||||||
                            await e.Send("Cannot find that discord user.");
 | 
					                      }
 | 
				
			||||||
                            return;
 | 
					                      await e.Channel.SendIsTyping();
 | 
				
			||||||
                        }
 | 
					                      var res = await SearchHelper.GetResponseAsync($"https://mashape-community-urban-dictionary.p.mashape.com/define?term={Uri.EscapeUriString(arg)}",
 | 
				
			||||||
                    });
 | 
					                          new Tuple<string, string>[] {
 | 
				
			||||||
                */
 | 
					                                  new Tuple<string, string>("X-Mashape-Key", NadekoBot.creds.MashapeKey)
 | 
				
			||||||
            });
 | 
					                          });
 | 
				
			||||||
 | 
					                      try
 | 
				
			||||||
 | 
					                      {
 | 
				
			||||||
 | 
					                          var items = JObject.Parse(res);
 | 
				
			||||||
 | 
					                          await e.Send($"`Term:` {items["list"][0]["word"].ToString()}\n");
 | 
				
			||||||
 | 
					                          await e.Send($"`Definition:` {items["list"][0]["definition"].ToString()}\n");
 | 
				
			||||||
 | 
					                          await e.Send($"`Link:` <{await items["list"][0]["permalink"].ToString().ShortenUrl()}>");
 | 
				
			||||||
 | 
					                      }
 | 
				
			||||||
 | 
					                      catch (Exception ex)
 | 
				
			||||||
 | 
					                      {
 | 
				
			||||||
 | 
					                          await e.Channel.SendMessage("💢 Exception: " + ex.Message);
 | 
				
			||||||
 | 
					                      }
 | 
				
			||||||
 | 
					                      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                      //todo when moved from parse
 | 
				
			||||||
 | 
					                      /*
 | 
				
			||||||
 | 
					                      cgb.CreateCommand("~osubind")
 | 
				
			||||||
 | 
					                          .Description("Bind discord user to osu name\n**Usage**: ~osubind My osu name")
 | 
				
			||||||
 | 
					                          .Parameter("osu_name", ParameterType.Unparsed)
 | 
				
			||||||
 | 
					                          .Do(async e => {
 | 
				
			||||||
 | 
					                              var userName = e.GetArg("user_name");
 | 
				
			||||||
 | 
					                              var osuName = e.GetArg("osu_name");
 | 
				
			||||||
 | 
					                              var usr = e.Server.FindUsers(userName).FirstOrDefault();
 | 
				
			||||||
 | 
					                              if (usr == null) {
 | 
				
			||||||
 | 
					                                  await e.Send("Cannot find that discord user.");
 | 
				
			||||||
 | 
					                                  return;
 | 
				
			||||||
 | 
					                              }
 | 
				
			||||||
 | 
					                          });
 | 
				
			||||||
 | 
					                      */
 | 
				
			||||||
 | 
					                  });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user