/// <summary> /// Build embed from beatmap and beatmapset information /// </summary> /// <param name="bm">Beatmap object</param> /// <param name="bms">Beatmapset object</param> /// <param name="gBeatmap">Beatmap object from gatari (if exists)</param> /// <returns></returns> public DiscordEmbed BeatmapToEmbed(Beatmap bm, Beatmapset bms, GBeatmap gBeatmap = null) { DiscordEmbedBuilder embedBuilder = new DiscordEmbedBuilder(); TimeSpan mapLen = TimeSpan.FromSeconds(bm.total_length); DiscordEmoji banchoRankEmoji = osuEmoji.RankStatusEmoji(bm.ranked); DiscordEmoji diffEmoji = osuEmoji.DiffEmoji(bm.difficulty_rating); StringBuilder embedMsg = new StringBuilder(); embedMsg.AppendLine($"{diffEmoji} **__[{bm.version}]__**\n▸**Difficulty**: {bm.difficulty_rating}★\n▸**CS**: {bm.cs} ▸**HP**: {bm.drain} ▸**AR**: {bm.ar} ▸**OD**: {bm.accuracy}\n\nBancho: {banchoRankEmoji} : [link](https://osu.ppy.sh/beatmapsets/{bms.id}#osu/{bm.id})\nLast updated: {bm.last_updated}"); if (!(gBeatmap is null)) { DiscordEmoji gatariRankEmoji = osuEmoji.RankStatusEmoji(gBeatmap.ranked); embedMsg.AppendLine($"\nGatari: {gatariRankEmoji} : [link](https://osu.gatari.pw/s/{gBeatmap.beatmapset_id}#osu/{gBeatmap.beatmap_id})\nLast updated: {(gBeatmap.ranking_data != 0 ? new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(gBeatmap.ranking_data).ToString() : "")}"); } // Construct embed embedBuilder.WithTitle($"{banchoRankEmoji} {bms.artist} – {bms.title} by {bms.creator}"); embedBuilder.WithUrl(bm.url); embedBuilder.AddField($"Length: {mapLen.Minutes}:{string.Format("{0:00}", mapLen.Seconds)}, BPM: {bm.bpm}", embedMsg.ToString(), true); embedBuilder.WithThumbnail(bms.covers.List2x); embedBuilder.WithFooter(bms.tags); return(embedBuilder.Build()); }
/// <summary> /// Начинает отслеживание реакций сообщения с картинкой. /// </summary> /// <param name="message">Отслеживаемое изображение</param> /// <param name="attachment">Картинка</param> private async Task ExecuteMessageTrack(DiscordMessage message, DiscordAttachment attachment) { var res = await queue.QueueTask(() => DownloadAndRecognizeImage(attachment)); if (res == null) { return; } Beatmapset banchoBeatmapset = res.Item1; Beatmap banchoBeatmap = res.Item2; // Ignore beatmap for several minutes foreach (var kvp in ignoreList) { if (DateTime.Now - kvp.Value > TimeSpan.FromMinutes(10)) { ignoreList.Remove(kvp.Key); } } if (ignoreList.ContainsKey(banchoBeatmap.id)) { logger.LogInformation($"Beatmap is in ignore list {banchoBeatmap.id}"); return; } ignoreList.Add(banchoBeatmap.id, DateTime.Now); // Contruct message DiscordEmbedBuilder embedBuilder = new DiscordEmbedBuilder(); TimeSpan mapLen = TimeSpan.FromSeconds(banchoBeatmap.total_length); DiscordEmoji banchoRankEmoji = emoji.RankStatusEmoji(banchoBeatmap.ranked); DiscordEmoji diffEmoji = emoji.DiffEmoji(banchoBeatmap.difficulty_rating); // Check gatari GBeatmap gBeatmap = gapi.TryGetBeatmap(banchoBeatmap.id); DiscordEmbed embed = utils.BeatmapToEmbed(banchoBeatmap, banchoBeatmapset, gBeatmap); await message.RespondAsync(embed : embed); }
private async Task Client_MessageCreated(DiscordClient sender, DSharpPlus.EventArgs.MessageCreateEventArgs e) { if (!e.Message.Content.Contains("http")) return; if (!(e.Channel.Name.Contains("-osu") || e.Channel.Name.Contains("map-offer") || e.Channel.Name.Contains("bot-debug") || e.Channel.Name.Contains("dev-announce") || e.Channel.Name.Contains("www-register"))) return; // Check, if it is map url from bancho Tuple<int, int> BMSandBMid = utils.GetBMandBMSIdFromBanchoUrl(e.Message.Content); if (!(BMSandBMid is null)) { int bms_id = BMSandBMid.Item1, bm_id = BMSandBMid.Item2; Beatmap bm = api.GetBeatmap(bm_id); Beatmapset bms = api.GetBeatmapset(bms_id); GBeatmap gbm = gapi.TryGetBeatmap(bm_id); if (!(bm is null || bms is null)) { DiscordEmbed embed = utils.BeatmapToEmbed(bm, bms, gbm); await e.Message.RespondAsync(embed: embed); } return; } // Check, if it is beatmapset url from gatari int? BMSid = utils.GetBMSIdFromGatariUrl(e.Message.Content); if (!(BMSid is null)) { int bms_id = (int)BMSid; Beatmapset bms = api.GetBeatmapset(bms_id); int bm_id = bms.beatmaps.First().id; Beatmap bm = api.GetBeatmap(bm_id); GBeatmap gbm = gapi.TryGetBeatmap(bm_id); if (!(bm is null || bms is null)) { DiscordEmbed embed = utils.BeatmapToEmbed(bm, bms, gbm); await e.Message.RespondAsync(embed: embed); } return; } // Check, if it is beatmap url from gatari int? BMid = utils.GetBMIdFromGatariUrl(e.Message.Content); if (!(BMid is null)) { int bm_id = (int)BMid; Beatmap bm = api.GetBeatmap(bm_id); Beatmapset bms = api.GetBeatmapset(bm.beatmapset_id); GBeatmap gbm = gapi.TryGetBeatmap(bm_id); if (!(bm is null || bms is null)) { DiscordEmbed embed = utils.BeatmapToEmbed(bm, bms, gbm); await e.Message.RespondAsync(embed: embed); } return; } // Check, if it is user link from bancho int? userId = utils.GetUserIdFromBanchoUrl(e.Message.Content); if (!(userId is null)) { int user_id = (int)userId; User user = null; if (!api.TryGetUser(user_id, ref user)) return; List<Score> scores = api.GetUserBestScores(user_id, 5); if (!(scores is null) && scores.Count == 5) { DiscordEmbed embed = utils.UserToEmbed(user, scores); await e.Message.RespondAsync(embed: embed); } return; } // Check, if it is user link from bancho int? guserId = utils.GetUserIdFromGatariUrl(e.Message.Content); if (!(guserId is null)) { int guser_id = (int)guserId; GUser guser = null; if (!gapi.TryGetUser(guser_id, ref guser)) return; List<GScore> gscores = gapi.GetUserBestScores(guser.id, 5); if (gscores is null || gscores.Count == 0) return; GStatistics gstats = gapi.GetUserStats(guser.username); if (gstats is null) return; DiscordEmbed gembed = utils.UserToEmbed(guser, gstats, gscores); await e.Message.RespondAsync(embed: gembed); return; } }