feat: initial working version of service refs NOISSUE
This commit is contained in:
@@ -1,14 +1,83 @@
|
||||
|
||||
using Scalar.AspNetCore;
|
||||
using Microsoft.AspNetCore.OpenApi;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
DataContext.Instance = new DataContext();
|
||||
var groupId = "group.Wmk1UTVQTnh0Sjd6a0xiOGhnTnMzZlNkc2p2Q3c0SXJiQkU2eDlNU0hyTT0=";
|
||||
SignalIntegration.Instance = new SignalIntegration("192.168.1.108", 8719, "+4367762751895");
|
||||
await SignalIntegration.Instance.ListGroups();
|
||||
SignalIntegration.Instance = new SignalIntegration(AppConfiguration.Instance.SignalAPIEndpointUri,
|
||||
int.Parse(AppConfiguration.Instance.SignalAPIEndpointPort),
|
||||
AppConfiguration.Instance.HostPhoneNumber);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var userCheckTimer = new CronTimer("*/1 * * * *", "Europe/Vienna", includingSeconds: false);
|
||||
userCheckTimer.OnOccurence += async (s, ea) =>
|
||||
{
|
||||
var memberList = await SignalIntegration.Instance.GetMemberListAsync();
|
||||
var dci = DataContext.Instance;
|
||||
var needsSaving = false;
|
||||
foreach (var memberId in memberList)
|
||||
{
|
||||
var foundUser = dci.Users.Where(u => u.SignalMemberId == memberId).SingleOrDefault();
|
||||
if (foundUser == null)
|
||||
{
|
||||
var newUserContact = await SignalIntegration.Instance.GetContactAsync(memberId);
|
||||
Console.WriteLine("New user:");
|
||||
Console.WriteLine($" Name: {newUserContact.Name}");
|
||||
Console.WriteLine($" MemberId: {memberId}");
|
||||
User newUser = new User()
|
||||
{
|
||||
Name = newUserContact.Name,
|
||||
SignalMemberId = memberId,
|
||||
NickName = string.Empty,
|
||||
IsIntroduced = false
|
||||
};
|
||||
needsSaving = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needsSaving)
|
||||
{
|
||||
await dci.SaveChangesAsync();
|
||||
}
|
||||
await dci.DisposeAsync();
|
||||
};
|
||||
userCheckTimer.Start();
|
||||
|
||||
var userIntroTimer = new CronTimer("*/1 * * * *", "Europe/Vienna", includingSeconds: false);
|
||||
userIntroTimer.OnOccurence += async (s, ea) =>
|
||||
{
|
||||
var dci = DataContext.Instance;
|
||||
var introUsers = dci.Users.Where(u => !u.IsIntroduced);
|
||||
bool needsSaving = false;
|
||||
foreach (var user in introUsers)
|
||||
{
|
||||
await SignalIntegration.Instance.IntroduceUserAsync(user);
|
||||
user.IsIntroduced = true;
|
||||
needsSaving = true;
|
||||
}
|
||||
|
||||
if (needsSaving)
|
||||
{
|
||||
await dci.SaveChangesAsync();
|
||||
}
|
||||
await dci.DisposeAsync();
|
||||
};
|
||||
userIntroTimer.Start();
|
||||
|
||||
var pickOfTheDayTimer = new CronTimer("0 8 * * *", "Europe/Vienna", includingSeconds: false);
|
||||
pickOfTheDayTimer.OnOccurence += async (s, ea) =>
|
||||
{
|
||||
var dci = DataContext.Instance;
|
||||
var luckyUser = await dci.Users.ElementAtAsync((new Random()).Next(await dci.Users.CountAsync()));
|
||||
var userName = string.IsNullOrEmpty(luckyUser.NickName) ? luckyUser.Name : luckyUser.NickName;
|
||||
SignalIntegration.Instance.SendMessageToGroupAsync($"Today's chosen person to share a song is: **{userName}**");
|
||||
SignalIntegration.Instance.SendMessageToUserAsync($"Congratulations, you have been chosen to share a song today!", luckyUser.SignalMemberId);
|
||||
var suggestion = await dci.SuggestionHelpers.ElementAtAsync((new Random()).Next(await dci.SuggestionHelpers.CountAsync()));
|
||||
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);
|
||||
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);
|
||||
};
|
||||
pickOfTheDayTimer.Start();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddOpenApi();
|
||||
@@ -34,7 +103,4 @@ app.MapStaticAssets();
|
||||
app.MapRazorPages()
|
||||
.WithStaticAssets();
|
||||
|
||||
app.Run();
|
||||
|
||||
//Console.WriteLine("Size: " + DataContext.Instance.Songs.Count());
|
||||
//await SignalIntegration.Instance.ListGroups();
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user