Exemplo n.º 1
0
 public void Em(CommandParser parser)
 {
     if (parser.Parameters.Length > 0)
     {
         _controller.OnMessageCallback(_connection, new InstantMessage(_strUsername, parser.WorkingString));
     }
 }
Exemplo n.º 2
0
        public Result GotoPostIndex(int iChoice, LocalUser user, CommandParser parser)
        {
            Result rs = null;
            bool bShowBBCode = false;

            if (parser != null)
            {
                // TODO: need to refactor/rewrite the command parser
                foreach (string strOption in parser.Parameters)
                {
                    if (strOption.ToLower() == "b")
                    {
                        bShowBBCode = true;
                        break;
                    }
                }
            }

            UserLocation curPostLoc = UserLocation.LoadLocation(UserLocationType.POST, user);

            if (curPostLoc != null)
            {
                VBotService.UserCredentials uc = BotService.Credentialize(ResponseChannel);
                VBotService.GetPostResult r = BotService.Instance.GetPostByIndex(uc, (int)curPostLoc.LocationRemoteID, iChoice, bShowBBCode);

                if (r.Result.Code == 0)
                {
                    if (r.Post != null && r.Post.PostID > 0)
                    {
                        string strText = ResponseChannel.FetchTemplate(@"postbit",
                            new object[] {r.Post.PageText,iChoice,r.Post.DateLineText,r.Post.Username});

                        user.SaveLastPostIndex(iChoice);
                        rs = new Result(ResultCode.Success, strText);
                    }
                    else
                    {
                        rs = new Result(ResultCode.Error, @"Invalid post index.");
                    }
                }
                else
                {
                    rs = new Result(ResultCode.Error, @"Invalid request.");
                }
            }
            else
            {// no location for a thread exists in the local db

                rs = new Result(ResultCode.Error, @"Invalid thread id. Use `lt` and browse to a thread");
            }
            return rs;
        }
Exemplo n.º 3
0
        public Result DoCommand(string strCommand,LocalUser user)
        {
            Result retval = new Result();
            CommandParser parser = new CommandParser(strCommand);

            if (parser.Parse())
            {
                int iListChoice = 0;

                if (int.TryParse(parser.ApplicationName, out iListChoice) && iListChoice > 0)
                {
                    // user entered a number, let's deal with the lastlists
                    UserLastList ll = VBotDB.Instance.UserLastLists.FirstOrDefault(l => l.LocalUserID == user.LocalUserID);

                    if (ll != null)
                    {
                        switch (ll.Name)
                        {
                            case @"forum":
                                retval = GotoForumIndex(iListChoice, user);
                                break;

                            case @"thread":
                                retval = GotoThreadIndex(iListChoice, user);
                                break;

                            case @"post":
                                retval = GotoPostIndex(iListChoice, user, parser);
                                break;

                            default:
                                log.ErrorFormat("Unknown lastlist {0}", ll.Name);
                            break;
                        }
                    }
                    else
                    {
                        retval = new Result(ResultCode.Error, @"Use `lf`,`lt` or `lp` to browse forums, threads and posts.");
                    }
                }
                else
                { // assume a command was entered
                    switch (parser.ApplicationName.ToLower())
                    {
                        #region long switch statement to be refactored
                        case @"\":
                        case "/":
                            retval = GotoForumIndex(-1, user, true);
                            break;

                        case @".":
                            retval = GotoParentForum(user);
                            break;

                        case @"cp":
                            retval = GotoPostIndex(user.PostIndex,user,parser);
                            break;

                        case @"gt":
                            retval = GotoThread(user, parser.Parameters);
                            break;

                        case @"im":
                            retval = TurnOnOffAutoIMS(user, parser.Parameters);
                            break;

                        case "lf":
                            retval = ListForum(user);
                            break;

                        case @"lp":
                            retval = ListPosts(user, parser.Parameters);
                            break;

                        case "lt":
                            retval = ListThreads(user, parser.Parameters);
                            break;

                        case "mfr":
                            retval = MarkRead(user, @"forum");
                            break;

                        case "mtr":
                            retval = MarkRead(user, @"thread");
                            break;

                        case @"n":
                            retval = GotoNextPost(user, true);
                            break;

                        case @"nt":
                            retval = NewThread(user);
                            break;

                        case @"p":
                            retval = GotoNextPost(user, false);
                            break;

                        case @"r":
                            retval = ThreadReply(user,false);
                            break;

                        case @"rq":
                            retval = ThreadReply(user, true);
                            break;

                        case "sub":
                            retval = SubscribeThread(user, parser.Parameters);
                            break;

                        case "unsub":
                            retval = UnsubscribeThread(user, parser.Parameters);
                            break;

                        case @"whereami":
                            retval = WhereAmI(user);
                            break;

                        case "whoami":
                            // TODO: the string in UserConnectionName should come from somewhere else?
                            retval = WhoAmI(ResponseChannel.ToName, ResponseChannel.Connection.Alias);
                        break;

                        default:
                            retval = new Result(ResultCode.Error, @"Unknown command. Please see http://code.google.com/p/vbulletinbot/ for help.");
                        break;

                        #endregion
                    }
                }
            }

            return retval;
        }
Exemplo n.º 4
0
        public void ExecuteCommand(string strCommand, bool bUseMethodName)
        {
            CommandParser parser = new CommandParser(strCommand, this);
            parser.Parse();

            MethodInfo mi = null;

            if (bUseMethodName)
            {
                mi = this.GetType().GetMethod(parser.ApplicationName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
            }

            if (mi == null)
            {
                foreach (MethodInfo mit in this.GetType().GetMethods())
                {
                    foreach (object obj in mit.GetCustomAttributes(false))
                    {
                        MethodAliasAttribute maa = obj as MethodAliasAttribute;

                        if (maa != null)
                        {
                            if (maa.Aliases != null && maa.Aliases.Contains(parser.ApplicationName))
                            {
                                mi = mit;
                                break;
                            }
                        }
                    }

                    if (mi != null)
                    {
                        break;
                    }
                }
            }

            if (mi != null)
            {
                try
                {
                    if (mi.GetParameters().Length == 0)
                    {
                        mi.Invoke(this, null);
                    }
                    else
                    {
                        object[] oparams = new object[mi.GetParameters().Length];

                        foreach (ParameterInfo m in mi.GetParameters())
                        {
                            if (m.ParameterType == typeof(string))
                            {
                                oparams[oparams.Length - 1] = parser.WorkingString;
                            }
                            else if (m.ParameterType == typeof(CommandParser))
                                oparams[oparams.Length - 1] = parser;
                        }

                        if (oparams != null)
                            mi.Invoke(this, oparams);

                    }
                }
                catch (Exception e)
                {
                    log.Error("Commands.ExecuteCommand exception: " + e.Message);
                }
            }
            else
            {
                log.Info(@"Unknown command");
            }
        }
Exemplo n.º 5
0
        public void WhoAmI(CommandParser parser)
        {
            try
            {
                UserCredentials uc = new UserCredentials();

                uc.Username = parser.Parameters[0];
                uc.ServiceName = parser.Parameters[1];

                RequestResult result = BotService.Instance.WhoAmI(uc);

                if (result.Code == 0 && result.RemoteUser.UserID > 0)
                {
                    log.InfoFormat("UserID: {0}", result.RemoteUser.UserID);
                    log.InfoFormat("UserName: {0}", result.RemoteUser.Username);
                }
                else if (result.Code == 0)
                {
                    log.Info("Unknown User");
                }
                else
                {
                    log.InfoFormat("Web Service Error: {0}", result.Text);
                }
            }
            catch (Exception ex)
            {
                log.Error("Could not execute WhoAMI()", ex);
            }
        }
Exemplo n.º 6
0
        public void Test(CommandParser parser)
        {
            Connection c = new GTalkConnection("testuser", "testpass");
            ResponseChannel rc = new ResponseChannel("aimname", c);

            Dictionary<string, object> d = new Dictionary<string, object>()
                {
                    {"PageText","this is the pagettext"},
                    {"Index",8},
                    {"DateLineText","Today at 5pm"},
                    {"Username","Manchy"},
                };

            string str = rc.FetchTemplate(@"postbit", new object[] { "text",3,"Yesterday @ 3pm","Frank Power"} );
            log.Debug(str);

            //VBotService.PostNotificationsResult result = BotService.Instance.GetPostNotifications(true);

            //UserCredentials uc = new UserCredentials();
            //uc.ServiceName = @"gtalk";
            //uc.Username = @"*****@*****.**";

            //VBotService.PostReplyResult res = BotService.Instance.PostNewThread(uc, 2, @"title", "page text");//

            //UserCredentials uc1 = new UserCredentials();
            //uc1.ServiceName = @"aim";
            //uc1.Username = @"zethon";

            //VBotService.RequestResult res = BotService.Instance.WhoAmI(uc);
        }
Exemplo n.º 7
0
 public void SetUser(CommandParser parser)
 {
     if (parser.Parameters.Length > 0)
     {
         _strUsername = parser.Parameters[0];
        _connection = new AIMConnection(null, null);
     }
 }
Exemplo n.º 8
0
 public void ResetDatabase(CommandParser parser)
 {
     VBotDB.Instance.Connection.Close();
     VBotDB.Instance.DeleteDatabase();
     VBotDB.Instance.CreateDatabase();
     log.Info("Database reset");
 }