static async Task Main(string[] args) { System.Console.WriteLine("Please provide API Key."); string apiKey = System.Console.ReadLine(); var factory = OsuApiClientFactory.CreateFactory(new[] { "a", "b" }); IOsuApiClient osuApiClient = factory.CreateHttpApi(); var user = await osuApiClient.GetUser(6659067, Mode.Mania); var user2 = await osuApiClient.GetUser("bleatingsheep"); var beatmaps = await osuApiClient.GetBeatmaps(Mode.Mania, false, DateTime.Now - TimeSpan.FromDays(2), 100); var s = await osuApiClient.GetScores(1, Mode.Standard, 100); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { DateTimeOffset now = DateTimeOffset.UtcNow; DateTimeOffset start = now.AddYears(-1); int? osuId = await _dataProvider.GetOsuIdAsync(context.UserId).ConfigureAwait(false); if (osuId == null) { _ = await api.SendMessageAsync(context.Endpoint, "未绑定").ConfigureAwait(false); return; } UserSnapshot?snap = await _newbieContext.UserSnapshots .Where(s => s.UserId == osuId && s.Mode == _mode && s.Date > start) .OrderBy(s => s.Date) .FirstOrDefaultAsync().ConfigureAwait(false); if (snap is null) { _ = await api.SendMessageAsync(context.Endpoint, "没有找到数据").ConfigureAwait(false); return; } UserInfo?userInfo = await _osuApiClient.GetUser(osuId.Value, _mode).ConfigureAwait(false); if (userInfo is null) { userInfo = (await _newbieContext.UserSnapshots .Where(s => s.UserId == osuId && s.Mode == _mode) .OrderByDescending(s => s.Date) .FirstAsync().ConfigureAwait(false)).UserInfo; } int startPC = snap.UserInfo.PlayCount; int currentPC = userInfo.PlayCount; List <UserPlayRecord> playList = await _newbieContext.UserPlayRecords .Where(r => r.UserId == osuId && r.Mode == _mode && r.PlayNumber > startPC) .OrderBy(r => r.PlayNumber) .ToListAsync().ConfigureAwait(false); _ = await api.SendMessageAsync(context.Endpoint, $"数据完整度:{playList.Count} of {currentPC - startPC}。功能制作中。").ConfigureAwait(false); if (playList.Count == 0) { return; } // assign data to fields. _userPlayRecords = playList; { // days played (int days, int totalDays) = GetPlayedDays(); _ = await api.SendMessageAsync(context.Endpoint, $"你在过去一年中有 {days} 天打了图。").ConfigureAwait(false); } { // most played (int bid, int count, BeatmapInfo? beatmap) = await GetMostPlayedBeatmapAsync().ConfigureAwait(false); _ = await api.SendMessageAsync(context.Endpoint, $"你最常打的一张图是 {bid},打了 {count} 次。" + $"{beatmap}").ConfigureAwait(false); } { // most playing hour var mostPlayingHour = GetMostPlayingHours(); _ = await api.SendMessageAsync(context.Endpoint, $"你最常在 {mostPlayingHour}-{mostPlayingHour + 1} 时打图。").ConfigureAwait(false); } }