lolban added
This commit is contained in:
parent
378897de81
commit
83f224d9d5
@ -172,60 +172,74 @@ namespace NadekoBot.Classes.Music {
|
||||
|
||||
private async Task BufferSong() {
|
||||
//start feeding the buffer
|
||||
var psi = new ProcessStartInfo {
|
||||
FileName = "ffmpeg",
|
||||
Arguments = $"-i {Url} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", //+ (NadekoBot.IsLinux ? "2> /dev/null" : "2>NUL"),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
};
|
||||
using (var p = Process.Start(psi)) {
|
||||
int attempt = 0;
|
||||
while (true) {
|
||||
while (buffer.writePos - buffer.readPos > 5.MB() && State != StreamState.Completed) {
|
||||
prebufferingComplete = true;
|
||||
await Task.Delay(200);
|
||||
}
|
||||
|
||||
if (State == StreamState.Completed) {
|
||||
Console.WriteLine("Buffering canceled, stream is completed.");
|
||||
return;
|
||||
}
|
||||
if (buffer.readPos > 5.MiB() && buffer.writePos > 5.MiB()) {
|
||||
var skip = 5.MB();
|
||||
lock (_bufferLock) {
|
||||
byte[] data = new byte[buffer.Length - skip];
|
||||
Buffer.BlockCopy(buffer.GetBuffer(), skip, data, 0, (int)(buffer.Length - skip));
|
||||
var newReadPos = buffer.readPos - skip;
|
||||
var newPos = buffer.Position - skip;
|
||||
buffer = new DualStream();
|
||||
buffer.Write(data, 0, data.Length);
|
||||
buffer.readPos = newReadPos;
|
||||
buffer.Position = newPos;
|
||||
Process p = null;
|
||||
try {
|
||||
var psi = new ProcessStartInfo {
|
||||
FileName = "ffmpeg",
|
||||
Arguments = $"-i {Url} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", //+ (NadekoBot.IsLinux ? "2> /dev/null" : "2>NUL"),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
};
|
||||
using (p = Process.Start(psi)) {
|
||||
int attempt = 0;
|
||||
while (true) {
|
||||
while (buffer.writePos - buffer.readPos > 5.MB() && State != StreamState.Completed) {
|
||||
prebufferingComplete = true;
|
||||
await Task.Delay(200);
|
||||
}
|
||||
}
|
||||
int blockSize = 1920 * NadekoBot.client.GetService<AudioService>()?.Config?.Channels ?? 3840;
|
||||
var buf = new byte[blockSize];
|
||||
int read = 0;
|
||||
read = await p.StandardOutput.BaseStream.ReadAsync(buf, 0, blockSize);
|
||||
//Console.WriteLine($"Read: {read}");
|
||||
if (read == 0) {
|
||||
if (attempt == 5) {
|
||||
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length");
|
||||
|
||||
if (State == StreamState.Completed) {
|
||||
Console.WriteLine("Buffering canceled, stream is completed.");
|
||||
p.Close();
|
||||
return;
|
||||
}
|
||||
if (buffer.readPos > 5.MiB() && buffer.writePos > 5.MiB()) {
|
||||
var skip = 5.MB();
|
||||
lock (_bufferLock) {
|
||||
byte[] data = new byte[buffer.Length - skip];
|
||||
Buffer.BlockCopy(buffer.GetBuffer(), skip, data, 0, (int)(buffer.Length - skip));
|
||||
var newReadPos = buffer.readPos - skip;
|
||||
var newPos = buffer.Position - skip;
|
||||
buffer = new DualStream();
|
||||
buffer.Write(data, 0, data.Length);
|
||||
buffer.readPos = newReadPos;
|
||||
buffer.Position = newPos;
|
||||
}
|
||||
}
|
||||
int blockSize = 1920 * NadekoBot.client.GetService<AudioService>()?.Config?.Channels ?? 3840;
|
||||
var buf = new byte[blockSize];
|
||||
int read = 0;
|
||||
read = await p.StandardOutput.BaseStream.ReadAsync(buf, 0, blockSize);
|
||||
//Console.WriteLine($"Read: {read}");
|
||||
if (read == 0) {
|
||||
if (attempt == 5) {
|
||||
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length");
|
||||
p.Close();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
++attempt;
|
||||
await Task.Delay(20);
|
||||
}
|
||||
}
|
||||
else {
|
||||
++attempt;
|
||||
await Task.Delay(20);
|
||||
}
|
||||
}
|
||||
else {
|
||||
attempt = 0;
|
||||
lock (_bufferLock) {
|
||||
buffer.Write(buf, 0, read);
|
||||
attempt = 0;
|
||||
lock (_bufferLock) {
|
||||
buffer.Write(buf, 0, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
finally {
|
||||
if (p != null) {
|
||||
p.Close();
|
||||
p.Dispose();
|
||||
p = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task StartPlayback() {
|
||||
|
@ -10,6 +10,14 @@ using NadekoBot.Extensions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
namespace NadekoBot.Commands {
|
||||
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() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@ -24,7 +32,7 @@ namespace NadekoBot.Commands {
|
||||
|
||||
public override void Init(CommandGroupBuilder cgb) {
|
||||
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("position", ParameterType.Unparsed)
|
||||
.Do(async e => {
|
||||
@ -59,7 +67,7 @@ namespace NadekoBot.Commands {
|
||||
if (roles[i] == role)
|
||||
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)
|
||||
.FirstOrDefault()?["general"];
|
||||
if (general == null) {
|
||||
@ -181,6 +189,35 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
|
||||
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 {
|
||||
Champion,
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user