public ScoreInfoEmbed(UserBest userBest) { ScoreInfo scoreInfo = userBest.newScore; UserInfo userInfo = ConvertOsuData.GetUserInfo(scoreInfo.user_id); MapInfo mapInfo = ConvertOsuData.getMapInfo(scoreInfo.beatmap_id); EmbedBuilder builder = new EmbedBuilder() .WithTitle(string.Format("\n{0} - {1}", mapInfo.artist, mapInfo.title)) .WithDescription(string.Format("**[{0}] {1}**\n", mapInfo.version, ConvertOsuData.modsToString(scoreInfo.enabled_mods))) .WithUrl(string.Format("https://osu.ppy.sh/beatmapsets/{0}#osu/{1}", mapInfo.beatmapset_id, scoreInfo.beatmap_id)) .WithColor(new Color(0xFF69B4)) .WithTimestamp(ConvertOsuData.dateToOffset(scoreInfo.date)) .WithFooter(footer => { footer .WithText((userBest.newScoreIndex + 1) + "번째 탑 플레이"); }) .WithThumbnailUrl(ConvertOsuData.rankToImageUrl(scoreInfo.rank)) .WithImageUrl(string.Format("https://assets.ppy.sh/beatmaps/{0}/covers/cover.jpg", mapInfo.beatmapset_id)) .WithAuthor(author => { author .WithName(userInfo.username) .WithUrl("https://osu.ppy.sh/users/" + userInfo.user_id) .WithIconUrl("https://github.com/ppy/osu/blob/master/assets/lazer.png?raw=true"); }) .AddField("퍼포먼스", string.Format("{0:0.0#}pp", scoreInfo.pp)) .AddField("콤보", string.Format("{0}/{1}", scoreInfo.maxcombo, mapInfo.max_combo), true) .AddField("정확도", string.Format("{0:0.0#}%", ConvertOsuData.getAccuracy(scoreInfo.count300, scoreInfo.count100, scoreInfo.count50, scoreInfo.countmiss)), true) .AddField("\u200B", "\u200B", true) .AddField("300", "x" + scoreInfo.count300, true) .AddField("100", "x" + scoreInfo.count100, true) .AddField("\u200B", "\u200B", true) .AddField("50", "x" + scoreInfo.count50, true) .AddField("미스", "x" + scoreInfo.countmiss, true) .AddField("\u200B", "\u200B", true); embed = builder.Build(); }
public async Task checkNewScores() { DataTable users = Sql.Get("SELECT user_id FROM targets GROUP BY user_id"); // 타겟 유저 마다 검사 foreach (DataRow user in users.Rows) { try { string user_id = user["user_id"].ToString(); var userBest = new UserBest(user_id); // 새로운 베퍼포가 있을 경우 if (userBest.newScore != null) { var scoreInfoEmbed = new ScoreInfoEmbed(userBest); DataTable channels = Sql.Get("SELECT guild_id, channel_id FROM targets WHERE user_id = '{0}'", user_id); foreach (DataRow channel in channels.Rows) { ulong guild_id = 0; ulong channel_id = 0; // 스코어 정보 전송 try { guild_id = ulong.Parse(channel["guild_id"].ToString()); channel_id = ulong.Parse(channel["channel_id"].ToString()); var socketTextChannel = _client.GetGuild(guild_id).GetTextChannel(channel_id); await socketTextChannel.SendMessageAsync(embed : scoreInfoEmbed.embed); } // 실패 시 채널이 삭제된 것으로 판단하고 DB에서 삭제 catch (NullReferenceException) { Sql.Execute("DELETE FROM targets WHERE channel_id = '{0}'", channel_id); // 해당 서버에서 삭제한 유저가 타겟에 더 이상 없을 경우 점수 기록도 삭제 DataTable findUser = Sql.Get("SELECT user_id FROM targets WHERE user_id = {0}", user_id); if (findUser.Rows.Count == 0) { Sql.Execute("DELETE FROM pphistories WHERE user_id = {0}", user_id); } } } } } catch (Exception e) { Console.WriteLine(e.Message); } } Thread.Sleep(1000); await Task.Factory.StartNew(() => checkNewScores()); }
public async Task CheckNewBest() { DataTable userTable = Sql.Get("SELECT user_id FROM targets GROUP BY user_id"); // 타겟 유저 마다 검사 foreach (DataRow userRow in userTable.Rows) { try { UserBest userBest; User user = User.Search((int)userRow["user_id"]); // 이전 pp 기록이 있는지 확인 DataTable ppHistorySearchTable = Sql.Get( "SELECT p.user_id FROM pphistories p, targets t " + "WHERE p.user_id = {0} AND p.user_id = t.user_id", user.user_id ); // 이전 pp 기록이 없을 경우 새로 삽입하고 다음 타겟 검사 if (ppHistorySearchTable.Rows.Count == 0) { userBest = new UserBest(user.user_id); Sql.Execute("INSERT INTO pphistories VALUES ({0}, {1}, {2}, {3})", user.user_id, userBest.pp_sum, user.pp_raw, user.pp_rank); continue; } double previous_pp_raw = Convert.ToDouble(Sql.Get("SELECT pp_raw FROM pphistories WHERE user_id = {0}", user.user_id).Rows[0]["pp_raw"]); // pp 변화가 없을 경우 다음 타겟 검사 if (previous_pp_raw.IsCloseTo(user.pp_raw)) { continue; } // pp 변화가 있을 경우 새로운 베퍼포가 있는지 확인 userBest = new UserBest(user.user_id); userBest.GetNewBest(); // 새로운 베퍼포가 없을 경우 다음 타겟 검사 if (userBest.newBest == null) { continue; } ScoreEmbed scoreEmbed = new ScoreEmbed(userBest); DataTable guildTable = Sql.Get("SELECT guild_id FROM targets WHERE user_id = '{0}'", user.user_id); foreach (DataRow guildRow in guildTable.Rows) { ulong guild_id = ulong.Parse(guildRow["guild_id"].ToString()); SocketGuild guild = _client.GetGuild(guild_id); try { SocketTextChannel osuTrackerChannel = await guild.CreateChannelIfNotExist("osu-tracker"); await osuTrackerChannel.SendMessageAsync(embed : scoreEmbed.Build()); } catch (Exception e) { Console.WriteLine(e.Message); } } } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(userRow["user_id"]); } Sql.Execute("DELETE FROM pphistories WHERE user_id NOT IN (SELECT user_id FROM targets)"); await Task.Factory.StartNew(() => CheckNewBest()); }