~wiki added, closes #263 , ~clr [HEX] added
This commit is contained in:
parent
92eb26cb0e
commit
8bfae6293b
@ -440,6 +440,44 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
||||
else
|
||||
await e.Channel.SendMessage(link).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "wiki")
|
||||
.Description("Gives you back a wikipedia link")
|
||||
.Parameter("query", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
var query = e.GetArg("query");
|
||||
var result = await SearchHelper.GetResponseStringAsync("https://en.wikipedia.org//w/api.php?action=query&format=json&prop=info&redirects=1&formatversion=2&inprop=url&titles=" + Uri.EscapeDataString(query));
|
||||
var data = JsonConvert.DeserializeObject<WikipediaApiModel>(result);
|
||||
if (data.Query.Pages[0].Missing)
|
||||
await e.Channel.SendMessage("`That page could not be found.`");
|
||||
else
|
||||
await e.Channel.SendMessage(data.Query.Pages[0].FullUrl);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "clr")
|
||||
.Description("Shows you what color corresponds to that hex.\n**Usage**: `~clr 00ff00`")
|
||||
.Parameter("color", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
var arg1 = e.GetArg("color")?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(arg1))
|
||||
return;
|
||||
var img = new Bitmap(50, 50);
|
||||
|
||||
var red = Convert.ToInt32(arg1.Substring(0, 2), 16);
|
||||
var green = Convert.ToInt32(arg1.Substring(2, 2), 16);
|
||||
var blue = Convert.ToInt32(arg1.Substring(4, 2), 16);
|
||||
var brush = new SolidBrush(Color.FromArgb(red, green, blue));
|
||||
|
||||
using (Graphics g = Graphics.FromImage(img))
|
||||
{
|
||||
g.FillRectangle(brush, 0, 0, 50, 50);
|
||||
g.Flush();
|
||||
}
|
||||
|
||||
await e.Channel.SendFile("arg1.png", img.ToStream());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,50 @@ namespace NadekoBot.Classes.JSONModels
|
||||
public string kind { get; set; }
|
||||
public string videoId { get; set; }
|
||||
}
|
||||
|
||||
#region wikpedia example
|
||||
// {
|
||||
// "batchcomplete": true,
|
||||
// "query": {
|
||||
// "normalized": [
|
||||
// {
|
||||
// "from": "u3fn92fb32f9yb329f32",
|
||||
// "to": "U3fn92fb32f9yb329f32"
|
||||
// }
|
||||
// ],
|
||||
// "pages": [
|
||||
// {
|
||||
// "ns": 0,
|
||||
// "title": "U3fn92fb32f9yb329f32",
|
||||
// "missing": true,
|
||||
// "contentmodel": "wikitext",
|
||||
// "pagelanguage": "en",
|
||||
// "pagelanguagehtmlcode": "en",
|
||||
// "pagelanguagedir": "ltr",
|
||||
// "fullurl": "https://en.wikipedia.org/wiki/U3fn92fb32f9yb329f32",
|
||||
// "editurl": "https://en.wikipedia.org/w/index.php?title=U3fn92fb32f9yb329f32&action=edit",
|
||||
// "canonicalurl": "https://en.wikipedia.org/wiki/U3fn92fb32f9yb329f32"
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
|
||||
public class WikipediaApiModel
|
||||
{
|
||||
public WikipediaQuery Query { get; set; }
|
||||
}
|
||||
|
||||
public class WikipediaQuery
|
||||
{
|
||||
public WikipediaPage[] Pages { get; set; }
|
||||
}
|
||||
|
||||
public class WikipediaPage
|
||||
{
|
||||
public bool Missing { get; set; } = false;
|
||||
public string FullUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
//{
|
||||
|
Loading…
Reference in New Issue
Block a user