Ejemplo n.º 1
0
        public async Task AddRedditSubscription(CommandContext ctx, [Description("Subreddit to subscribe to (ex. /r/pics)")] string subredditUrl, [Description("Interval in minutes to check")] int intervalMin = 30)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(subredditUrl))
                {
                    await ctx.RespondAsync("You need to enter a subreddit to subscribe too :^(");

                    return;
                }

                if (intervalMin <= 0 || intervalMin > 1000000)
                {
                    await ctx.RespondAsync("The interval timer must fall between 1 and 1000000 minutes :^(");

                    return;
                }

                if (RedditSubscriptionsFile.Instance.DoesSubExistForGuild(subredditUrl, ctx.Guild.Id))
                {
                    await ctx.RespondAsync("This Subreddit subscription already exists :^(");

                    return;
                }

                RedditController.AddNewSubscription(subredditUrl, ctx.Guild.Id, ctx.Channel.Id, ctx.User.Username, intervalMin);
                await ctx.RespondAsync("Successfully added subscription :^)");
            }
            catch (Exception ex)
            {
                Program.Client.DebugLogger.Error(ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
        public async Task UpdateIntervalTimerForSubscription(CommandContext ctx, [Description("Subscription to update")] string subredditUrl, [Description("New polling interval in minutes")] int intervalMin)
        {
            if (string.IsNullOrWhiteSpace(subredditUrl))
            {
                await ctx.RespondAsync("You need to enter a subreddit to update :^(");

                return;
            }

            if (intervalMin <= 0 || intervalMin > 1000000)
            {
                await ctx.RespondAsync("The polling interval must fall between 1 and 1000000 minutes :^(");

                return;
            }

            if (RedditController.UpdateInterval(subredditUrl, ctx.Guild.Id, intervalMin))
            {
                await ctx.RespondAsync("Subscription Interval was updated :^)");

                return;
            }
            else
            {
                await ctx.RespondAsync("Subscription interval was not updated. Are you sure it exists? :^(");

                return;
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string  username = Console.ReadLine();
            string  password = Console.ReadLine();
            Account account  = new Account(username, password);

            switch (RedditController.Validate(account))
            {
            case LoginResponse.Success:
                Console.WriteLine($"Working Account: {account.ToString()}");
                break;

            case LoginResponse.Fail:
                Console.WriteLine($"Wrong Account: {account.ToString()}");
                break;

            case LoginResponse.Error:
                Console.WriteLine($"Error on account {account.ToString()}");
                break;

            default:
                Console.WriteLine($"Error on account {account.ToString()}");
                break;
            }
        }
Ejemplo n.º 4
0
        public async Task RemoveRedditSubscription(CommandContext ctx, [RemainingText, Description("Subreddit to remove")] string subredditUrl)
        {
            if (!RedditSubscriptionsFile.Instance.DoesSubExistForGuild(subredditUrl, ctx.Guild.Id))
            {
                await ctx.RespondAsync("This Subreddit subscription does not exists :^(");

                return;
            }

            if (RedditController.RemoveSubscription(subredditUrl, ctx.Guild.Id))
            {
                await ctx.RespondAsync("Removed subscription :^)");
            }
        }
Ejemplo n.º 5
0
        public async Task RunBotAsync()
        {
            try
            {
                // load settings then we want to instantiate our client
                DiscordConfiguration discordConfiguration = GetConfigFromJsonSettings();
                Client = new DiscordClient(discordConfiguration);
            }
            catch (InvalidConfigException ice)
            {
                Console.WriteLine(string.Format("{0}:\tCRITICAL ERROR: Problem with the Json Settings: {1}\n\nPress enter to close", DateTime.Now, ice.Message));
                Console.ReadLine();
                return;
            }

            // If you are on Windows 7 and using .NETFX, install
            // DSharpPlus.WebSocket.WebSocket4Net from NuGet,
            // add appropriate usings, and uncomment the following
            // line
            // this.Client.SetWebSocketClient<WebSocket4NetClient>();

            // If you are on Windows 7 and using .NET Core, install
            // DSharpPlus.WebSocket.WebSocket4NetCore from NuGet,
            // add appropriate usings, and uncomment the following
            // line
            // this.Client.SetWebSocketClient<WebSocket4NetCoreClient>();

            // If you are using Mono, install
            // DSharpPlus.WebSocket.WebSocketSharp from NuGet,
            // add appropriate usings, and uncomment the following
            // line
            // this.Client.SetWebSocketClient<WebSocketSharpClient>();

            // if using any alternate socket client implementations,
            // remember to add the following to the top of this file:
            // using DSharpPlus.Net.WebSocket;

            // next, let's hook some events, so we know
            // what's going on
            Client.Ready           += this.Client_Ready;
            Client.GuildAvailable  += this.Client_GuildAvailable;
            Client.ClientErrored   += this.Client_ClientError;
            Client.PresenceUpdated += Client_PresenceUpdated;
            Client.DebugLogger.LogMessageReceived += DebugLogger_LogMessageReceived;


            // up next, let's set up our commands
            var ccfg = new CommandsNextConfiguration
            {
                // let's use the string prefix defined in config.json
                StringPrefixes = new[] { configFile.CommandPrefix },

                // enable responding in direct messages
                EnableDms = true,

                // enable mentioning the bot as a command prefix
                EnableMentionPrefix = true
            };

            // and hook them up
            this.Commands = Client.UseCommandsNext(ccfg);

            // let's hook some command events, so we know what's
            // going on
            this.Commands.CommandExecuted += this.Commands_CommandExecuted;
            this.Commands.CommandErrored  += this.Commands_CommandErrored;

            // up next, let's register our commands
            this.Commands.RegisterCommands <VoiceCommand>();
            this.Commands.RegisterCommands <PlayAudioCommand>();
            this.Commands.RegisterCommands <WormsCommand>();
            this.Commands.RegisterCommands <VoiceRecognition>();
            this.Commands.RegisterCommands <FuckYouCommand>();
            this.Commands.RegisterCommands <CustomAudioCommand>();
            this.Commands.RegisterCommands <MadWorldCommand>();
            this.Commands.RegisterCommands <CustomIntroCommand>();
            this.Commands.RegisterCommands <EmoteCommands>();
            this.Commands.RegisterCommands <RedditCommands>();
            this.Commands.SetHelpFormatter <HelpFormatter>();
            //this.Client.TypingStarted += Client_TypingStarted;

            // let's set up voice
            var vcfg = new VoiceNextConfiguration
            {
                VoiceApplication = VoiceApplication.Music,
                EnableIncoming   = false
            };

            // and let's enable it
            this.Voice = Client.UseVoiceNext(vcfg);

            // finally, let's connect and log in
            await Client.ConnectAsync();

            // for this example you will need to read the
            // VoiceNext setup guide, and include ffmpeg.

            RedditController.StartSubscriptionThreadsThread();

            // and this is to prevent premature quitting
            await Task.Delay(-1);
        }
Ejemplo n.º 6
0
        public async Task Controller_UsingADomain_AllDBSavesHaveDomain()
        {
            var controller = new RedditController(new MixedDomainRedditAccess(), new MockRepository());
            var posts = await controller.GetSubreddit("bbc.com");

            var expected = new List<UserPostsModel>
            {
                new UserPostsModel
                {
                    Author = "Account1",
                    Posts = new List<PostDto>
                    {
                        new PostDto
                        {
                            Id = "1",
                            Title = "1",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink = "link"
                        },
                        new PostDto
                        {
                            Id = "2",
                            Title = "2",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink = "link"
                        }
                    }
                },
                new UserPostsModel
                {
                    Author = "Account2",
                    Posts = new List<PostDto>
                    {
                        new PostDto
                        {
                            Id = "3",
                            Title = "3",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink = "link"
                        },
                        new PostDto
                        {
                            Id = "4",
                            Title = "4",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink = "link"
                        }
                    }
                },
                new UserPostsModel
                {
                    Author = "Account3",
                    Posts = new List<PostDto>
                    {
                        new PostDto
                        {
                            Id = "5",
                            Title = "5",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink = "link"
                        }
                    }
                }
            };

            var actualList = posts.ToList();

            Assert.AreEqual(expected, actualList);
        }
Ejemplo n.º 7
0
        public async Task Controller_UsingADomain_AllDBSavesHaveDomain()
        {
            var controller = new RedditController(new MixedDomainRedditAccess(), new MockRepository());
            var posts      = await controller.GetSubreddit("bbc.com");

            var expected = new List <UserPostsModel>
            {
                new UserPostsModel
                {
                    Author = "Account1",
                    Posts  = new List <PostDto>
                    {
                        new PostDto
                        {
                            Id          = "1",
                            Title       = "1",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink   = "link"
                        },
                        new PostDto
                        {
                            Id          = "2",
                            Title       = "2",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink   = "link"
                        }
                    }
                },
                new UserPostsModel
                {
                    Author = "Account2",
                    Posts  = new List <PostDto>
                    {
                        new PostDto
                        {
                            Id          = "3",
                            Title       = "3",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink   = "link"
                        },
                        new PostDto
                        {
                            Id          = "4",
                            Title       = "4",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink   = "link"
                        }
                    }
                },
                new UserPostsModel
                {
                    Author = "Account3",
                    Posts  = new List <PostDto>
                    {
                        new PostDto
                        {
                            Id          = "5",
                            Title       = "5",
                            CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0),
                            PermaLink   = "link"
                        }
                    }
                }
            };

            var actualList = posts.ToList();

            Assert.AreEqual(expected, actualList);
        }