Esempio n. 1
0
        private static async Task MainBotLogic()
        {
            List <string> EmailIdsToSend = new List <string>();
            List <Embed>  EmbedsToSend   = new List <Embed>();

            while (true)
            {
                //Gets emails, First part of string array has Email, second is email ID (gross but it works)
                List <string[]> Emails = GmailLib.GmailFunctions.GetEmails();
                //for every email, check if its sent, if it isn't, send the date.
                foreach (string[] Email in Emails)
                {
                    //Date and place is on 5th line (arrays start at 0 whew), array indexed by lines, replace with regex later.
                    string DateForRoboticsStr = Email[0].Split("\n\r")[4];
                    if (!SentMessages.Contains(Email[1]))
                    {
                        /*
                         * TODO: Years change.
                         */
                        DateTime DateForRoboticsDateTimeObj;
                        DateForRoboticsDateTimeObj = ConvertToDateTimeObj(DateForRoboticsStr);
                        //if the date for robotics meeting has not passed and the date is only 1 day away, add date and time to embeds to send.
                        if (DateForRoboticsDateTimeObj > DateTime.Now && DateForRoboticsDateTimeObj - DateTime.Now < new TimeSpan(1, 0, 0, 0))
                        {
                            EmbedsToSend.Add(new Embed {
                                title       = "There is a Upcoming Robotics Meeting!",
                                description = "Date/Time: " + DateForRoboticsStr,
                                color       = 16731254
                            });
                            Console.WriteLine("Date/Time: " + DateForRoboticsStr);
                            //Acts as a buffer for emails that are going to be sent, but not yet sent.
                            EmailIdsToSend.Add(Email[1]);
                        }
                    }
                }
                //Make and send webhook
                Webhook WebhookToSend = new Webhook()
                {
                    username   = "******",
                    embeds     = EmbedsToSend,
                    avatar_url = "https://cdn.discordapp.com/avatars/453944196307615746/9a0bf2d580b7efa4f676196fb638c362.png?size=256"
                };
                //Sends message
                var response = await WebhookToSend.SendWebhook(ReadConfig());

                if (string.IsNullOrEmpty(response))
                {
                    Console.WriteLine("Message Succesfully sent!");
                }
                else
                {
                    Console.WriteLine("Discord's return Json: \n" + response);
                }
                //Adds EmailIds as sent.
                SentMessages.AddRange(EmailIdsToSend);
                Save <List <string> >(SentMessages, "data.bin");
                EmailIdsToSend.Clear();
                EmbedsToSend.Clear();
                System.Threading.Thread.Sleep(1000 * 3600);
                //restart
            }
        }