thx visual studio
This commit is contained in:
parent
f06ab16a2f
commit
72ecafd552
@ -19,18 +19,23 @@ namespace NadekoBot.Commands {
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<CachedChampion> CachedChampionImages = new List<CachedChampion>();
|
private static Dictionary<string, CachedChampion> CachedChampionImages = new Dictionary<string, CachedChampion>();
|
||||||
private readonly object cacheLock = new object();
|
private readonly object cacheLock = new object();
|
||||||
|
|
||||||
|
|
||||||
|
private System.Timers.Timer clearTimer { get; } = new System.Timers.Timer();
|
||||||
public LoLCommands() : base() {
|
public LoLCommands() : base() {
|
||||||
Task.Run(async () => {
|
clearTimer.Interval = new TimeSpan(0, 10, 0).TotalMilliseconds;
|
||||||
while (true) {
|
clearTimer.Start();
|
||||||
lock (cacheLock) {
|
clearTimer.Elapsed += (s, e) => {
|
||||||
CachedChampionImages = CachedChampionImages.Where(cc => DateTime.Now - cc.AddedAt < new TimeSpan(1, 0, 0)).ToList();
|
try {
|
||||||
}
|
lock (cacheLock)
|
||||||
await Task.Delay(new TimeSpan(0, 10, 0));
|
CachedChampionImages = CachedChampionImages
|
||||||
|
.Where(kvp => DateTime.Now - kvp.Value.AddedAt > new TimeSpan(1, 0, 0))
|
||||||
|
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||||
}
|
}
|
||||||
});
|
catch { }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] trashTalk = new[] { "Better ban your counters. You are going to carry the game anyway.",
|
string[] trashTalk = new[] { "Better ban your counters. You are going to carry the game anyway.",
|
||||||
@ -61,10 +66,11 @@ namespace NadekoBot.Commands {
|
|||||||
try {
|
try {
|
||||||
//get role
|
//get role
|
||||||
string role = ResolvePos(e.GetArg("position"));
|
string role = ResolvePos(e.GetArg("position"));
|
||||||
|
string resolvedRole = role;
|
||||||
var name = e.GetArg("champ").Replace(" ", "");
|
var name = e.GetArg("champ").Replace(" ", "");
|
||||||
CachedChampion champ;
|
CachedChampion champ = null;
|
||||||
lock (cacheLock) {
|
lock (cacheLock) {
|
||||||
champ = CachedChampionImages.Where(cc => cc.Name == name.ToLower()).FirstOrDefault();
|
CachedChampionImages.TryGetValue(name + "_" + resolvedRole, out champ);
|
||||||
}
|
}
|
||||||
if (champ != null) {
|
if (champ != null) {
|
||||||
Console.WriteLine("Sending lol image from cache.");
|
Console.WriteLine("Sending lol image from cache.");
|
||||||
@ -89,6 +95,16 @@ namespace NadekoBot.Commands {
|
|||||||
else {
|
else {
|
||||||
data = allData[0];
|
data = allData[0];
|
||||||
role = allData[0]["role"].ToString();
|
role = allData[0]["role"].ToString();
|
||||||
|
resolvedRole = ResolvePos(role);
|
||||||
|
}
|
||||||
|
lock (cacheLock) {
|
||||||
|
CachedChampionImages.TryGetValue(name + "_" + resolvedRole, out champ);
|
||||||
|
}
|
||||||
|
if (champ != null) {
|
||||||
|
Console.WriteLine("Sending lol image from cache.");
|
||||||
|
champ.ImageStream.Position = 0;
|
||||||
|
await e.Channel.SendFile("champ.png", champ.ImageStream);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//name = data["title"].ToString();
|
//name = data["title"].ToString();
|
||||||
// get all possible roles, and "select" the shown one
|
// get all possible roles, and "select" the shown one
|
||||||
@ -217,8 +233,8 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
|
|||||||
smallImgSize));
|
smallImgSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var cachedChamp = new CachedChampion { AddedAt = DateTime.Now, ImageStream = img.ToStream(System.Drawing.Imaging.ImageFormat.Png), Name = name.ToLower() };
|
var cachedChamp = new CachedChampion { AddedAt = DateTime.Now, ImageStream = img.ToStream(System.Drawing.Imaging.ImageFormat.Png), Name = name.ToLower() + "_" + resolvedRole };
|
||||||
CachedChampionImages.Add(cachedChamp);
|
CachedChampionImages.Add(cachedChamp.Name, cachedChamp);
|
||||||
await e.Channel.SendFile(data["title"] + "_stats.png", cachedChamp.ImageStream);
|
await e.Channel.SendFile(data["title"] + "_stats.png", cachedChamp.ImageStream);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@ -579,10 +579,9 @@ namespace NadekoBot.Modules {
|
|||||||
|
|
||||||
cgb.CreateCommand(".unstuck")
|
cgb.CreateCommand(".unstuck")
|
||||||
.Description("Clears the message queue. **OWNER ONLY**")
|
.Description("Clears the message queue. **OWNER ONLY**")
|
||||||
.Do(async e => {
|
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
||||||
if (e.User.Id != NadekoBot.OwnerID)
|
.Do(e => {
|
||||||
return;
|
NadekoBot.client.MessageQueue.Clear();
|
||||||
await Task.Run(() => NadekoBot.client.MessageQueue.Clear());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(".donators")
|
cgb.CreateCommand(".donators")
|
||||||
|
Loading…
Reference in New Issue
Block a user