Example #1
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var                  routeMsg    = scope.RouteMessage;
            BllUserRole          bllUserRole = new BllUserRole();
            List <TableUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId));

            if (userInfo.Count == 0)
            {
                return(routeMsg.ToSource(DefaultReply.IdNotBound, true));
            }

            var id = userInfo[0].UserId;

            var client      = new OldSiteApiClient();
            var beatmapSets = client.GetBeatmapSetsByCreator(new UserId(id))
                              .Where(k => k.Beatmaps.FirstOrDefault()?.LastUpdate.AddDays(28) < DateTimeOffset.Now)
                              .ToArray();

            if (beatmapSets.Length == 0)
            {
                return(routeMsg.ToSource("你没有Graveyard Beatmaps!", true));
            }

            var beatmapSet = beatmapSets[StaticRandom.Next(beatmapSets.Length)];
            var cqMusic    = new CustomMusic(
                $"https://osu.ppy.sh/s/{beatmapSet.Id}",
                $"https://b.ppy.sh/preview/{beatmapSet.Id}.mp3",
                beatmapSet.Title,
                $"{beatmapSet.Artist}\r\n({beatmapSet.FavouriteCount} fav)",
                $"https://b.ppy.sh/thumb/{beatmapSet.Id}l.jpg");

            return(routeMsg
                   .ToSource(cqMusic.ToString())
                   .ForceToSend());
        }
Example #2
0
        /// <summary>
        /// 发送音乐消息
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="music"></param>
        /// <param name="accessToen"></param>
        /// <returns></returns>
        public static ErrorEntity SendMusic(string openid, CustomMusic music, string accessToen)
        {
            var json = new
            {
                touser  = openid,
                msgtype = "music",
                music   = music
            };

            return(Send(json, accessToen));
        }
        private static void LoadCustomMusic()
        {
            var fileInfo = new FileInfo(MusicPath);

            fileInfo.Directory.Create(); // If the directory already exists, this method does nothing.

            foreach (var filename in Directory.GetFiles(MusicPath, "*", SearchOption.AllDirectories))
            {
                if (CustomMusic.ContainsKey(filename) || failedPaths.Contains(filename) || !ValidAudioFile(filename))
                {
                    continue;
                }

                CustomMusic.Add(filename, null);
            }
        }
Example #4
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            BllUserRole        bllUserRole = new BllUserRole();
            List <TblUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId));

            if (userInfo.Count == 0)
            {
                return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true));
            }

            var id = userInfo[0].UserId.ToString();

            List <Beatmapsets> totalList = new List <Beatmapsets>();

            Beatmapsets[] tmpArray;
            int           page  = 0;
            const int     count = 10;

            do
            {
                string json = WebRequestUtil.GetResponseString(
                    WebRequestUtil.CreateGetHttpResponse(
                        "https://osu.ppy.sh/users/" + id + "/beatmapsets/graveyard?offset=" + page + "&limit=" + count));
                Logger.Debug("GET JSON");

                tmpArray = JsonConvert.DeserializeObject <Beatmapsets[]>(json);
                totalList.AddRange(tmpArray);
                page += count;

                if (tmpArray.Length != count)
                {
                    break;
                }
            } while (tmpArray.Length != 0);

            if (totalList.Count == 0)
            {
                return(new CommonMessageResponse("惊了,你竟然会没坑!", messageObj, true));
            }

            Random      rnd     = new Random();
            Beatmapsets beatmap = totalList[rnd.Next(totalList.Count)];
            var         cqMusic = new CustomMusic("https://osu.ppy.sh/s/" + beatmap.Id, $"https://b.ppy.sh/preview/{beatmap.Id}.mp3", beatmap.Title,
                                                  $"{beatmap.Artist}\r\n({beatmap.FavouriteCount} fav)", $"https://b.ppy.sh/thumb/{beatmap.Id}l.jpg");

            return(new CommonMessageResponse(cqMusic.ToString(), messageObj));
        }