protected async Task <UserInfo> EnsureGetUserInfo(string name, Bleatingsheep.Osu.Mode mode)
        {
            var(success, result) = await OsuApi.GetUserInfoAsync(name, mode);

            ExecutingException.Ensure(success, "网络错误。");
            ExecutingException.Ensure(result != null, "无此用户!");
            return(result);
        }
        /// <summary>
        /// 确保。
        /// </summary>
        /// <exception cref="ExecutingException"></exception>
        protected async Task <int> EnsureGetBindingIdAsync(long qq)
        {
            var(success, result) = await DataProvider.GetBindingIdAsync(qq);

            ExecutingException.Ensure(success, "哎,获取绑定信息失败了。");
            ExecutingException.Ensure(result != null, "没有绑定 osu! 账号。见https://github.com/bltsheep/OsuQqBotForNewbieGroup/wiki/%E5%B0%86-QQ-%E5%8F%B7%E4%B8%8E-osu!-%E8%B4%A6%E5%8F%B7%E7%BB%91%E5%AE%9A");
            return(result.Value);
        }
Ejemplo n.º 3
0
        public static async Task <UserInfo> EnsureGetUserInfo(this OsuApiClient osuApi, string name, Bleatingsheep.Osu.Mode mode)
        {
            var(success, result) = await osuApi.GetUserInfoAsync(name, mode);

            ExecutingException.Ensure(success, "网络错误。");
            ExecutingException.Ensure(result != null, "无此用户!");
            return(result);
        }
Ejemplo n.º 4
0
        public async Task ProcessAsync(Message message, Sisters.WudiLib.HttpApiClient api)
        {
            long id = message.UserId;

            var(networkSuccess, osuResult) = await DataProvider.GetBindingIdAsync(id);

            ExecutingException.Ensure(networkSuccess, "无法查询绑定账号。");
            ExecutingException.Ensure(osuResult != null, "未绑定 osu! 游戏账号。");

            var osuId  = osuResult.Value;
            var recent = (await OsuApi.GetRecentlyAsync(osuId, OsuMixedApi.Mode.Standard, 1)).FirstOrDefault();

            if (recent == null)
            {
                await api.SendMessageAsync(message.Endpoint, "没打图!");

                return;
            }

            var reply = new List <string> {
                "/np 给 bleatingsheep,查询更方便!"
            };

            try
            {
                var ppBeatmap = await s_spider.GetBeatmapPlusAsync(recent.BeatmapId);

                if (ppBeatmap == null)
                {
                    reply.Add("很抱歉,无法查询 Loved 图。也有可能是 PP+ 没有这张图的数据。");
                    return;
                }
                reply.Add($"https://syrin.me/pp+/b/{ppBeatmap.Id}/");
                reply.Add("Stars: " + ppBeatmap.Stars);
                reply.Add("Aim (Jump): " + ppBeatmap.AimJump);
                reply.Add("Aim (Flow): " + ppBeatmap.AimFlow);
                reply.Add("Precision: " + ppBeatmap.Precision);
                reply.Add("Speed: " + ppBeatmap.Speed);
                reply.Add("Stamina: " + ppBeatmap.Stamina);
                reply.Add("Accuracy: " + ppBeatmap.Accuracy);
                reply.Add("数据来自 PP+。");
            }
            catch (ExceptionPlus)
            {
                reply.Add("访问 PP+ 网站失败。");
            }
            finally
            {
                await api.SendMessageAsync(message.Endpoint, string.Join("\r\n", reply));
            }
        }
Ejemplo n.º 5
0
        public async Task ProcessAsync(MessageContext context, HttpApiClient api)
        {
            //await api.SendMessageAsync(context.Endpoint, $"[DEBUG] 比较:{_other};模式:{_mode}");

            var id = await DataProvider.EnsureGetBindingIdAsync(context.UserId).ConfigureAwait(false);

            //var browser = GetBrowser();

            byte[] data = null;
            var    mode = Bleatingsheep.Osu.Mode.Standard;

            try
            {
                if (!string.IsNullOrEmpty(_mode))
                {
                    mode = Bleatingsheep.Osu.ModeExtensions.Parse(_mode);
                }
            }
            catch
            {
                await api.SendMessageAsync(context.Endpoint, "模式识别失败,fallback 到 Standard。").ConfigureAwait(false);
            }

            var url = $"http://hydrantweb/pptth/mini/{id}?height=350&mode={(int)mode}";

            if (!string.IsNullOrEmpty(_other))
            {
                var(_, user) = await OsuApi.GetUserInfoAsync(_other, mode);

                if (user == null)
                {
                    ExecutingException.Ensure(false, "对比玩家错误");
                }
                url += $"&compared={user.Id}";
            }
            using (var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false))
            {
                await page.SetViewportAsync(new ViewPortOptions
                {
                    DeviceScaleFactor = 1.15,
                    Width             = 640,
                    Height            = 350,
                }).ConfigureAwait(false);

                await page.GoToAsync(url).ConfigureAwait(false);

                await Task.Delay(0).ConfigureAwait(false);

                data = await page.ScreenshotDataAsync(new ScreenshotOptions
                {
                    FullPage = true,
                    //Type = ScreenshotType.Jpeg,
                    //Quality = 100,
                }).ConfigureAwait(false);
            }

            var stopwatch    = Stopwatch.StartNew();
            var sendResponse = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false);

            var elapsedTime = stopwatch.ElapsedMilliseconds;
            var failed      = sendResponse is null;

            if (failed)
            {
                await api.SendMessageAsync(context.Endpoint, "图片发送失败(确定)").ConfigureAwait(false);
            }
            (failed ? FailedElapsed : SuccessfulElapsed).Add(elapsedTime);
        }
Ejemplo n.º 6
0
        public async Task ProcessAsync(Sisters.WudiLib.Posts.Message message, HttpApiClient api)
        {
            var osuApi = OsuApi;

            // 获取操作者信息。
            var operatorBind = await Database.GetBindingIdAsync(_operator);

            if (!operatorBind.Success)
            {
                await api.SendMessageAsync(message.Endpoint, "查询数据库失败,无法记录日志。");

                return;
            }
            string operatorName = (await osuApi.GetUserInfoAsync(operatorBind.Result.Value, OsuMixedApi.Mode.Standard)).Item2?.Name ?? "未知";

            // 获取此用户名的相关信息。
            var(networkSuccess, newUser) = await osuApi.GetUserInfoAsync(_username, OsuMixedApi.Mode.Standard);

            if (!networkSuccess)
            {
                await api.SendMessageAsync(message.Endpoint, "网络访问失败。");

                return;
            }
            ExecutingException.Cannot(newUser == null, "没有这个用户。");

            // 绑定。
            var oldBind = (await Database.ResetBindingAsync(
                               qq: _qq,
                               osuId: newUser.Id,
                               osuName: newUser.Name,
                               source: "由管理员修改",
                               operatorId: _operator,
                               operatorName: operatorName,
                               reason: _reason
                               )).EnsureSuccess("绑定失败,数据库访问出错。");

            ExecutingException.Cannot(oldBind.Result == newUser.Id, "未更改绑定,因为已经绑定了该账号。");

            SendingMessage message1 = new SendingMessage("将") + SendingMessage.At(_qq) + new SendingMessage($"绑定为{newUser.Name}。");

            if (oldBind.Result == null)
            {
                await api.SendMessageAsync(message.Endpoint, message1);

                return;
            }

            // 获取旧的用户信息。
            OsuMixedApi.UserInfo oldUser;
            (networkSuccess, oldUser) = await osuApi.GetUserInfoAsync(oldBind.Result.Value, OsuMixedApi.Mode.Standard);

            if (!networkSuccess)
            {
                message1 += new SendingMessage($"因网络问题,无法获取旧的用户名(id: {oldBind.Result.Value})。");
            }
            else if (oldUser == null)
            {
                message1 += new SendingMessage($"以前绑定的用户已经被 Ban(id: {oldBind.Result.Value})。");
            }
            else
            {
                message1 += new SendingMessage($"取代{oldUser.Name}({oldUser.Id})。");
            }
            await api.SendMessageAsync(message.Endpoint, message1);
        }