/// <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; } }