当前位置: 首页>>代码示例>>C#>>正文


C# TimeInterval.Parse方法代码示例

本文整理汇总了C#中TimeInterval.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# TimeInterval.Parse方法的具体用法?C# TimeInterval.Parse怎么用?C# TimeInterval.Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeInterval的用法示例。


在下文中一共展示了TimeInterval.Parse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Alog

        public static async Task Alog(CommandContext bc)
        {
            int timeSpan = 0;
            string timeSpanName = string.Empty;
            Match timeInterval = Regex.Match(bc.Message, @"@(.+?)( |$)");
            if (timeInterval.Success)
            {
                var timePeriod = new TimeInterval();
                if (timePeriod.Parse(timeInterval.Groups[1].Value))
                {
                    timeSpan = (int) timePeriod.Time.TotalSeconds;
                    timeSpanName = timePeriod.Name;
                }
                else if (timeInterval.Groups[1].Value == "all")
                {
                    timeSpan = int.MaxValue;
                }
                bc.Message = Regex.Replace(bc.Message, @"@(.+?)( |$)", string.Empty, RegexOptions.IgnoreCase);
                bc.Message = bc.Message.Trim();
            }

            var rsn = await bc.GetPlayerName(bc.From.Nickname);
            if (bc.MessageTokens.GetLength(0) > 1)
            {
                rsn = await bc.GetPlayerName(bc.MessageTokens.Join(1));
            }

            List<RssItem> list = null;
            try
            {
                var reader = new RssManager("http://services.runescape.com/m=adventurers-log/rssfeed?searchName=" + rsn);
                reader.GetFeed();
                list = reader.RssItems;
            }
            catch
            {
            }

            if (list == null)
            {
                await bc.SendReply(@"No achievements found for \c7{0}\c{1}. The profile may be private, the player may be f2p, or the rsn incorrect.", rsn, string.IsNullOrEmpty(timeSpanName) ? string.Empty : @" in " + timeSpanName);
                return;
            }

            var p = await Player.FromHiscores(rsn);
            list.Sort((i1, i2) => i2.Date.CompareTo(i1.Date));
            if (timeSpan > 0)
            {
                list.RemoveAll(i => (DateTime.UtcNow - i.Date).TotalSeconds > timeSpan);
            }
            else if (list.Count > 15)
            {
                list.RemoveAll(i => i.Date < list[14].Date);
                timeSpanName = "recent";
            }
            if (list.Count == 0 || !p.Ranked)
            {
                await bc.SendReply(@"No achievements found for \c7{0}\c{1}. The profile may be private, the player may be f2p, or the rsn incorrect.", rsn, string.IsNullOrEmpty(timeSpanName) ? string.Empty : @" in " + timeSpanName);
                return;
            }

            const string questRegex = @"Quest complete: (.+)";
            const string killRegex = @"killed the player (.+?)\.|I killed\s*(?:an?|the)?\s*(.+?)\.?$";
            const string levelRegex = @"Level?led up (\w+)\.?|Levelled all skills over (\d+)";
            const string itemRegex = @"Item found: (?:an?|some) (.+)";
            const string expRegex = @"(\d+)XP in (\w+)";
            const string duRegex = @"Dungeon level (\d+) reached.";

            var alogItems = new Dictionary<string, Dictionary<string, AlogItem>> {
                { "I reached", new Dictionary<string, AlogItem>() },
                { "I gained", new Dictionary<string, AlogItem>() },
                { "I killed", new Dictionary<string, AlogItem>() },
                { "I found", new Dictionary<string, AlogItem>() },
                { "I completed", new Dictionary<string, AlogItem>() },
                { "Others", new Dictionary<string, AlogItem>() }
            };
            foreach (RssItem item in list)
            {
                Match M = Regex.Match(item.Title, questRegex);
                if (M.Success)
                {
                    var quest = new AlogItem(item, M, "I completed");
                    alogItems["I completed"].Add(alogItems["I completed"].Count.ToStringI(), quest);
                    continue;
                }
                M = Regex.Match(item.Title, killRegex);
                if (M.Success)
                {
                    var kill = new AlogItem(item, M, "I killed");
                    string npc = Regex.Replace(kill.Info[0].Replace("monsters", "monster"), @"\W", " ");
                    if (alogItems["I killed"].ContainsKey(npc))
                    {
                        alogItems["I killed"][npc].Amount += kill.Amount;
                    }
                    else
                    {
                        kill.Info[0] = npc;
                        alogItems["I killed"].Add(npc, kill);
                    }
                    continue;
//.........这里部分代码省略.........
开发者ID:alfaproject,项目名称:Supay-Bot,代码行数:101,代码来源:CmdAlog.cs


注:本文中的TimeInterval.Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。