예제 #1
0
        public Result ListThreads(LocalUser user, string[] options)
        {
            lock (this)
            {
                ResultCode rc = ResultCode.Unknown;

                string strResponse = string.Empty;
                UserLocation loc = UserLocation.LoadLocation(UserLocationType.THREAD, user);

                if (loc == null)
                {
                    Result ret = new Result(ResultCode.Error, @"No active forum. Use `lf` to browse to a forum.");
                    return ret;
                }

                if (loc != null)
                {
                    int iPageNumber = 0;
                    int iPerPage = 0;

                    if (options.Length < 1 || !int.TryParse(options[0], out iPageNumber))
                    {
                        iPageNumber = 1;
                    }

                    if (options.Length < 2 || !int.TryParse(options[1], out iPerPage))
                    {
                        iPerPage = 5;
                    }

                    if (iPerPage > 30)
                    {
                        iPerPage = 30;
                    }

                    VBotService.UserCredentials uc = BotService.Credentialize(ResponseChannel);
                    VBotService.ThreadListResult r = BotService.Instance.ListThreads(uc, (int)loc.LocationRemoteID, iPageNumber, iPerPage);

                    if (r.Result.Code != 0)
                    {
                        log.ErrorFormat("Could not list threads: {0}", r.Result.Text);
                        return new Result(ResultCode.Error, ResponseChannel.FetchTemplate(r.Result.Text));
                    }

                    bool bShowIDs = false;
                    foreach (string strOption in options)
                    {
                        if (strOption.ToLower() == "ids")
                        {
                            bShowIDs = true;
                            break;
                        }
                    }

                    bool bForumsExist = false;
                    string strIsNew = string.Empty;
                    string strIsSubscribed = string.Empty;
                    int iTotalPages = 0;

                    if (r.ThreadList != null && r.ThreadList.Count() > 0)
                    {
                        iTotalPages = (int)Math.Ceiling((double)r.ThreadCount / (double)iPerPage);
                        iTotalPages += 1;

                        int iCount = 1;
                        foreach (VBotService.Thread thread in r.ThreadList)
                        {
                            string strID = string.Empty;
                            if (bShowIDs)
                            {
                                strID = " [" + thread.ThreadID.ToString() + "]";
                            }

                            strIsNew = string.Empty;
                            if (thread.IsNew)
                            {
                                strIsNew = "*";
                            }

                            strIsSubscribed = thread.IsSubscribed ? "#" : string.Empty;

                            bForumsExist = true;

                            strResponse += ResponseChannel.FetchTemplate("thread_list_inline",
                                new object[] {
                                                iCount,
                                                strIsSubscribed,
                                                strIsNew,
                                                thread.ThreadTitle,
                                                strID,
                                                thread.ReplyCount + 1,
                                                thread.DateLineText,
                                                thread.LastPoster
                                });

                            iCount++;
                        }
                    }

                    if (!bForumsExist)
                    {
                        strResponse = "There are no threads in this forum.";
                        rc = ResultCode.Error;
                    }
                    else
                    {
                        loc.PageNumber = iPageNumber;
                        loc.PerPage = iPerPage;
                        loc.ParseIDList(r.ThreadList);
                        loc.SaveLocation();

                        strResponse = ResponseChannel.FetchTemplate("thread_list",
                            new object[] { loc.Title, iPageNumber, iTotalPages, iPerPage, strResponse });

                        rc = ResultCode.Success;
                    }
                }
                else
                {
                    strResponse = "No forum selected. (Try typing `lf` and selecting a forum.)";
                    rc = ResultCode.Error;
                }

                user.SaveLastList(@"thread");
                return new Result(rc, strResponse);
            }
        }
예제 #2
0
        public Result ListForum(LocalUser user, VBotService.Forum[] forums)
        {
            lock (this)
            {
                Result resval = null;
                UserLocation loc = UserLocation.LoadLocation(UserLocationType.FORUM, user);

                if (loc == null)
                { // this location does not exist

                    loc = UserLocation.GetDefaultLocation(UserLocationType.FORUM, user);
                    VBotService.ForumListResult res = BotService.Instance.ListForums(BotService.Credentialize(ResponseChannel), (int)loc.LocationRemoteID);

                    // TODO: error checking of the above call
                    loc.SetCurrentForum(res.CurrentForum);
                    loc.ParseIDList(res.ForumList);
                    loc.SaveLocation();
                }

                if (forums == null)
                {
                    VBotService.ForumListResult res = BotService.Instance.ListForums(BotService.Credentialize(ResponseChannel), (int)loc.LocationRemoteID);

                    if (res.Result.Code != 0)
                    {
                        log.ErrorFormat("Could not list forums: {0}", res.Result.Text);
                        return new Result(ResultCode.Error, ResponseChannel.FetchTemplate(res.Result.Text));
                    }
                    forums = res.ForumList;
                }

                string strResponse = string.Empty;

                bool bForumsExist = false;
                string strIsNew = string.Empty;

                if (forums.Count() > 0)
                {
                    int iCount = 1;
                    foreach (VBotService.Forum foruminfo in forums)
                    {
                        strIsNew = string.Empty;
                        if (foruminfo.IsNew)
                        {
                            strIsNew = "*";
                        }

                        bForumsExist = true;
                        strResponse += ResponseChannel.FetchTemplate("forum_list_inline", new object[] { iCount, strIsNew, foruminfo.Title });
                        iCount++;
                    }

                    user.SaveLastList(@"forum");
                }

                if (!bForumsExist)
                {
                    strResponse += "No subforums";
                    strResponse = ResponseChannel.FetchTemplate("forum_list", new object[] { loc.Title, strResponse });
                    resval = new Result(ResultCode.Error, strResponse);
                }
                else
                {
                    strResponse = ResponseChannel.FetchTemplate("forum_list", new object[] { loc.Title, strResponse });
                    resval = new Result(ResultCode.Success, strResponse);
                }

                return resval;
            }
        }
예제 #3
0
        public Result ListPosts(LocalUser user, string[] options, VBotService.PostListResult result)
        {
            lock (this)
            {
                ResultCode rc = ResultCode.Unknown;
                UserLocation loc = UserLocation.LoadLocation(UserLocationType.POST, user);

                if (loc == null)
                {
                    Result ret = new Result(ResultCode.Error, @"No active thread. Use `lt` to browse to a thread.");
                    return ret;
                }

                int iPageNumber = 0;
                int iPerPage = 0;

                if (options.Length < 1 || !int.TryParse(options[0], out iPageNumber))
                {
                    iPageNumber = 1;
                }

                if (options.Length < 2 || !int.TryParse(options[1], out iPerPage))
                {
                    iPerPage = 5;
                }

                if (iPerPage > 30)
                {
                    iPerPage = 30;
                }

                if (result == null)
                {
                    VBotService.UserCredentials uc = BotService.Credentialize(ResponseChannel);
                    result = BotService.Instance.ListPosts(uc, (int)loc.LocationRemoteID, iPageNumber, iPerPage);

                    if (result.Result.Code != 0)
                    {
                        log.ErrorFormat("Could not list posts: {0}", result.Result.Text);
                        return new Result(ResultCode.Error, ResponseChannel.FetchTemplate(result.Result.Text));
                    }
                }

                string strResponse = string.Empty;

                double dTotalPosts = (double)(result.Thread.ReplyCount + 1);
                int iTotalPages = (int)Math.Ceiling(dTotalPosts / (double)iPerPage);

                string strIsNew = string.Empty;
                if (result.PostList.Count() > 0)
                {
                    int iCount = ((iPageNumber - 1) * iPerPage) + 1;
                    foreach (VBotService.Post postInfo in result.PostList)
                    {
                        strIsNew = string.Empty;
                        if (postInfo.IsNew)
                        {
                            strIsNew = "*";
                        }

                        strResponse += ResponseChannel.FetchTemplate("post_list_inline", new object[] {
                                            iCount,
                                            strIsNew,
                                            postInfo.GetShortPostText(),
                                            postInfo.DateLineText,
                                            postInfo.Username
                        });

                        iCount++;
                    }

                    strResponse = ResponseChannel.FetchTemplate("post_list", new object[] {
                        loc.Title,
                        iPageNumber,
                        iTotalPages,
                        iPerPage,
                        strResponse });

                    rc = ResultCode.Success;
                }
                else
                {
                    strResponse += "Invalid page number";
                    rc = ResultCode.Error;
                }

                user.SaveLastList(@"post");
                user.SaveLastPostIndex(1);
                return new Result(rc, strResponse);
            }
        }