feat: implement Blazor web interface for GM session management
Deploy Telegram Bot / deploy (push) Has been cancelled
Deploy Telegram Bot / deploy (push) Has been cancelled
- Created GmRelay.Web project (Blazor Server) - Created GmRelay.Shared library for domain models and rendering - Refactored GmRelay.Bot to use the Shared library - Integrated Telegram Login widget with server-side HMAC verification - Added Dashboard, Group Details, and Edit Session pages - Enabled bot notifications and in-place message updates from web actions - Updated .NET Aspire orchestration and Docker Compose configuration
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
namespace GmRelay.Shared.Domain;
|
||||
|
||||
public static class MoscowTime
|
||||
{
|
||||
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
|
||||
|
||||
public static DateTimeOffset Now => DateTimeOffset.UtcNow.ToOffset(MoscowOffset);
|
||||
|
||||
public static DateTimeOffset ToMoscow(this DateTimeOffset utc) => utc.ToOffset(MoscowOffset);
|
||||
|
||||
public static string FormatMoscow(this DateTimeOffset utc)
|
||||
=> utc.ToOffset(MoscowOffset).ToString("d MMMM yyyy, HH:mm", System.Globalization.CultureInfo.GetCultureInfo("ru-RU"));
|
||||
|
||||
public static DateTime ToMoscow(this DateTime utcDt) => utcDt.Add(MoscowOffset);
|
||||
|
||||
public static string FormatMoscow(this DateTime utcDt)
|
||||
=> utcDt.Add(MoscowOffset).ToString("d MMMM yyyy, HH:mm", System.Globalization.CultureInfo.GetCultureInfo("ru-RU"));
|
||||
|
||||
public static string FormatMoscowShort(this DateTime utcDt)
|
||||
=> utcDt.Add(MoscowOffset).ToString("dd.MM");
|
||||
|
||||
public static bool TryParseMoscow(string text, out DateTimeOffset utcTime)
|
||||
{
|
||||
if (DateTime.TryParseExact(text, new[] { "dd.MM.yyyy HH:mm", "dd.MM.yyyy H:mm", "d.MM.yyyy HH:mm" },
|
||||
System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out var localDt))
|
||||
{
|
||||
utcTime = new DateTimeOffset(localDt, MoscowOffset).ToUniversalTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
utcTime = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace GmRelay.Shared.Domain;
|
||||
|
||||
public static class RsvpStatus
|
||||
{
|
||||
public const string Pending = "Pending";
|
||||
public const string Confirmed = "Confirmed";
|
||||
public const string Declined = "Declined";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace GmRelay.Shared.Domain;
|
||||
|
||||
public static class SessionStatus
|
||||
{
|
||||
public const string Planned = "Planned";
|
||||
public const string ConfirmationSent = "ConfirmationSent";
|
||||
public const string Confirmed = "Confirmed";
|
||||
public const string Cancelled = "Cancelled";
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Telegram.Bot" Version="22.9.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,62 @@
|
||||
using GmRelay.Shared.Domain;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
|
||||
namespace GmRelay.Shared.Rendering;
|
||||
|
||||
public sealed record SessionBatchDto(Guid SessionId, DateTime ScheduledAt, string Status);
|
||||
public sealed record ParticipantBatchDto(Guid SessionId, string DisplayName, string? TelegramUsername);
|
||||
|
||||
public static class SessionBatchRenderer
|
||||
{
|
||||
public static (string Text, InlineKeyboardMarkup Markup) Render(
|
||||
string title,
|
||||
IReadOnlyList<SessionBatchDto> sessions,
|
||||
IReadOnlyList<ParticipantBatchDto> participants)
|
||||
{
|
||||
var activeSessions = sessions.OrderBy(s => s.ScheduledAt).ToList();
|
||||
|
||||
var messageText = $"🎲 <b>Новые игры:</b> {System.Net.WebUtility.HtmlEncode(title)}\n\n" +
|
||||
$"<b>Расписание:</b>\n\n";
|
||||
|
||||
var buttons = new List<InlineKeyboardButton[]>();
|
||||
|
||||
foreach (var session in activeSessions)
|
||||
{
|
||||
var sessionPlayers = participants.Where(p => p.SessionId == session.SessionId).ToList();
|
||||
|
||||
messageText += $"📅 <b>{session.ScheduledAt.FormatMoscow()}</b>\n";
|
||||
messageText += $"👥 Игроки ({sessionPlayers.Count}):\n";
|
||||
|
||||
if (sessionPlayers.Count > 0)
|
||||
{
|
||||
messageText += string.Join("\n", sessionPlayers.Select(p => $" 👤 {(p.TelegramUsername != null ? "@" + p.TelegramUsername : p.DisplayName)}")) + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
messageText += " <i>Пока никто не записался</i>\n";
|
||||
}
|
||||
|
||||
if (session.Status == "Cancelled")
|
||||
{
|
||||
messageText += "❌ <i>Сессия отменена</i>\n\n";
|
||||
}
|
||||
else if (session.Status == "RecruitmentClosed")
|
||||
{
|
||||
messageText += "🔒 <i>Набор завершен</i>\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
messageText += "\n";
|
||||
var dateTitle = session.ScheduledAt.FormatMoscowShort();
|
||||
buttons.Add(new[]
|
||||
{
|
||||
InlineKeyboardButton.WithCallbackData($"✋ На {dateTitle}", $"join_session:{session.SessionId}"),
|
||||
InlineKeyboardButton.WithCallbackData($"❌ Отменить {dateTitle} (ГМ)", $"cancel_session:{session.SessionId}"),
|
||||
InlineKeyboardButton.WithCallbackData($"⏰ (ГМ)", $"reschedule_session:{session.SessionId}")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return (messageText, new InlineKeyboardMarkup(buttons));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user