public async override void CheckForChange_Elapsed(object stateinfo) { try { foreach (var pp in AllPP.ToList()) { OsuResult userInformation = await fetchUser(pp.Key); try{ if (pp.Value + ChannelConfig.Select(x => (double)x.Value[PPTHRESHOLD]).Min() >= double.Parse(userInformation.pp_raw, CultureInfo.InvariantCulture)) { continue; } } catch { continue; } var recentScores = await fetchRecent(pp.Key); RecentScore scoreInformation = recentScores.FirstOrDefault(x => !x.rank.Equals("F")); Beatmap beatmapInformation = scoreInformation != null ? await fetchBeatmap(scoreInformation.beatmap_id, pp.Key, int.Parse(scoreInformation.enabled_mods)) : null; if (userInformation == null) { return; } foreach (var channel in ChannelConfig) { if (pp.Value > 0 && pp.Value + (double)channel.Value[PPTHRESHOLD] <= double.Parse(userInformation.pp_raw, CultureInfo.InvariantCulture)) { if (scoreInformation == null) { AllPP[pp.Key] = double.Parse(userInformation.pp_raw ?? "0", CultureInfo.InvariantCulture); await UpdateTracker(); return; } await OnMajorChangeTracked(channel.Key, createEmbed(userInformation, beatmapInformation, await fetchScore(scoreInformation.beatmap_id, pp.Key), Math.Round(double.Parse(userInformation.pp_raw, CultureInfo.InvariantCulture) - pp.Value, 2), pp.Key), (string)channel.Value["Notification"]); } if (pp.Value != double.Parse(userInformation.pp_raw ?? "0", CultureInfo.InvariantCulture)) { AllPP[pp.Key] = double.Parse(userInformation.pp_raw ?? "0", CultureInfo.InvariantCulture); await UpdateTracker(); } } } } catch (Exception e) { if (!e.StackTrace.StartsWith("The read operation failed") && !e.Message.Contains("error occurred while sending the request")) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e)); } } }
private Embed createEmbed(OsuResult userInformation, Beatmap beatmapInformation, Score scoreInformation, double ppChange, string mode = "m=0") { EmbedBuilder e = new EmbedBuilder(); e.Color = new Color(255, 87, 156); e.Title = $"{beatmapInformation.artist} - {beatmapInformation.title} [{beatmapInformation.version}]"; e.Url = $"https://osu.ppy.sh/b/{beatmapInformation.beatmap_id}&m={beatmapInformation.mode}"; e.Description = Math.Round(double.Parse(beatmapInformation.difficultyrating, CultureInfo.InvariantCulture), 2) + "*\n" + (Mods)int.Parse(scoreInformation.enabled_mods); e.Timestamp = DateTime.Parse(scoreInformation.date).AddHours(1); EmbedAuthorBuilder author = new EmbedAuthorBuilder(); author.Name = Name; author.Url = $"https://osu.ppy.sh/u/{userInformation.user_id}"; author.IconUrl = $"https://a.ppy.sh/{userInformation.user_id}_0.png"; e.Author = author; EmbedFooterBuilder footer = new EmbedFooterBuilder(); footer.IconUrl = "https://vignette.wikia.nocookie.net/cytus/images/5/51/Osu_icon.png"; footer.Text = "Osu!"; e.Footer = footer; switch (mode) { case "m=0": e.ThumbnailUrl = "https://lemmmy.pw/osusig/img/osu.png"; break; case "m=1": e.ThumbnailUrl = "https://lemmmy.pw/osusig/img/taiko.png"; break; case "m=2": e.ThumbnailUrl = "https://lemmmy.pw/osusig/img/ctb.png"; break; case "m=3": e.ThumbnailUrl = "https://lemmmy.pw/osusig/img/mania.png"; break; } e.ImageUrl = $"https://b.ppy.sh/thumb/{beatmapInformation.beatmapset_id}l.jpg"; e.AddField("Score", scoreInformation.score + $" ({scoreInformation.maxcombo}/{beatmapInformation.max_combo}x)", true); e.AddField("Acc", calcAcc(scoreInformation, int.Parse(beatmapInformation.mode)) + $"% {scoreInformation.rank}", true); e.AddField("PP for play", Math.Round(double.Parse(scoreInformation.pp ?? "NaN", CultureInfo.InvariantCulture), 2) + $" (+{ppChange})", true); e.AddField("Rank", userInformation.pp_rank, true); return(e.Build()); }