lolban added

This commit is contained in:
Master Kwoth 2016-02-24 02:43:27 +01:00
parent 378897de81
commit 83f224d9d5
6 changed files with 98 additions and 47 deletions

View File

@ -172,13 +172,16 @@ namespace NadekoBot.Classes.Music {
private async Task BufferSong() { private async Task BufferSong() {
//start feeding the buffer //start feeding the buffer
Process p = null;
try {
var psi = new ProcessStartInfo { var psi = new ProcessStartInfo {
FileName = "ffmpeg", FileName = "ffmpeg",
Arguments = $"-i {Url} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", //+ (NadekoBot.IsLinux ? "2> /dev/null" : "2>NUL"), Arguments = $"-i {Url} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", //+ (NadekoBot.IsLinux ? "2> /dev/null" : "2>NUL"),
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = true, RedirectStandardOutput = true,
}; };
using (var p = Process.Start(psi)) { using (p = Process.Start(psi)) {
int attempt = 0; int attempt = 0;
while (true) { while (true) {
while (buffer.writePos - buffer.readPos > 5.MB() && State != StreamState.Completed) { while (buffer.writePos - buffer.readPos > 5.MB() && State != StreamState.Completed) {
@ -188,6 +191,7 @@ namespace NadekoBot.Classes.Music {
if (State == StreamState.Completed) { if (State == StreamState.Completed) {
Console.WriteLine("Buffering canceled, stream is completed."); Console.WriteLine("Buffering canceled, stream is completed.");
p.Close();
return; return;
} }
if (buffer.readPos > 5.MiB() && buffer.writePos > 5.MiB()) { if (buffer.readPos > 5.MiB() && buffer.writePos > 5.MiB()) {
@ -211,6 +215,7 @@ namespace NadekoBot.Classes.Music {
if (read == 0) { if (read == 0) {
if (attempt == 5) { if (attempt == 5) {
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length"); Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length");
p.Close();
return; return;
} }
else { else {
@ -227,6 +232,15 @@ namespace NadekoBot.Classes.Music {
} }
} }
} }
catch { }
finally {
if (p != null) {
p.Close();
p.Dispose();
p = null;
}
}
}
internal async Task StartPlayback() { internal async Task StartPlayback() {
Console.WriteLine("Starting playback."); Console.WriteLine("Starting playback.");

View File

@ -10,6 +10,14 @@ using NadekoBot.Extensions;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace NadekoBot.Commands { namespace NadekoBot.Commands {
class LoLCommands : DiscordCommand { class LoLCommands : DiscordCommand {
string[] trashTalk = new[] { "Better ban your counters. You are going to carry the game anyway.",
"Go with the flow. Don't think. Just ban one of these.",
"DONT READ BELOW! Ban Urgot mid OP 100%. Im smurf Diamond 1.",
"Ask your teammates what would they like to play, and ban that.",
"If you consider playing teemo, do it. If you consider teemo, you deserve him.",
"Doesn't matter what you ban really. Enemy will ban your main and you will lose." };
public override Func<CommandEventArgs, Task> DoFunc() { public override Func<CommandEventArgs, Task> DoFunc() {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -24,7 +32,7 @@ namespace NadekoBot.Commands {
public override void Init(CommandGroupBuilder cgb) { public override void Init(CommandGroupBuilder cgb) {
cgb.CreateCommand("~lolchamp") cgb.CreateCommand("~lolchamp")
.Description("Checks champion statistic for a lol champion.") .Description("Shows League Of Legends champion statistics. Optional second parameter is a role.\n**Usage:**~lolchamp Riven or ~lolchamp Annie sup")
.Parameter("champ", ParameterType.Required) .Parameter("champ", ParameterType.Required)
.Parameter("position", ParameterType.Unparsed) .Parameter("position", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
@ -59,7 +67,7 @@ namespace NadekoBot.Commands {
if (roles[i] == role) if (roles[i] == role)
roles[i] = ">" + roles[i] + "<"; roles[i] = ">" + roles[i] + "<";
} }
var general = JArray.Parse(await Classes.SearchHelper.GetResponseAsync($"http://api.champion.gg/stats/champs/{name}?api_key={NadekoBot.creds.LOLAPIKey}")) var general = JArray.Parse(await Classes.SearchHelper.GetResponseAsync($"http://api.champion.gg/champion/{name}?api_key={NadekoBot.creds.LOLAPIKey}"))
.Where(jt => jt["role"].ToString() == role) .Where(jt => jt["role"].ToString() == role)
.FirstOrDefault()?["general"]; .FirstOrDefault()?["general"];
if (general == null) { if (general == null) {
@ -181,6 +189,35 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
return; return;
} }
}); });
cgb.CreateCommand("~lolban")
.Description("Shows top 6 banned champions ordered by ban rate. Ban these champions and you will be Plat 5 in no time.")
.Do(async e => {
int showCount = 6;
//http://api.champion.gg/stats/champs/mostBanned?api_key=YOUR_API_TOKEN&page=1&limit=2
try {
var data = JObject.Parse(
await Classes
.SearchHelper
.GetResponseAsync($"http://api.champion.gg/stats/champs/mostBanned?api_key={NadekoBot.creds.LOLAPIKey}&page=1&limit={showCount}"))["data"] as JArray;
StringBuilder sb = new StringBuilder();
sb.AppendLine($"**Showing {showCount} top banned champions.**");
sb.AppendLine($"`{trashTalk[new Random().Next(0, trashTalk.Length)]}`");
for (int i = 0; i < data.Count; i++) {
if (i % 2 == 0 && i != 0)
sb.AppendLine();
sb.Append($"`{i + 1}.` **{data[i]["name"]}** ");
//sb.AppendLine($" ({data[i]["general"]["banRate"]}%)");
}
await e.Channel.SendMessage(sb.ToString());
}
catch (Exception ex) {
await e.Channel.SendMessage($"Fail:\n{ex}");
}
});
} }
enum GetImageType { enum GetImageType {
Champion, Champion,

Binary file not shown.