예제 #1
0
        CorralEvent PostToAction(Post post)
        {
            String       actor      = post.Poster.Name;
            CorralAction verb       = CorralAction.NoAction;
            String       target     = "no target";
            String       parameter  = "no parameter";
            String       title      = post.Title;
            String       msg        = post.Content.Trim();
            Int32        id         = post.PostId;
            Int32        postNumber = post.PostNumber;

            foreach (Bold b in post.Bolded)
            {
                String content = b.Content.Trim().ToLower();
                String shoot   = "shoot ";
                if (content.StartsWith(shoot))
                {
                    target = content.Substring(shoot.Length).Trim();
                    verb   = CorralAction.Shoot;
                    break;
                }
            }
            CorralEvent ga = new CorralEvent(actor, verb, target, parameter, post.Time, title, msg, id, postNumber);

            return(ga);
        }
예제 #2
0
 internal CorralEvent(string actor, CorralAction action, string target, string parameter, DateTimeOffset time, string title,
                      string content, Int32 id, Int32 postNumber)
 {
     Actor      = actor;
     Action     = action;
     Target     = target;
     Parameter  = parameter;
     TimeStamp  = time;
     Title      = title;
     Content    = content;
     Id         = id;
     PostNumber = postNumber;
 }
예제 #3
0
        CorralEvent PMToAction(PrivateMessage pm)
        {
            String       actor      = pm.From;
            CorralAction verb       = CorralAction.NoAction;
            String       target     = "no target";
            String       parameter  = "no parameter";
            String       title      = pm.Title;
            String       msg        = pm.Content.Trim();
            Int32        id         = pm.Id;
            Int32        postNumber = 0;
            Match        m          = Regex.Match(msg, @"(\w+)\s+(.*)", RegexOptions.Singleline);

            // action: arm, unarm, shoot, trade suit, steal suit, steal gun
            if (m.Success)
            {
                String action = m.Groups[1].Value.ToLower();
                String rem    = m.Groups[2].Value.Trim();
                switch (action)
                {
                case "arm":
                {
                    verb      = CorralAction.Arm;
                    parameter = TrimLead(rem, "with");
                }
                break;

                case "unarm":
                {
                    verb = CorralAction.UnArm;
                }
                break;

                case "shoot":
                {
                    target = rem;
                    verb   = CorralAction.Shoot;
                    Console.WriteLine("shooting '{0}'", target);
                }
                break;

                case "trade":
                {
                    rem    = TrimLead(rem, "suit");
                    target = TrimLead(rem, "with");
                    verb   = CorralAction.Trade;
                }
                break;

                case "steal":
                {
                    parameter = ParseFirstWord(ref rem);
                    target    = TrimLead(rem, "from");
                    verb      = CorralAction.Steal;
                }
                break;

                case "toss":
                {
                    parameter = TrimLead(rem, "gun");
                    verb      = CorralAction.Toss;
                }
                break;

                default:
                {
                    Console.WriteLine("unknown action '{0}'", action);
                }
                break;
                }
            }
            CorralEvent ga = new CorralEvent(actor, verb, target, parameter, pm.TimeStamp.Value, title, msg, id, postNumber);

            return(ga);
        }