Ejemplo n.º 1
0
        public async void SetChineseNameCommand(AcceptedMessage message, string[] args)
        {
            var vtuber = await GetVtuberAsync(args[2]);

            if (vtuber == null)
            {
                await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到Vtuber.");

                return;
            }
            vtuber.ChineseName = args[3];
            await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                    new UpdateOptions()
            {
                IsUpsert = true
            });

            await SendingService.SendGroupMessageAsync(message.FromGroup, "设置完成.");

            try
            {
                var uploader = (await BilibiliApi.SearchBilibiliUsersAsync(vtuber.ChineseName))
                               .OrderByDescending(v => v.Follower).FirstOrDefault(v => v.IsUploader);
                if (uploader != null && vtuber.BilibiliUserId == 0)
                {
                    vtuber.BilibiliUserId = uploader.Id;
                    await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                            new UpdateOptions()
                    {
                        IsUpsert = true
                    });

                    await SendingService.SendGroupMessageAsync(message.FromGroup, $"已根据中文名自动查找B站搬运组:" +
                                                               $"\r\n用户名: {uploader.Username}" +
                                                               $"\r\n主页: https://space.bilibili.com/{uploader.Id}" +
                                                               $"\r\n粉丝数: {uploader.Follower}");

                    await SendingService.SendGroupMessageAsync(message.FromGroup, "可使用!Vtuber 设置B站 <Vtuber名字> <B站空间ID或搬运组名称> 来修改");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("Search bilibili uploader error.", ex: ex);
            }
        }
Ejemplo n.º 2
0
        public async void UpdateBilibiliProfileCommand(AcceptedMessage message, string[] args)
        {
            var vtuber = await GetVtuberAsync(args[2]);

            if (vtuber == null)
            {
                await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到相关Vtuber");

                return;
            }
            if (long.TryParse(args[3], out var uid))
            {
                var userInfo = await BilibiliApi.GetBilibiliUserAsync(uid);

                if (userInfo == null)
                {
                    await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到UID: " + uid);

                    return;
                }
                vtuber.BilibiliUserId = uid;
                await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                        new UpdateOptions()
                {
                    IsUpsert = true
                });

                await SendingService.SendGroupMessageAsync(message.FromGroup, $"保存完成:" +
                                                           $"\r\n用户名: {userInfo.Username}" +
                                                           $"\r\n主页: https://space.bilibili.com/{uid}" +
                                                           $"\r\n粉丝数: {userInfo.Follower}");

                return;
            }
            try
            {
                var uploader = (await BilibiliApi.SearchBilibiliUsersAsync(args[3]))
                               .OrderByDescending(v => v.Follower).FirstOrDefault(v => v.IsUploader);
                if (uploader != null)
                {
                    vtuber.BilibiliUserId = uploader.Id;
                    await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                            new UpdateOptions()
                    {
                        IsUpsert = true
                    });

                    await SendingService.SendGroupMessageAsync(message.FromGroup, $"保存完成:" +
                                                               $"\r\n用户名: {uploader.Username}" +
                                                               $"\r\n主页: https://space.bilibili.com/{uploader.Id}" +
                                                               $"\r\n粉丝数: {uploader.Follower}");

                    return;
                }
                await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到 " + args[3]);
            }
            catch (Exception ex)
            {
                LogHelper.Error("Search bilibili uploader error.", ex: ex);
            }
        }