feat: save submission history, refs #7
This commit is contained in:
@@ -31,7 +31,7 @@ userCheckTimer.OnOccurence += async (s, ea) =>
|
||||
var needsSaving = false;
|
||||
foreach (var memberId in memberList)
|
||||
{
|
||||
var foundUser = dci.Users.Where(u => u.SignalMemberId == memberId).SingleOrDefault();
|
||||
var foundUser = dci.Users?.Where(u => u.SignalMemberId == memberId).SingleOrDefault();
|
||||
if (foundUser == null)
|
||||
{
|
||||
var newUserContact = await SignalIntegration.Instance.GetContactAsync(memberId);
|
||||
@@ -47,7 +47,7 @@ userCheckTimer.OnOccurence += async (s, ea) =>
|
||||
LdapUserName = string.Empty,
|
||||
AssociationInProgress = false,
|
||||
};
|
||||
dci.Users.Add(newUser);
|
||||
dci.Users?.Add(newUser);
|
||||
needsSaving = true;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,13 @@ var userIntroTimer = new CronTimer("*/1 * * * *", "Europe/Vienna", includingSeco
|
||||
userIntroTimer.OnOccurence += async (s, ea) =>
|
||||
{
|
||||
var dci = DataContext.Instance;
|
||||
var introUsers = dci.Users.Where(u => !u.IsIntroduced);
|
||||
var introUsers = dci.Users?.Where(u => !u.IsIntroduced);
|
||||
if (introUsers == null)
|
||||
{
|
||||
await dci.DisposeAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
bool needsSaving = false;
|
||||
foreach (var user in introUsers)
|
||||
{
|
||||
@@ -87,34 +93,63 @@ Console.WriteLine("Setting up pick of the day timer");
|
||||
var pickOfTheDayTimer = new CronTimer("0 8 * * *", "Europe/Vienna", includingSeconds: false);
|
||||
pickOfTheDayTimer.OnOccurence += async (s, ea) =>
|
||||
{
|
||||
var rand = new Random();
|
||||
var num = rand.NextInt64();
|
||||
var mod = num % AppConfiguration.Instance.AverageDaysBetweenRequests;
|
||||
var dci = DataContext.Instance;
|
||||
|
||||
if (mod > 0)
|
||||
var lastSong = dci.SongSuggestions?.LastOrDefault();
|
||||
|
||||
if (lastSong != null && lastSong.Date >= DateTime.Today.Subtract(TimeSpan.FromDays(AppConfiguration.Instance.DaysBetweenRequests)))
|
||||
{
|
||||
Console.WriteLine("Skipping pick of the day today!");
|
||||
await dci.DisposeAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var dci = DataContext.Instance;
|
||||
if (dci.Users == null || dci.SuggestionHelpers == null || dci.SongSuggestions == null)
|
||||
{
|
||||
Console.WriteLine("Unable to properly initialize DB context!");
|
||||
await dci.DisposeAsync();
|
||||
return;
|
||||
}
|
||||
var luckyUser = await dci.Users.ElementAtAsync((new Random()).Next(await dci.Users.CountAsync()));
|
||||
if (luckyUser == null)
|
||||
{
|
||||
Console.WriteLine("Unable to determine today's lucky user!");
|
||||
await dci.DisposeAsync();
|
||||
return;
|
||||
}
|
||||
var userName = string.IsNullOrEmpty(luckyUser.NickName) ? luckyUser.Name : luckyUser.NickName;
|
||||
var suggestion = await dci.SuggestionHelpers.ElementAtAsync((new Random()).Next(await dci.SuggestionHelpers.CountAsync()));
|
||||
await SignalIntegration.Instance.SendMessageToGroupAsync($"Today's chosen person to share a song is: **{userName}**");
|
||||
await SignalIntegration.Instance.SendMessageToGroupAsync($"Today's (optional) suggestion helper to help you pick a song is:\n\n**{suggestion.Title}**\n\n*{suggestion.Description}*");
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Congratulations, you have been chosen to share a song today!", luckyUser.SignalMemberId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Today's (optional) suggestion helper to help you pick a song is:\n\n**{suggestion.Title}**\n\n*{suggestion.Description}*", luckyUser.SignalMemberId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"For now please just share your suggestion with the group - in the future I might ask you to share directly with me or via the website to help me keep track of past suggestions!", luckyUser.SignalMemberId);
|
||||
var newSongSuggestion = new SongSuggestion()
|
||||
{
|
||||
User = luckyUser,
|
||||
SuggestionHelper = suggestion,
|
||||
UserHasSubmitted = false,
|
||||
HasUsedSuggestion = false,
|
||||
Date = DateTime.Today
|
||||
};
|
||||
if (luckyUser.SignalMemberId is string signalId)
|
||||
{
|
||||
await dci.SongSuggestions.AddAsync(newSongSuggestion);
|
||||
await dci.SaveChangesAsync();
|
||||
await SignalIntegration.Instance.SendMessageToGroupAsync($"Today's chosen person to share a song is: **{userName}**");
|
||||
await SignalIntegration.Instance.SendMessageToGroupAsync($"Today's (optional) suggestion helper to help you pick a song is:\n\n**{suggestion.Title}**\n\n*{suggestion.Description}*");
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Congratulations, you have been chosen to share a song today!", signalId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Today's (optional) suggestion helper to help you pick a song is:\n\n**{suggestion.Title}**\n\n*{suggestion.Description}*", signalId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"For now please just share your suggestion with the group - in the future I might ask you to share directly with me or via the website to help me keep track of past suggestions!", luckyUser.SignalMemberId);
|
||||
}
|
||||
await dci.DisposeAsync();
|
||||
};
|
||||
pickOfTheDayTimer.Start();
|
||||
|
||||
var startUserAssociationProcess = async (User userToAssociate) =>
|
||||
{
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Hi, I see you are not associated with any website user yet.", userToAssociate.SignalMemberId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"If you haven't yet, please navigate to https://users.disi.dev to create a new account.", userToAssociate.SignalMemberId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Once you have done so, go to https://sotd.disi.dev, login, navigate to \"Unclaimed Phone Numbers\" and click on the \"Claim\" button to start the claim process.", userToAssociate.SignalMemberId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"With a future update you will be required to submit songs via your user account - at that point you will be skipped during the selection process if you have not yet claimed your phone number!", userToAssociate.SignalMemberId);
|
||||
if (userToAssociate.SignalMemberId is string signalId)
|
||||
{
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Hi, I see you are not associated with any website user yet.", signalId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"If you haven't yet, please navigate to https://users.disi.dev to create a new account.", signalId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"Once you have done so, go to https://sotd.disi.dev, login, navigate to \"Unclaimed Phone Numbers\" and click on the \"Claim\" button to start the claim process.", signalId);
|
||||
await SignalIntegration.Instance.SendMessageToUserAsync($"With a future update you will be required to submit songs via your user account - at that point you will be skipped during the selection process if you have not yet claimed your phone number!", signalId);
|
||||
}
|
||||
};
|
||||
|
||||
Console.WriteLine("Setting up LdapAssociation timer");
|
||||
@@ -122,6 +157,12 @@ var ldapAssociationTimer = new CronTimer("*/10 * * * *", "Europe/Vienna", includ
|
||||
ldapAssociationTimer.OnOccurence += async (s, ea) =>
|
||||
{
|
||||
var dci = DataContext.Instance;
|
||||
if (dci.Users == null)
|
||||
{
|
||||
Console.WriteLine("Unable to properly initialize DB context!");
|
||||
await dci.DisposeAsync();
|
||||
return;
|
||||
}
|
||||
var nonAssociatedUsers = dci.Users.Where(u => string.IsNullOrEmpty(u.LdapUserName) && !u.AssociationInProgress);
|
||||
var needsSaving = false;
|
||||
foreach (var user in nonAssociatedUsers)
|
||||
|
||||
Reference in New Issue
Block a user