~osu command, better strings

This commit is contained in:
Master Kwoth 2016-02-06 14:48:35 +01:00
parent 06a4cf9f30
commit 0d3d35613c

View File

@ -145,7 +145,7 @@ namespace NadekoBot.Modules {
}); });
cgb.CreateCommand("~hs") cgb.CreateCommand("~hs")
.Description("Searches for a Hearthstone card and shows its image.") .Description("Searches for a Hearthstone card and shows its image. Takes a while to complete.\n**Usage**:~hs Ysera")
.Parameter("name", ParameterType.Unparsed) .Parameter("name", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
var arg = e.GetArg("name"); var arg = e.GetArg("name");
@ -174,28 +174,40 @@ namespace NadekoBot.Modules {
images.Add(System.Drawing.Bitmap.FromStream(await GetResponseStream(item["img"].ToString()))); images.Add(System.Drawing.Bitmap.FromStream(await GetResponseStream(item["img"].ToString())));
} }
if (items.Count > 4) { if (items.Count > 4) {
await e.Send(":exclamation: Found over 4 images. Showing random 4."); await e.Send(":warning: Found over 4 images. Showing random 4.");
} }
Console.WriteLine("Start"); Console.WriteLine("Start");
await e.Channel.SendFile(arg + ".png", (await images.MergeAsync()).ToStream(System.Drawing.Imaging.ImageFormat.Png)); await e.Channel.SendFile(arg + ".png", (await images.MergeAsync()).ToStream(System.Drawing.Imaging.ImageFormat.Png));
Console.WriteLine("Finish"); Console.WriteLine("Finish");
} catch (Exception ex) { } catch (Exception ex) {
await e.Send($":anger: Error {ex}"); await e.Send($":anger: Error {ex.Message}");
} }
}); });
/*
cgb.CreateCommand("~osu") cgb.CreateCommand("~osu")
.Description("desc") .Description("Shows osu stats for a player\n**Usage**:~osu Name")
.Parameter("arg", ParameterType.Required) .Parameter("usr",ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
var arg = e.GetArg("arg"); if (string.IsNullOrWhiteSpace(e.GetArg("usr")))
var res = await GetResponseStream($"http://lemmmy.pw/osusig/sig.php?uname=kwoth&flagshadow&xpbar&xpbarhex&pp=2"); return;
await e.Channel.SendFile($"_{e.GetArg("arg")}.png", res); try {
using (WebClient cl = new WebClient()) {
cl.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
cl.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.2; Win64; x64)");
cl.DownloadDataAsync(new Uri($"http://lemmmy.pw/osusig/sig.php?uname={ e.GetArg("usr") }&flagshadow&xpbar&xpbarhex&pp=2"));
cl.DownloadDataCompleted += async (s, cle) => {
await e.Channel.SendFile($"{e.GetArg("usr")}.png", new MemoryStream(cle.Result));
};
}
} catch (Exception ex) {
await e.Channel.SendMessage(":anger: " + ex.Message);
}
}); });
//todo when moved from parse
/*
cgb.CreateCommand("~osubind") cgb.CreateCommand("~osubind")
.Description("Bind discord user to osu name\n**Usage**: ~osubind @MyDiscordName My osu name") .Description("Bind discord user to osu name\n**Usage**: ~osubind My osu name")
.Parameter("user_name", ParameterType.Required)
.Parameter("osu_name", ParameterType.Unparsed) .Parameter("osu_name", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
var userName = e.GetArg("user_name"); var userName = e.GetArg("user_name");
@ -205,9 +217,6 @@ namespace NadekoBot.Modules {
await e.Send("Cannot find that discord user."); await e.Send("Cannot find that discord user.");
return; return;
} }
//query for a username
//if exists save bind pair to parse.com
//if not valid error
}); });
*/ */
}); });
@ -216,8 +225,6 @@ namespace NadekoBot.Modules {
public static async Task<Stream> GetResponseStream(string v) { public static async Task<Stream> GetResponseStream(string v) {
var wr = (HttpWebRequest)WebRequest.Create(v); var wr = (HttpWebRequest)WebRequest.Create(v);
try { try {
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
wr.UserAgent = @"Mozilla/5.0 (Windows NT 6.2; Win64; x64)";
return (await (wr).GetResponseAsync()).GetResponseStream(); return (await (wr).GetResponseAsync()).GetResponseStream();
} catch (Exception ex) { } catch (Exception ex) {
Console.WriteLine("error in getresponse stream " + ex); Console.WriteLine("error in getresponse stream " + ex);