当前位置: 首页>>代码示例>>C#>>正文


C# Reddit.ComposePrivateMessage方法代码示例

本文整理汇总了C#中RedditSharp.Reddit.ComposePrivateMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Reddit.ComposePrivateMessage方法的具体用法?C# Reddit.ComposePrivateMessage怎么用?C# Reddit.ComposePrivateMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedditSharp.Reddit的用法示例。


在下文中一共展示了Reddit.ComposePrivateMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Launch

 public void Launch()
 {
     List<String> title = new List<string>();
     List<String> urls = new List<string>();
     string body = "";
     var reddit = new Reddit();
     var user = reddit.LogIn("bot_wallpaper", "qwerty");
     var subreddit = reddit.GetSubreddit("/r/" + _wallpaperType);
     foreach (var post in subreddit.GetTop(FromTime.Week).Take(25))
     {
         if (_resolution == "null")
         {
             title.Add(post.Title);
             urls.Add(post.Url.ToString());
         }
         else if (post.Title.Contains(_resolution))
         {
             title.Add(post.Title);
             urls.Add(post.Url.ToString());
         }
     }
     for (int i = 0; i < title.Count; i++)
     {
         body += "[" + title[i] + "](" + urls[i] + ") \n\n";
     }
     reddit.ComposePrivateMessage("Wallpapers!", "#Here is the top wallpapers of this week in **/r/" + _wallpaperType + "** \n\n" + body + "\n\n I am a bot!", _username, "", "");
     Console.WriteLine("UserProcessor: Message sent to " + _username);
 }
开发者ID:erickchin,项目名称:RedditWallpaperBot,代码行数:28,代码来源:UserProcessor.cs

示例2: GetOrCreateDailyPosts

        private static IEnumerable<Post> GetOrCreateDailyPosts(Reddit reddit, Subreddit subreddit, AuthenticatedUser user, int year, int month)
        {
            var firstDateOfMonth = new DateTime(year, month, 1);
            var monthName = firstDateOfMonth.ToString("MMMM");

            var createdPost = false;
            var dailyPostDate = firstDateOfMonth;
            var userPosts = user.Posts.ToList();

            while (dailyPostDate.Month == month)
            {
                var dailyPostTitle = string.Format(DailyPostTitleFormat, year, monthName, dailyPostDate.Day);
                var dailyPosts = userPosts.Where(p => p.Title == dailyPostTitle).OrderByDescending(p => p.Created);

                if (dailyPosts.Any())
                {
                    if (dailyPosts.Count() > 1)
                        reddit.ComposePrivateMessage("Multiple daily posts found", "Multiple posts found for " + dailyPostDate.ToShortDateString() + " post." + Environment.NewLine + string.Join(Environment.NewLine, dailyPosts.Select(p => p.Shortlink)), SubredditName);

                    yield return dailyPosts.First();
                }
                else
                {
                    // Create the post for the day.
                    var post = subreddit.SubmitTextPost(dailyPostTitle, string.Format(DailyPostDescription, dailyPostDate.ToLongDateString()));

                    CreateDailyEvents(post, dailyPostDate.Year, dailyPostDate.Month, dailyPostDate.Day);

                    yield return post;

                    createdPost = true;
                    Thread.Sleep(10000); // Wait 10 seconds before creating another post
                }

                dailyPostDate = dailyPostDate.AddDays(1);
            }

            if (createdPost)
                reddit.ComposePrivateMessage("New month worth of posts created", "Daily posts were created for " + monthName + ".", SubredditName);
        }
开发者ID:bhasden,项目名称:rJacksonvilleModBot,代码行数:40,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            var password = string.Empty;
            var username = string.Empty;

            if (args != null && args.Count() == 2)
            {
                password = args[1];
                username = args[0];
            }
            else
            {
                password = CloudConfigurationManager.GetSetting("pass");
                username = CloudConfigurationManager.GetSetting("user");
            }

            if (string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(username))
            {
                Console.WriteLine("Invalid or missing username and password.");
                Environment.Exit(1);
            }

            var reddit = new Reddit();
            var user = reddit.LogIn(username, password);
            var subreddit = reddit.GetSubreddit(SubredditName);

            AppDomain.CurrentDomain.UnhandledException += (o, e) =>
            {
                reddit.ComposePrivateMessage("Exception", e.ExceptionObject.ToString(), SubredditName);
                Console.WriteLine(e.ExceptionObject);
                Environment.Exit(3);
            };

            subreddit.Subscribe();

            if (!user.ModeratorSubreddits.Any(s => s.ToString().Equals(SubredditName, StringComparison.OrdinalIgnoreCase)))
            {
                reddit.ComposePrivateMessage("Bot user not a moderator", "The user '" + username + "' is not a moderator for the " + SubredditName + " subreddit.", SubredditName);
                Console.WriteLine("The user '" + username + "' is not a moderator for the " + SubredditName + " subreddit.");
                Environment.Exit(2);
            }

            // Reply to any private messages that have been sent to the mod bot.
            foreach (var message in user.PrivateMessages.Where(m => m.Unread))
            {
                message.Reply("You have messaged the " + SubredditName + " moderator bot. These private messages are not actively monitored.");
                message.SetAsRead();
            }

            // Get or create the post for this month
            var today = DateTime.Now;
            var dailyPosts = GetOrCreateDailyPosts(reddit, subreddit, user, today.Year, today.Month).ToList();
            var todaysPosts = dailyPosts.Where(p => p.AuthorName == user.Name && p.Title == string.Format(DailyPostTitleFormat, today.Year, today.ToString("MMMM"), today.Day)).ToList();

            if (dailyPosts.Any())
            {
                var settings = subreddit.Settings;
                var sidebar = settings.Sidebar;

                if (!string.IsNullOrEmpty(sidebar) && sidebar.Contains(SidebarSectionMarkdown))
                {
                    var startIndex = sidebar.IndexOf(SidebarSectionMarkdown, StringComparison.Ordinal) + SidebarSectionMarkdown.Length;
                    var endIndex = sidebar.IndexOf("#**", startIndex, StringComparison.Ordinal); // Find the beginning of the next section

                    if (endIndex < 0)
                        endIndex = sidebar.Length - 1; // There's no next section, so just replace the rest of the content

                    var newSidebarContent = "* [" + today.DayOfWeek + "](" + todaysPosts.First().Shortlink + ")";
                    newSidebarContent += Environment.NewLine + "* [" + today.ToString("MMMM") + "](" + todaysPosts.First().Shortlink + ")";
                    newSidebarContent += Environment.NewLine + "* [" + today.Day + "](" + todaysPosts.First().Shortlink + ")";
                    newSidebarContent += Environment.NewLine + Environment.NewLine + ">" + Environment.NewLine;
                    newSidebarContent += Environment.NewLine + "* [There are " + todaysPosts.First().ListComments(2000).Count() + " events today. Check it out or add your own.](" + todaysPosts.First().Shortlink + ")";
                    newSidebarContent += Environment.NewLine + Environment.NewLine + "&nbsp;" + Environment.NewLine;

                    newSidebarContent += "######" + today.ToString("MMMM");
                    newSidebarContent += Environment.NewLine + "| Su | Mo | Tu | We | Th | Fr | Sa |" + Environment.NewLine + "|-|-|-|-|-|-|-|";

                    for (var i = 1; i <= DateTime.DaysInMonth(today.Year, today.Month); i++)
                    {
                        var date = new DateTime(today.Year, today.Month, i);

                        if (i == 1)
                            newSidebarContent += Environment.NewLine + string.Join("|", Enumerable.Range(0, (int)date.DayOfWeek + 1).Select(d => string.Empty));

                        var dailyPost = dailyPosts.Where(p => p.AuthorName == user.Name && p.Title == string.Format(DailyPostTitleFormat, today.Year, today.ToString("MMMM"), i)).ToList();

                        if (dailyPost.Any())
                            newSidebarContent += "| [" + i + "](" + dailyPost.First().Shortlink + ")";
                        else
                            newSidebarContent += "| " + i;

                        if (date.DayOfWeek == DayOfWeek.Saturday)
                            newSidebarContent += "|" + Environment.NewLine;
                    }

                    newSidebarContent += Environment.NewLine + Environment.NewLine + "&nbsp;" + Environment.NewLine;
                    newSidebarContent += Environment.NewLine + SidebarSectionAdditional;

                    settings.Sidebar = sidebar.Remove(startIndex, endIndex - startIndex).Insert(startIndex, Environment.NewLine + Environment.NewLine + newSidebarContent + Environment.NewLine + Environment.NewLine);
                    settings.UpdateSettings();
//.........这里部分代码省略.........
开发者ID:bhasden,项目名称:rJacksonvilleModBot,代码行数:101,代码来源:Program.cs


注:本文中的RedditSharp.Reddit.ComposePrivateMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。