Merge branch 'fkndean-1.0' into 1.0

Merged fkndean1.0 - wikia and minecraftquery
This commit is contained in:
Kwoth 2016-11-09 16:58:04 +01:00
commit 9687da3dd0
4 changed files with 442 additions and 4 deletions

2
.gitignore vendored
View File

@ -2,7 +2,7 @@
src/NadekoBot/credentials.json src/NadekoBot/credentials.json
src/NadekoBot/data/NadekoBot.db src/NadekoBot/data/NadekoBot.db
src/NadekoBot/musicdata src/NadekoBot/data/musicdata
# Created by https://www.gitignore.io/api/visualstudio,visualstudiocode,windows,linux,macos # Created by https://www.gitignore.io/api/visualstudio,visualstudiocode,windows,linux,macos

View File

@ -4,6 +4,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Linq; using System.Linq;
using System.Text;
using System.Net.Http; using System.Net.Http;
using NadekoBot.Services; using NadekoBot.Services;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -242,7 +243,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
throw new KeyNotFoundException("Cannot find a card by that name"); throw new KeyNotFoundException("Cannot find a card by that name");
foreach (var item in items.Where(item => item.HasValues && item["img"] != null).Take(4)) foreach (var item in items.Where(item => item.HasValues && item["img"] != null).Take(4))
{ {
using (var sr =await http.GetStreamAsync(item["img"].ToString())) using (var sr = await http.GetStreamAsync(item["img"].ToString()))
{ {
var imgStream = new MemoryStream(); var imgStream = new MemoryStream();
await sr.CopyToAsync(imgStream); await sr.CopyToAsync(imgStream);
@ -294,7 +295,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
try try
{ {
var items = JObject.Parse(res); var items = JObject.Parse(res);
var sb = new System.Text.StringBuilder(); var sb = new StringBuilder();
sb.AppendLine($"`Term:` {items["list"][0]["word"].ToString()}"); sb.AppendLine($"`Term:` {items["list"][0]["word"].ToString()}");
sb.AppendLine($"`Definition:` {items["list"][0]["definition"].ToString()}"); sb.AppendLine($"`Definition:` {items["list"][0]["definition"].ToString()}");
sb.Append($"`Link:` <{await _google.ShortenUrl(items["list"][0]["permalink"].ToString()).ConfigureAwait(false)}>"); sb.Append($"`Link:` <{await _google.ShortenUrl(items["list"][0]["permalink"].ToString()).ConfigureAwait(false)}>");
@ -493,6 +494,255 @@ $@"🌍 **Weather for** 【{obj["target"]}】
} }
} }
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Wikia(IUserMessage umsg, string targ, [Remainder] string query = null)
{
var channel = (ITextChannel)umsg.Channel;
var arg = query;
if (string.IsNullOrWhiteSpace(targ) || string.IsNullOrWhiteSpace(arg))
{
await channel.SendMessageAsync("💢 Please enter `target query`.").ConfigureAwait(false);
return;
}
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Clear();
string target = targ;
string search = arg;
try
{
var res = await http.GetStringAsync($"http://www.{Uri.EscapeUriString(target)}.wikia.com/api/v1/Search/List?query={Uri.EscapeUriString(search)}&limit=25&minArticleQuality=10&batch=1&namespaces=0%2C14").ConfigureAwait(false);
var items = JObject.Parse(res);
var sb = new StringBuilder();
sb.AppendLine($"`Found:` {items["items"][0]["title"].ToString()}");
sb.AppendLine($"`Total Found:` {items["total"].ToString()}");
sb.AppendLine($"`Batch:` {items["currentBatch"].ToString()}/{items["batches"].ToString()}");
sb.Append($"`URL:` <{await _google.ShortenUrl(items["items"][0]["url"].ToString()).ConfigureAwait(false)}> / `Quality`: {items["items"][0]["quality"].ToString()}");
await channel.SendMessageAsync(sb.ToString());
}
catch
{
await channel.SendMessageAsync($"💢 Failed finding `{arg}`.").ConfigureAwait(false);
}
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task MCPing(IUserMessage umsg, [Remainder] string query = null)
{
var channel = (ITextChannel)umsg.Channel;
var arg = query;
if (string.IsNullOrWhiteSpace(arg))
{
await channel.SendMessageAsync("💢 Please enter a `ip:port`.").ConfigureAwait(false);
return;
}
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Clear();
string ip = arg.Split(':')[0];
string port = arg.Split(':')[1];
var res = await http.GetStringAsync($"https://api.minetools.eu/ping/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false);
try
{
var items = JObject.Parse(res);
var sb = new StringBuilder();
int ping = (int)Math.Ceiling(Double.Parse(items["latency"].ToString()));
sb.AppendLine($"`Server:` {arg}");
sb.AppendLine($"`Version:` {items["version"]["name"].ToString()} / Protocol {items["version"]["protocol"].ToString()}");
sb.AppendLine($"`Description:` {items["description"].ToString()}");
sb.AppendLine($"`Online Players:` {items["players"]["online"].ToString()}/{items["players"]["max"].ToString()}");
sb.Append($"`Latency:` {ping}");
await channel.SendMessageAsync(sb.ToString());
}
catch
{
await channel.SendMessageAsync($"💢 Failed finding `{arg}`.").ConfigureAwait(false);
}
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task MCQ(IUserMessage umsg, [Remainder] string query = null)
{
var channel = (ITextChannel)umsg.Channel;
var arg = query;
if (string.IsNullOrWhiteSpace(arg))
{
await channel.SendMessageAsync("💢 Please enter a `ip:port`.").ConfigureAwait(false);
return;
}
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Clear();
try
{
string ip = arg.Split(':')[0];
string port = arg.Split(':')[1];
var res = await http.GetStringAsync($"https://api.minetools.eu/query/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false);
var items = JObject.Parse(res);
var sb = new StringBuilder();
sb.AppendLine($"`Server:` {arg.ToString()} 〘Status: {items["status"]}〙");
sb.AppendLine($"`Player List (First 5):`");
foreach (var item in items["Playerlist"].Take(5))
{
sb.AppendLine($":rosette: {item}");
}
sb.AppendLine($"`Online Players:` {items["Players"]} / {items["MaxPlayers"]}");
sb.AppendLine($"`Plugins:` {items["Plugins"]}");
sb.Append($"`Version:` {items["Version"]}");
await channel.SendMessageAsync(sb.ToString());
}
catch
{
await channel.SendMessageAsync($"💢 Failed finding server `{arg}`.").ConfigureAwait(false);
}
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task MCPing(IUserMessage umsg, [Remainder] string query = null)
{
var channel = (ITextChannel)umsg.Channel;
var arg = query;
if (string.IsNullOrWhiteSpace(arg))
{
await channel.SendMessageAsync("💢 Please enter a ip:port.").ConfigureAwait(false);
return;
}
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Clear();
string ip = arg.Split(':')[0];
string port = arg.Split(':')[1];
var res = await http.GetStringAsync($"https://api.minetools.eu/ping/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false);
try
{
var items = JObject.Parse(res);
var sb = new System.Text.StringBuilder();
int ping = (int)Math.Ceiling(Double.Parse(items["latency"].ToString()));
sb.AppendLine($"`Server:` {arg}");
sb.AppendLine($"`Version:` {items["version"]["name"].ToString()} / Protocol {items["version"]["protocol"].ToString()}");
sb.AppendLine($"`Description:` {items["description"].ToString()}");
sb.AppendLine($"`Online Players:` {items["players"]["online"].ToString()}/{items["players"]["max"].ToString()}");
sb.Append($"`Latency:` {ping}");
await channel.SendMessageAsync(sb.ToString());
}
catch
{
await channel.SendMessageAsync($"💢 [MINECRAFT] Failed finding {arg}.").ConfigureAwait(false);
}
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task MCQuery(IUserMessage umsg, [Remainder] string query = null)
{
var channel = (ITextChannel)umsg.Channel;
var arg = query;
if (string.IsNullOrWhiteSpace(arg))
{
await channel.SendMessageAsync("💢 Please enter a ip:port.").ConfigureAwait(false);
return;
}
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Clear();
try
{
string ip = arg.Split(':')[0];
string port = arg.Split(':')[1];
var res = await http.GetStringAsync($"https://api.minetools.eu/query/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false);
var items = JObject.Parse(res);
var sb = new System.Text.StringBuilder();
sb.AppendLine($"`Server:` {arg.ToString()} 〘Status: {items["status"]}〙");
sb.AppendLine($"`Player List:`");
for (int i=0;i < items["Playerlist"].Count();i++)
{
if (i == 5)
{
break;
} else
{
sb.AppendLine($"{i+1}. {items["Playerlist"][i]}");
}
}
sb.AppendLine($"`Online Players:` {items["Players"]} / {items["MaxPlayers"]}");
sb.AppendLine($"`Plugins:` {items["Plugins"]}");
sb.Append($"`Version:` {items["Version"]}");
await channel.SendMessageAsync(sb.ToString());
}
catch
{
await channel.SendMessageAsync($"💢 [MINECRAFT] Failed finding server: `{arg}`.").ConfigureAwait(false);
}
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task MCUser(IUserMessage umsg, [Remainder] string query = null)
{
var channel = (ITextChannel)umsg.Channel;
var arg = query;
if (string.IsNullOrWhiteSpace(arg))
{
await channel.SendMessageAsync("💢 Please enter a name or uuid.").ConfigureAwait(false);
return;
}
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Clear();
var res = await http.GetStringAsync($"https://api.minetools.eu/uuid/{Uri.EscapeUriString(arg)}").ConfigureAwait(false);
try
{
var items = JObject.Parse(res);
var sb = new System.Text.StringBuilder();
if (items["uuid"].ToString() == "null")
{
sb.Append($"💢 [MINECRAFT] Failed finding a name/uuid going by {Uri.EscapeUriString(arg)}, bugger off!");
}
else
{
using (var httpkek = new HttpClient())
{
httpkek.DefaultRequestHeaders.Clear();
var uuid = items["uuid"].ToString();
var reskek = await http.GetStringAsync($"https://api.minetools.eu/profile/{Uri.EscapeUriString(uuid)}").ConfigureAwait(false);
try
{
var itemskek = JObject.Parse(reskek);
sb.AppendLine($"`Profile ID:` {itemskek["decoded"]["profileId"].ToString()}");
sb.AppendLine($"`Profile Name:` {itemskek["decoded"]["profileName"].ToString()}");
sb.AppendLine($"`Textures (CAPE):` {await _google.ShortenUrl(itemskek["decoded"]["textures"]["CAPE"]["url"].ToString()).ConfigureAwait(false)}");
sb.AppendLine($"`Textures (SKIN):` {await _google.ShortenUrl(itemskek["decoded"]["textures"]["SKIN"]["url"].ToString()).ConfigureAwait(false)}");
sb.Append($"`Timestamp:` {Convert.ToDateTime(itemskek["decoded"]["timestamp"].ToString())}");
}
catch
{
}
}
}
await channel.SendMessageAsync(sb.ToString());
}
catch
{
await channel.SendMessageAsync("💢 [MINECRAFT] Failed finding user.").ConfigureAwait(false);
}
}
}
public static async Task<bool> ValidateQuery(ITextChannel ch, string query) public static async Task<bool> ValidateQuery(ITextChannel ch, string query)
{ {
if (!string.IsNullOrEmpty(query.Trim())) return true; if (!string.IsNullOrEmpty(query.Trim())) return true;

View File

@ -3938,6 +3938,60 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to minecraftping mcping.
/// </summary>
public static string mcping_cmd {
get {
return ResourceManager.GetString("mcping_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Pings a minecraft server..
/// </summary>
public static string mcping_desc {
get {
return ResourceManager.GetString("mcping_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}mcping 127.0.0.1:1337`.
/// </summary>
public static string mcping_usage {
get {
return ResourceManager.GetString("mcping_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to minecraftquery mcq.
/// </summary>
public static string mcq_cmd {
get {
return ResourceManager.GetString("mcq_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Finds information about a minecraft server..
/// </summary>
public static string mcq_desc {
get {
return ResourceManager.GetString("mcq_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}mcq server:ip`.
/// </summary>
public static string mcq_usage {
get {
return ResourceManager.GetString("mcq_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to `{0}memegen biw &quot;gets iced coffee&quot; &quot;in the winter&quot;`. /// Looks up a localized string similar to `{0}memegen biw &quot;gets iced coffee&quot; &quot;in the winter&quot;`.
/// </summary> /// </summary>
@ -7457,6 +7511,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to wikia.
/// </summary>
public static string wikia_cmd {
get {
return ResourceManager.GetString("wikia_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Gives you back a wikia link.
/// </summary>
public static string wikia_desc {
get {
return ResourceManager.GetString("wikia_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}wikia target query`.
/// </summary>
public static string wikia_usage {
get {
return ResourceManager.GetString("wikia_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to wowjoke. /// Looks up a localized string similar to wowjoke.
/// </summary> /// </summary>
@ -7564,5 +7645,85 @@ namespace NadekoBot.Resources {
return ResourceManager.GetString("youtube_usage", resourceCulture); return ResourceManager.GetString("youtube_usage", resourceCulture);
} }
} }
/// <summary>
/// Looks up a localized string similar to minecraftping mcping.
/// </summary>
public static string mcping_cmd {
get {
return ResourceManager.GetString("mcping_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Pings a minecraft server..
/// </summary>
public static string mcping_desc {
get {
return ResourceManager.GetString("mcping_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}mcping 127.0.0.1:1337`.
/// </summary>
public static string mcping_usage {
get {
return ResourceManager.GetString("mcping_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to minecraftquery mcquery.
/// </summary>
public static string mcquery_cmd {
get {
return ResourceManager.GetString("mcquery_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Finds information about a minecraft server..
/// </summary>
public static string mcquery_desc {
get {
return ResourceManager.GetString("mcquery_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}mcquery server:ip`.
/// </summary>
public static string mcquery_usage {
get {
return ResourceManager.GetString("mcquery_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to minecraftuser mcuser.
/// </summary>
public static string mcuser_cmd {
get {
return ResourceManager.GetString("mcuser_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Finds information about a minecraft user..
/// </summary>
public static string mcuser_desc {
get {
return ResourceManager.GetString("mcuser_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}mcuser username or uuid`.
/// </summary>
public static string mcuser_usage {
get {
return ResourceManager.GetString("mcuser_usage", resourceCulture);
}
}
} }
} }

View File

@ -2637,4 +2637,31 @@
<data name="shorten_usage" xml:space="preserve"> <data name="shorten_usage" xml:space="preserve">
<value>`{0}shorten https://google.com`</value> <value>`{0}shorten https://google.com`</value>
</data> </data>
<data name="mcping_cmd" xml:space="preserve">
<value>minecraftping mcping</value>
</data>
<data name="mcping_desc" xml:space="preserve">
<value>Pings a minecraft server.</value>
</data>
<data name="mcping_usage" xml:space="preserve">
<value>`{0}mcping 127.0.0.1:25565`</value>
</data>
<data name="mcq_cmd" xml:space="preserve">
<value>minecraftquery mcq</value>
</data>
<data name="mcq_desc" xml:space="preserve">
<value>Finds information about a minecraft server.</value>
</data>
<data name="mcq_usage" xml:space="preserve">
<value>`{0}mcq server:ip`</value>
</data>
<data name="wikia_cmd" xml:space="preserve">
<value>wikia</value>
</data>
<data name="wikia_desc" xml:space="preserve">
<value>Gives you back a wikia link</value>
</data>
<data name="wikia_usage" xml:space="preserve">
<value>`{0}wikia target query`</value>
</data>
</root> </root>