// Process the email and send it to everyone
        public async Task ProcessTrades()
        {
            // Take a screenshot of the email
            _driver.Navigate().GoToUrl("file:///C:/Users/Administrator/Desktop/ARK Bot/result.html");
            System.Threading.Thread.Sleep(10000);
            var ss = ((ITakesScreenshot)_driver).GetScreenshot();

            ss.SaveAsFile("ark.png");

            // Send it to Twitter
            var uploadedImage = await _twitterClient.Upload.UploadTweetImageAsync(File.ReadAllBytes("ark.png"));

            var tweetText = "(Click to enlarge)\nARK's Trading Information for Today";
            await _twitterClient.Tweets.PublishTweetAsync(new PublishTweetParameters(tweetText.Length <= 280 ? tweetText : $"(Click to enlarge)\nARK's Trading Information for {DateTime.Now:MM/dd}")
            {
                Medias = { uploadedImage }
            });

            // Send it to Discord
            // Create the embed
            var embed = new EmbedBuilder()
                        .WithColor(EmbedUtils.ARKColor)
                        .WithAuthor(new EmbedAuthorBuilder()
                                    .WithName($"ARK's Trading Information for Today")
                                    .WithIconUrl(EmbedUtils.Logo))
                        .WithImageUrl("attachment://ark.png")
                        .WithFooter("Via ARK Trade Notifications")
                        .Build();

            // Send it to everyone
            foreach (var guildChannel in DataStorage.LoadGuildChannelData(Config.GuildChannelsFile))
            {
                try
                {
                    var guild   = _client.GetGuild(guildChannel.GuildID);
                    var channel = guild.GetTextChannel(guildChannel.ChannelID);

                    if (guild != null && channel != null)
                    {
                        await guild.GetTextChannel(guildChannel.ChannelID).SendFileAsync("ark.png", null, embed: embed);

                        Console.WriteLine($"Successfully posted to {guild.Name}");
                    }
                }
                catch (HttpException e)
                {
                    if (e.HttpCode == HttpStatusCode.Forbidden)
                    {
                        // Oh well
                    }
                }
            }

            // Cleanup
            File.Delete("ark.png");
            File.Delete("result.html");
        }
Exemple #2
0
 // Initializer
 static GuildChannels()
 {
     if (DataStorage.SaveExists(Config.GuildChannelsFile))
     {
         guildChannelData = DataStorage.LoadGuildChannelData(Config.GuildChannelsFile).ToList();
     }
     else
     {
         guildChannelData = new List <GuildChannel>();
         SaveGuildChannelData();
     }
 }
Exemple #3
0
        private static GuildChannel GetOrCreateGuildChannelData(ulong guildID, ulong channelID)
        {
            guildChannelData = DataStorage.LoadGuildChannelData(Config.GuildChannelsFile).ToList();
            var result = from a in guildChannelData
                         where a.GuildID == guildID
                         select a;
            var account = result.FirstOrDefault();

            if (account == null)
            {
                account = CreateGuildChannelData(guildID, channelID);
            }
            return(account);
        }
        // Remove a server from our Guild Channel data if someone removes us
        private Task OnGuildLeft(SocketGuild guild)
        {
            var data         = DataStorage.LoadGuildChannelData(Config.GuildChannelsFile);
            var modifiedData = data.ToList();

            if (modifiedData.Any(x => x.GuildID == guild.Id))
            {
                modifiedData.Remove(modifiedData.First(x => x.GuildID == guild.Id));

                DataStorage.SaveGuildChannelData(modifiedData, Config.GuildChannelsFile);
                Console.WriteLine($"Left {guild.Name}. They were subsribed, so I removed them.");
            }
            else
            {
                Console.WriteLine($"Left {guild.Name}. They were not subscribed.");
            }

            return(Task.CompletedTask);
        }
        // Process the email and send it to everyone
        public async Task ProcessTrades(string email)
        {
            // Create the image
            ImageGenerator.MakeImage(ReadTrades(email));

            // Create the embed
            var embed = new EmbedBuilder()
                        .WithColor(EmbedUtils.ARKColor)
                        .WithAuthor(new EmbedAuthorBuilder()
                                    .WithName($"ARK Trading Information for {DateTime.Now:MM/dd}")
                                    .WithIconUrl(EmbedUtils.Logo))
                        .WithImageUrl("attachment://ark.png")
                        .WithFooter("Via ARK Trade Notifications")
                        .Build();

            // Send it to everyone
            foreach (var guildChannel in DataStorage.LoadGuildChannelData(GuildChannels.guildChannelsFile))
            {
                try
                {
                    var guild   = _client.GetGuild(guildChannel.GuildID);
                    var channel = guild.GetTextChannel(guildChannel.ChannelID);

                    if (guild != null && channel != null)
                    {
                        await guild.GetTextChannel(guildChannel.ChannelID).SendFileAsync("ark.png", null, embed: embed);

                        Console.WriteLine($"Successfully posted to {guild.Name}");
                    }
                }
                catch (HttpException e)
                {
                    if (e.HttpCode == HttpStatusCode.Forbidden)
                    {
                        // Oh well
                    }
                }
            }

            // Delete the local image
            File.Delete("ark.png");
        }
Exemple #6
0
        public async Task Announce([Remainder] string message)
        {
            // This is ONLY FOR ME!! In case I want to announce something
            // Maybe ARK resent their email and messed something up, or a new feature
            if (Context.User.Id != 354458973572956160)
            {
                return;
            }

            // Get the guild channel data and start sending this to everyone
            var guildChannels = DataStorage.LoadGuildChannelData(Config.GuildChannelsFile);

            // Create the embed
            var embed = new EmbedBuilder()
                        .WithColor(EmbedUtils.ARKColor)
                        .WithAuthor(new EmbedAuthorBuilder()
                                    .WithName("Announcement")
                                    .WithIconUrl(EmbedUtils.Logo))
                        .WithDescription(message)
                        .Build();

            // Send it to everyone
            foreach (var guildChannel in guildChannels)
            {
                try
                {
                    var guild = Context.Client.GetGuild(guildChannel.GuildID);
                    await guild.GetTextChannel(guildChannel.ChannelID).SendMessageAsync(null, false, embed);

                    Console.WriteLine($"Successfully posted to {guild.Name}");
                }
                catch (HttpException e)
                {
                    if (e.HttpCode == HttpStatusCode.Forbidden)
                    {
                        // Oh well
                    }
                }
            }
        }
Exemple #7
0
        public async Task Unsubscribe()
        {
            try
            {
                var user = (SocketGuildUser)Context.User;
                if (user.GuildPermissions.Administrator)
                {
                    var data         = DataStorage.LoadGuildChannelData(Config.GuildChannelsFile);
                    var modifiedData = data.ToList();

                    if (modifiedData.Any(x => x.GuildID == Context.Guild.Id))
                    {
                        modifiedData.Remove(modifiedData.First(x => x.GuildID == Context.Guild.Id));

                        DataStorage.SaveGuildChannelData(modifiedData, Config.GuildChannelsFile);
                        await Context.Channel.PrintSuccess(
                            $"This server is no longer subscribed to ARK notifications. You can subscribe again by doing `!ark subscribe`");
                    }
                    else
                    {
                        await Context.Channel.PrintError("This server is not subscribed to ARK notifications. You can subscribe by doing `!ark subscribe`");
                    }
                }
                else
                {
                    await Context.Channel.PrintError("Sorry, you must be an administrator to unsubscribe to ARK.");
                }
            }
            catch (HttpException e)
            {
                if (e.HttpCode == HttpStatusCode.Forbidden)
                {
                    await Context.User.PrintNoPermissionsMessage();
                }
            }
        }