Pretty terrible ~define
added
This commit is contained in:
parent
4be7000381
commit
718c82a891
@ -472,6 +472,42 @@ namespace NadekoBot.Modules.Searches
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Define(IUserMessage msg, [Remainder] string word)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(word))
|
||||
return;
|
||||
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var res = await http.GetStringAsync("http://api.pearson.com/v2/dictionaries/entries?headword=" + WebUtility.UrlEncode(word.Trim())).ConfigureAwait(false);
|
||||
|
||||
var data = JsonConvert.DeserializeObject<DefineModel>(res);
|
||||
|
||||
var sense = data.Results.Where(x => x.Senses != null && x.Senses[0].Definition != null).FirstOrDefault()?.Senses[0];
|
||||
|
||||
if (sense?.Definition == null)
|
||||
return;
|
||||
|
||||
string definition = sense.Definition.ToString();
|
||||
if (!(sense.Definition is string))
|
||||
definition = ((JArray)JToken.Parse(sense.Definition.ToString())).First.ToString();
|
||||
|
||||
var embed = new EmbedBuilder().WithOkColor()
|
||||
.WithTitle("Define: " + word)
|
||||
.WithDescription(definition)
|
||||
.WithFooter(efb => efb.WithText(sense.Gramatical_info?.type));
|
||||
|
||||
if (sense.Examples != null)
|
||||
embed.AddField(efb => efb.WithName("Example").WithValue(sense.Examples.First().text));
|
||||
|
||||
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Hashtag(IUserMessage umsg, [Remainder] string query = null)
|
||||
|
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -2003,6 +2003,33 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to define def.
|
||||
/// </summary>
|
||||
public static string define_cmd {
|
||||
get {
|
||||
return ResourceManager.GetString("define_cmd", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Finds a definition of a word..
|
||||
/// </summary>
|
||||
public static string define_desc {
|
||||
get {
|
||||
return ResourceManager.GetString("define_desc", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}def heresy`.
|
||||
/// </summary>
|
||||
public static string define_usage {
|
||||
get {
|
||||
return ResourceManager.GetString("define_usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to defvol dv.
|
||||
/// </summary>
|
||||
|
@ -2826,4 +2826,13 @@
|
||||
<data name="fairplay_usage" xml:space="preserve">
|
||||
<value>`{0}fp`</value>
|
||||
</data>
|
||||
<data name="define_cmd" xml:space="preserve">
|
||||
<value>define def</value>
|
||||
</data>
|
||||
<data name="define_desc" xml:space="preserve">
|
||||
<value>Finds a definition of a word.</value>
|
||||
</data>
|
||||
<data name="define_usage" xml:space="preserve">
|
||||
<value>`{0}def heresy`</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user