Example #1
0
        protected void InternalOnMessage(UserInfo user, string message)
        {
            if (IsDisposed) return;
            Logger.Trace("Message '{0}' -> Heyman:{1}",user,message);
            lock (_sync)
            {
                HeymanTalk talk;
                // try find talk with this user
                if (_talks.TryGetValue(user.Id, out talk))
                {
                    //already talks with this user -> send message ot talk
                    talk.OnMessage(message);
                }
                else
                {
                    // new talk -> try find command by message
                    var cmd = FindCommand(message);
                    if (cmd == null)
                    {
                        Logger.Warn("'{0}' -> Heyman: Unkwnon command '{1}'", user, message);
                        PrintHelp(user.Id, message,_commands);
                        return;
                    }

                    talk = new HeymanTalk(user, this);

                    _talks.Add(user.Id, talk);

                    try
                    {
                        Logger.Info("Begin talk '{0}' with user {1}", cmd.Title, user);
                        //run on current thread
                        talk.Run(cmd,message);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Error to begin talk {0} with", cmd.Title, user);
                        Say(talk.User.Id, ex.Message);
                    }

                    //wait for exit on new thread
                    Task.Factory.StartNew(()=>RemoveOnExit(talk), TaskCreationOptions.LongRunning);
                }
            }
        }
Example #2
0
 public HeymanTalk(UserInfo user, IHeymanMouth mouth)
 {
     _user = user;
     _mouth = mouth;
 }