thx visual studio

This commit is contained in:
Master Kwoth 2016-02-29 05:30:08 +01:00
parent f06ab16a2f
commit 72ecafd552
2 changed files with 990 additions and 975 deletions

View File

@ -19,18 +19,23 @@ namespace NadekoBot.Commands {
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 System.Timers.Timer clearTimer { get; } = new System.Timers.Timer();
public LoLCommands() : base() {
Task.Run(async () => {
while (true) {
lock (cacheLock) {
CachedChampionImages = CachedChampionImages.Where(cc => DateTime.Now - cc.AddedAt < new TimeSpan(1, 0, 0)).ToList();
clearTimer.Interval = new TimeSpan(0, 10, 0).TotalMilliseconds;
clearTimer.Start();
clearTimer.Elapsed += (s, e) => {
try {
lock (cacheLock)
CachedChampionImages = CachedChampionImages
.Where(kvp => DateTime.Now - kvp.Value.AddedAt > new TimeSpan(1, 0, 0))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
}
await Task.Delay(new TimeSpan(0, 10, 0));
}
});
catch { }
};
}
string[] trashTalk = new[] { "Better ban your counters. You are going to carry the game anyway.",
@ -61,10 +66,11 @@ namespace NadekoBot.Commands {
try {
//get role
string role = ResolvePos(e.GetArg("position"));
string resolvedRole = role;
var name = e.GetArg("champ").Replace(" ", "");
CachedChampion champ;
CachedChampion champ = null;
lock (cacheLock) {
champ = CachedChampionImages.Where(cc => cc.Name == name.ToLower()).FirstOrDefault();
CachedChampionImages.TryGetValue(name + "_" + resolvedRole, out champ);
}
if (champ != null) {
Console.WriteLine("Sending lol image from cache.");
@ -89,6 +95,16 @@ namespace NadekoBot.Commands {
else {
data = allData[0];
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();
// get all possible roles, and "select" the shown one
@ -217,8 +233,8 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
smallImgSize));
}
}
var cachedChamp = new CachedChampion { AddedAt = DateTime.Now, ImageStream = img.ToStream(System.Drawing.Imaging.ImageFormat.Png), Name = name.ToLower() };
CachedChampionImages.Add(cachedChamp);
var cachedChamp = new CachedChampion { AddedAt = DateTime.Now, ImageStream = img.ToStream(System.Drawing.Imaging.ImageFormat.Png), Name = name.ToLower() + "_" + resolvedRole };
CachedChampionImages.Add(cachedChamp.Name, cachedChamp);
await e.Channel.SendFile(data["title"] + "_stats.png", cachedChamp.ImageStream);
}
catch (Exception ex) {

View File

@ -579,10 +579,9 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(".unstuck")
.Description("Clears the message queue. **OWNER ONLY**")
.Do(async e => {
if (e.User.Id != NadekoBot.OwnerID)
return;
await Task.Run(() => NadekoBot.client.MessageQueue.Clear());
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
.Do(e => {
NadekoBot.client.MessageQueue.Clear();
});
cgb.CreateCommand(".donators")