Beispiel #1
0
        protected internal void SendReminder(ReminderRecord record, int minutes)
        {
            const string rtmp = @"rtmp://vps295136.vps.ovh.ca/live/";
            var          user = GetUser(record.DiscordUserName);

            ReminderServiceLog.Information($"Sending record {record.DiscordUserName} : {record.Game} in {minutes} minutes");
            var reminderMessage = new StringBuilder();

            reminderMessage.Append(user != null ? user.Mention : record.DiscordUserName.Split('#')[0]);
            // reminderMessage.Append(user != null ? user.Username : record.DiscordUserName.Split('#')[0]); no tag for debug
            ulong channelId = 0;

            if (!record.VolunteerType.IsNullOrEmpty())
            {
                reminderMessage.Append($" your shift for `Volunteer: {record.VolunteerType}` is coming up in **{minutes} minutes!**");
                channelId = GetVolunteerReminderChannel(); //MWSF Volunteer Reminders
            }
            else
            {
                reminderMessage.Append($" your run for `{record.Game}: {record.Category}` is coming up in **{minutes} minutes!**");
                //  reminderMessage.Append($" Please stream to `{rtmp}` with stream key `{record.StreamKey.ToLower()}`");
                channelId = GetRunnerReminderChannel(); //MWSF Runner Reminders
            }
            ((IMessageChannel)_client.GetChannel(channelId)).SendMessageAsync(reminderMessage.ToString());
        }
Beispiel #2
0
        private void SendMessageToBartaan(ReminderRecord record)
        {
            const ulong id       = 264274966025994241; //Bartaan's ID
            var         bartaan  = _client.GetUser(id);
            string      msg      = $"Hey {bartaan.Mention}";
            var         userName = record.DiscordUserName.Split('#')[0];

            if (userName.ToLower() == "cajink")
            {
                msg += $" Cajink's run will start in 30 minutes!";
            }
            if (userName.ToLower() == "marquisdan" && record.VolunteerType.ToLower() == "host")
            {
                msg += $" marquisdan's hosting will start in 30 minutes!";
            }

            bartaan.SendMessageAsync(msg);
        }
Beispiel #3
0
        protected internal virtual bool IsScheduledTimeWithinReminderRange(ReminderRecord record, out int minutes)
        {
            //Find the (possibly adjusted) run time of the record. Store the value in minutes.
            var runTime = record.Scheduled;

            if (ShouldRecordScheduleBeAdjusted(record))
            {
                runTime = runTime.AddMinutes(_minutesBehind); //Adjust if marathon is ahead or behind schedule
            }
            ;
            var currentTime = GetCurrentTime();
            var timeSpan    = runTime - currentTime;

            minutes = timeSpan.Minutes;

            //Determine if a reminder should be sent.
            if (runTime < currentTime)
            {
                //Do not send a reminder if reminder time already past
                return(false);
            }
            //Finally, determine if within reminder window and return result
            return(timeSpan <= TimeSpan.FromMinutes((int)ReminderTimes.Task + 1)); //Makes most messages say 30m not 29
        }
Beispiel #4
0
 private bool ShouldRecordScheduleBeAdjusted(ReminderRecord record)
 {
     //Only records with flexible schedules should be adjusted (e.g. those tied specifically to runs.)
     //Static volunteer records should not be adjusted (restreaming, setup, Social Media etc)
     return(!record.Game.IsNullOrEmpty() || record.VolunteerType.ToLower() == "host");
 }
Beispiel #5
0
        private void ReadReminderCsv(string fileName)
        {
            //if all records have been read in every file, kill the timer
            if (_runnersDone && _volunteersDone)
            {
                ReminderServiceLog.Information($"All records sent, ending {EventName} timer");
                KillTimer();
                return;
            }

            //Update how far we are behind
            UpdateTimeBehind();

            //Don't process files that are already finished
            switch (fileName)
            {
            case Filename_Runners:
                if (_runnersDone)
                {
                    return;
                }
                break;

            case Filename_Volunteers:
                if (_volunteersDone)
                {
                    return;
                }
                break;

            default: throw new ArgumentException($"{fileName} is invalid!");
            }

            var filePath       = $@"{_filePath}{fileName}.csv";
            var processingPath = $@"{_filePath}{fileName}_Processing.csv";

            try
            {
                var records = new List <ReminderRecord>();
                //Setup the CSV Reader
                using var reader = new StreamReader(filePath);
                using var csv    = new CsvReader(reader, CultureInfo.InvariantCulture);
                csv.Configuration.MissingFieldFound = null;
                csv.Read();
                csv.ReadHeader();

                //Read the CSV and populate list of records
                while (csv.Read())
                {
                    var record = new ReminderRecord
                    {
                        Scheduled       = csv.GetField <DateTime>(ScheduleTimeHeader),
                        Game            = csv.GetField <string>(GameHeader),
                        StreamKey       = csv.GetField <string>(StreamKeyHeader),
                        VolunteerType   = csv.GetField <string>(VolunteerTypeHeader),
                        Category        = csv.GetField <string>(CategoryHeader),
                        DiscordUserName = csv.GetField <string>(DiscordUserHeader),
                        Sent            = csv.GetField <int>(SentHeader)
                    };

                    records.Add(record);
                }

                //Process the reminders here, send any reminders that are due & update the sent flag
                var processedRecords = ProcessReminderRecords(records).ToList();

                //Mark the file done if all rows have been sent
                if (processedRecords.Count(x => x.Sent == 1) == processedRecords.Count)
                {
                    switch (fileName)
                    {
                    case Filename_Runners:
                        _runnersDone = true;
                        break;

                    case Filename_Volunteers:
                        _volunteersDone = true;
                        break;

                    default: throw new ArgumentException($"{fileName} is invalid!");
                    }
                }

                using (var writer = new StreamWriter(processingPath))
                {
                    using var csv2 = new CsvWriter(writer, CultureInfo.InvariantCulture);
                    csv2.WriteRecords(processedRecords);
                }
                reader.Close();

                ReminderServiceLog.Verbose($"Replacing file {fileName} with processed content");
                File.Replace(processingPath, filePath, null); //Replace existing file with processing
            }
            catch (Exception e)
            {
                ReminderServiceLog.Error(e.Message);
                ReminderServiceLog.Error(e.StackTrace);
                _client.GetUser(167082289325408256).SendMessageAsync(e.StackTrace);
            }
        }