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()); }
private void KillTimer() { ReminderTimer.Change(Timeout.Infinite, Timeout.Infinite); //stop the timer //Log & send message to user that timer has stopped ReminderServiceLog.Information($"Timer {EventName} ended. Bye bye!"); var msg = TextUtils.GetInfoText($"Reminder service for {EventName} stopped successfully"); ((IMessageChannel)_client.GetChannel(StatusChannelId)).SendMessageAsync(msg); }
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); } }