Пример #1
0
        public static LocalUser GetUser(ResponseChannel rc, VBotService.RemoteUser remoteUser)
        {
            LocalUser luser = VBotDB.Instance.LocalUsers.FirstOrDefault(
                u => u.Screenname == rc.ToName && u.Service == rc.Connection.Alias);

            if (luser == null)
            {

                luser = new LocalUser
                {
                    Screenname = rc.ToName,
                    Service = rc.Connection.Alias,
                    BoardUserID = remoteUser.UserID,
                    LastUpdate = DateTime.Now
                };

                VBotDB.Instance.LocalUsers.InsertOnSubmit(luser);
                VBotDB.Instance.SubmitChanges();

            }
            else
            {
                luser.LastUpdate = DateTime.Now;
                VBotDB.Instance.SubmitChanges();
            }

            if (luser != null)
            {
                luser.ResponseChannel = rc;
            }

            return luser;
        }
Пример #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);
            }
        }