Add Minecraft Commands
This commit is contained in:
		| @@ -4,6 +4,7 @@ using Newtonsoft.Json; | ||||
| using Newtonsoft.Json.Linq; | ||||
| using System; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Net.Http; | ||||
| using NadekoBot.Services; | ||||
| using System.Threading.Tasks; | ||||
| @@ -271,7 +272,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 | ||||
|                 try | ||||
|                 { | ||||
|                     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($"`Definition:` {items["list"][0]["definition"].ToString()}"); | ||||
|                     sb.Append($"`Link:` <{await _google.ShortenUrl(items["list"][0]["permalink"].ToString()).ConfigureAwait(false)}>"); | ||||
| @@ -464,6 +465,90 @@ $@"🌍 **Weather for** 【{obj["target"]}】 | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         [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:`"); | ||||
|                     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($"💢 Failed finding server `{arg}`.").ConfigureAwait(false); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public static async Task<bool> ValidateQuery(ITextChannel ch, string query) | ||||
|         { | ||||
|             if (!string.IsNullOrEmpty(query.Trim())) return true; | ||||
|   | ||||
							
								
								
									
										54
									
								
								src/NadekoBot/Resources/CommandStrings.Designer.cs
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										54
									
								
								src/NadekoBot/Resources/CommandStrings.Designer.cs
									
									
									
										generated
									
									
									
								
							| @@ -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> | ||||
|         ///    Looks up a localized string similar to `{0}memegen biw "gets iced coffee" "in the winter"`. | ||||
|         /// </summary> | ||||
|   | ||||
| @@ -2619,4 +2619,22 @@ | ||||
|   <data name="hentaibomb_usage" xml:space="preserve"> | ||||
|     <value>`{0}hentaibomb yuri`</value> | ||||
|   </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> | ||||
| </root> | ||||
		Reference in New Issue
	
	Block a user