refactor(wizard): move core to Shared, add IWizardMessenger contract (issue #112)
Moves the game-creation wizard state machine, view builder, and platform-neutral contracts (callback data, step names, storage exception, club option, step limits) from GmRelay.Bot to GmRelay.Shared. Telegram continues to work through a new TelegramWizardMessenger implementing IWizardMessenger and a WizardInteractionMapper that converts Update → WizardInteraction. Wires the new platform column on wizard_drafts (V032 migration) and switches chat/owner/thread/message ids to TEXT so the same table can hold Discord snowflakes later. - GameCreationWizard: now in Shared, takes IWizardMessenger + IWizardDraftRepository, dispatches on WizardInteraction. - New IWizardMessenger contract with Edit/Send/Answer/GetOwnerClubs (returns string ids so Telegram longs and Discord snowflakes both fit). - New WizardStepViewBuilder in Shared returns (text, IReadOnlyList<WizardAction>); TelegramWizardMessenger renders actions into InlineKeyboardMarkup via a new Bot-side ToInlineKeyboard helper. - New WizardInteractionMapper in Bot (5-case test) converts Telegram Update to WizardInteraction. - WizardDraft gains a Platform column; ChatId/MessageThreadId/OwnerId/ DraftMessageId switched to string. V032 migrates existing rows and rebuilds the owner lookup index on (platform, owner_id). - All existing wizard / create-session tests updated to the new contract (HandleInteractionAsync + WizardInteraction). Wizard callback-data format preserved. - dotnet build clean, dotnet format --verify-no-changes clean, all 101 wizard tests pass.
This commit is contained in:
@@ -1,40 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
using GmRelay.Shared.Domain;
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession;
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession.Wizard;
|
||||
using GmRelay.Shared.Platform;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using SharedCreateSessionHandler = GmRelay.Shared.Features.Sessions.CreateSession.CreateSessionHandler;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession;
|
||||
|
||||
/// <summary>
|
||||
/// Wizard-driven entry point for game-session creation. Replaces the legacy
|
||||
/// text-template parser. Exposes <see cref="StartWizardAsync"/> (called from
|
||||
/// <c>/newsession</c>), <see cref="TryResumeAsync"/> (continue a draft), and
|
||||
/// <see cref="SubmitDraftAsync"/> (finalize on "✅ Создать" callback).
|
||||
/// Telegram-side entry point for the wizard-driven session creation
|
||||
/// flow. Talks to the shared wizard through <see cref="IWizardMessenger"/>
|
||||
/// and the platform-neutral <see cref="WizardDraft"/>. Keeps the
|
||||
/// platform glue (mapping <c>Message</c> to draft fields, rendering
|
||||
/// error keyboards, etc.) local to <c>GmRelay.Bot</c>.
|
||||
/// </summary>
|
||||
public sealed class CreateSessionHandler
|
||||
{
|
||||
private const int MaxRetries = 3;
|
||||
private const string PlatformName = "Telegram";
|
||||
|
||||
private readonly IWizardDraftRepository _drafts;
|
||||
private readonly SharedCreateSessionHandler _shared;
|
||||
private readonly ITelegramWizardMessenger _messenger;
|
||||
private readonly IWizardMessenger _messenger;
|
||||
private readonly ILogger<CreateSessionHandler> _log;
|
||||
|
||||
public CreateSessionHandler(
|
||||
IWizardDraftRepository drafts,
|
||||
SharedCreateSessionHandler shared,
|
||||
ITelegramWizardMessenger messenger,
|
||||
IWizardMessenger messenger,
|
||||
ILogger<CreateSessionHandler> log)
|
||||
{
|
||||
_drafts = drafts;
|
||||
@@ -44,14 +45,14 @@ public sealed class CreateSessionHandler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entry point for <c>/newsession</c>. If a non-expired draft already exists for
|
||||
/// this (chat, thread, owner), returns <c>null</c> so the caller can render a
|
||||
/// "Continue / Start over / Cancel" menu.
|
||||
/// Entry point for <c>/newsession</c>. If a non-expired draft
|
||||
/// already exists for this owner, returns <c>null</c> so the caller
|
||||
/// can render a "Continue / Start over / Cancel" menu.
|
||||
/// </summary>
|
||||
public async Task<WizardDraft?> StartWizardAsync(Message message, CancellationToken ct)
|
||||
{
|
||||
var existing = await _drafts.GetActiveAsync(
|
||||
message.Chat.Id, message.MessageThreadId, message.From?.Id ?? 0, ct);
|
||||
var ownerId = (message.From?.Id ?? 0).ToString(CultureInfo.InvariantCulture);
|
||||
var existing = await _drafts.GetActiveAsync(PlatformName, ownerId, ct);
|
||||
if (existing is not null)
|
||||
{
|
||||
return null;
|
||||
@@ -60,9 +61,10 @@ public sealed class CreateSessionHandler
|
||||
var draft = new WizardDraft
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
ChatId = message.Chat.Id,
|
||||
MessageThreadId = message.MessageThreadId,
|
||||
OwnerTelegramId = message.From?.Id ?? 0,
|
||||
ChatId = message.Chat.Id.ToString(CultureInfo.InvariantCulture),
|
||||
MessageThreadId = message.MessageThreadId?.ToString(CultureInfo.InvariantCulture),
|
||||
OwnerId = ownerId,
|
||||
Platform = PlatformName,
|
||||
Step = WizardStepNames.Type,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
@@ -70,9 +72,8 @@ public sealed class CreateSessionHandler
|
||||
};
|
||||
await _drafts.UpsertAsync(draft, ct);
|
||||
|
||||
var (text, kb) = WizardStep.Render(draft, new WizardPayload());
|
||||
var msgId = await _messenger.SendGroupMessageAsync(
|
||||
draft.ChatId, draft.MessageThreadId, text, kb, ct);
|
||||
var (text, actions) = WizardStepViewBuilder.Build(draft, new WizardPayload());
|
||||
var msgId = await _messenger.SendDraftMessageAsync(draft, text, actions, ct);
|
||||
draft.DraftMessageId = msgId;
|
||||
draft.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await _drafts.UpsertAsync(draft, ct);
|
||||
@@ -80,24 +81,27 @@ public sealed class CreateSessionHandler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resume an existing draft — returns the draft row so the caller can re-render.
|
||||
/// Resume an existing draft — returns the draft row so the caller
|
||||
/// can re-render the resume/reset menu.
|
||||
/// </summary>
|
||||
public Task<WizardDraft?> TryResumeAsync(Message message, CancellationToken ct) =>
|
||||
_drafts.GetActiveAsync(
|
||||
message.Chat.Id, message.MessageThreadId, message.From?.Id ?? 0, ct);
|
||||
public Task<WizardDraft?> TryResumeAsync(Message message, CancellationToken ct)
|
||||
{
|
||||
var ownerId = (message.From?.Id ?? 0).ToString(CultureInfo.InvariantCulture);
|
||||
return _drafts.GetActiveAsync(PlatformName, ownerId, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalize: build shared command(s), call the shared handler, edit the wizard message.
|
||||
/// On failure, retry up to <see cref="MaxRetries"/> times before deleting the draft.
|
||||
/// Finalize: build shared command(s), call the shared handler, edit
|
||||
/// the wizard message. On failure, retry up to <see cref="MaxRetries"/>
|
||||
/// times before deleting the draft.
|
||||
/// </summary>
|
||||
public async Task SubmitDraftAsync(WizardDraft draft, CancellationToken ct)
|
||||
{
|
||||
var payload = LoadPayload(draft);
|
||||
if (!IsComplete(payload, out var missing))
|
||||
{
|
||||
await _messenger.EditMessageTextAsync(
|
||||
draft.ChatId, draft.MessageThreadId, draft.DraftMessageId ?? 0,
|
||||
$"❌ Не заполнены поля: {missing}", EmptyKeyboard(), ct);
|
||||
await _messenger.EditDraftMessageAsync(
|
||||
draft, $"❌ Не заполнены поля: {missing}", Array.Empty<WizardAction>(), ct);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,10 +113,11 @@ public sealed class CreateSessionHandler
|
||||
await _shared.HandleAsync(cmd, ct);
|
||||
}
|
||||
var totalSessions = commands.Sum(c => c.ScheduledTimes.Count);
|
||||
await _messenger.EditMessageTextAsync(
|
||||
draft.ChatId, draft.MessageThreadId, draft.DraftMessageId ?? 0,
|
||||
await _messenger.EditDraftMessageAsync(
|
||||
draft,
|
||||
$"✅ Создано: {totalSessions} {(totalSessions == 1 ? "сессия" : "сессий")}",
|
||||
EmptyKeyboard(), ct);
|
||||
Array.Empty<WizardAction>(),
|
||||
ct);
|
||||
await _drafts.DeleteAsync(draft.Id, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -122,26 +127,29 @@ public sealed class CreateSessionHandler
|
||||
SavePayload(draft, payload);
|
||||
if (payload.RetryCount >= MaxRetries)
|
||||
{
|
||||
await _messenger.EditMessageTextAsync(
|
||||
draft.ChatId, draft.MessageThreadId, draft.DraftMessageId ?? 0,
|
||||
await _messenger.EditDraftMessageAsync(
|
||||
draft,
|
||||
"💥 Не удалось создать сессию после 3 попыток. Используйте /newsession, чтобы начать заново.",
|
||||
EmptyKeyboard(), ct);
|
||||
Array.Empty<WizardAction>(),
|
||||
ct);
|
||||
await _drafts.DeleteAsync(draft.Id, ct);
|
||||
return;
|
||||
}
|
||||
draft.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await _drafts.UpsertAsync(draft, ct);
|
||||
await _messenger.EditMessageTextAsync(
|
||||
draft.ChatId, draft.MessageThreadId, draft.DraftMessageId ?? 0,
|
||||
await _messenger.EditDraftMessageAsync(
|
||||
draft,
|
||||
$"💥 Ошибка: {ex.Message}\nПопытка {payload.RetryCount}/{MaxRetries}.",
|
||||
RetryCancelKeyboard(), ct);
|
||||
RetryCancelActions(),
|
||||
ct);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Build shared commands ────────────────────────────────────────
|
||||
// The shared handler creates one session per scheduled time in a single transaction
|
||||
// and assigns the same batch_id to all of them. A wizard pool therefore produces ONE
|
||||
// command with N times; a single-game wizard produces ONE command with one time.
|
||||
// The shared handler creates one session per scheduled time in a
|
||||
// single transaction and assigns the same batch_id to all of them.
|
||||
// A wizard pool therefore produces ONE command with N times; a
|
||||
// single-game wizard produces ONE command with one time.
|
||||
private static List<CreateSessionCommand> BuildCommands(WizardDraft draft, WizardPayload p)
|
||||
{
|
||||
if (p.Type == WizardCreationType.Pool && p.Pool is { } pool && pool.Slots.Count > 0)
|
||||
@@ -153,7 +161,7 @@ public sealed class CreateSessionHandler
|
||||
p,
|
||||
pool.Slots.Select(s => s.ScheduledAt).ToList(),
|
||||
MaxPlayersForPool(pool),
|
||||
isOneShot: false)
|
||||
isOneShot: false),
|
||||
};
|
||||
}
|
||||
return new List<CreateSessionCommand>
|
||||
@@ -163,7 +171,7 @@ public sealed class CreateSessionHandler
|
||||
p,
|
||||
new[] { p.Single?.ScheduledAt ?? default },
|
||||
p.Single?.MaxPlayers ?? 0,
|
||||
isOneShot: true)
|
||||
isOneShot: true),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -177,18 +185,17 @@ public sealed class CreateSessionHandler
|
||||
int maxPlayers,
|
||||
bool isOneShot)
|
||||
{
|
||||
var gmId = draft.OwnerTelegramId;
|
||||
var user = new PlatformUser(
|
||||
PlatformKind.Telegram,
|
||||
gmId.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
draft.OwnerId,
|
||||
DisplayName: string.Empty,
|
||||
ExternalUsername: null);
|
||||
var group = new PlatformGroup(
|
||||
PlatformKind.Telegram,
|
||||
draft.ChatId.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
draft.ChatId,
|
||||
DisplayName: string.Empty,
|
||||
ExternalChannelId: null,
|
||||
ExternalThreadId: draft.MessageThreadId?.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
ExternalThreadId: draft.MessageThreadId);
|
||||
return new CreateSessionCommand(
|
||||
User: user,
|
||||
Group: group,
|
||||
@@ -245,10 +252,9 @@ public sealed class CreateSessionHandler
|
||||
}
|
||||
|
||||
// ── Keyboards ────────────────────────────────────────────────────
|
||||
private static InlineKeyboardMarkup EmptyKeyboard() => new(Array.Empty<InlineKeyboardButton[]>());
|
||||
private static InlineKeyboardMarkup RetryCancelKeyboard() => new(new[]
|
||||
private static IReadOnlyList<WizardAction> RetryCancelActions() => new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("🔁 Повторить", WizardCallbackData.Create()) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Отмена", WizardCallbackData.Cancel()) },
|
||||
});
|
||||
new WizardAction("🔁 Повторить", WizardCallbackData.Create(), WizardActionStyle.Primary),
|
||||
new WizardAction("❌ Отмена", WizardCallbackData.Cancel(), WizardActionStyle.Danger),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,504 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GmRelay.Shared.Domain;
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession.Wizard;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
/// <summary>
|
||||
/// Central state machine for the game/pool creation wizard.
|
||||
/// </summary>
|
||||
public sealed class GameCreationWizard
|
||||
{
|
||||
private readonly IWizardDraftRepository _drafts;
|
||||
private readonly ITelegramWizardMessenger _messenger;
|
||||
private readonly ILogger<GameCreationWizard> _log;
|
||||
|
||||
public GameCreationWizard(
|
||||
IWizardDraftRepository drafts,
|
||||
ITelegramWizardMessenger messenger,
|
||||
ILogger<GameCreationWizard> log)
|
||||
{
|
||||
_drafts = drafts;
|
||||
_messenger = messenger;
|
||||
_log = log;
|
||||
}
|
||||
|
||||
/// <summary>Handle a text or callback update from the owning GM.</summary>
|
||||
public async Task HandleUpdateAsync(Update update, WizardDraft draft, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (update.CallbackQuery is { } cb)
|
||||
{
|
||||
await HandleCallbackAsync(draft, cb, ct);
|
||||
}
|
||||
else if (update.Message is { } msg)
|
||||
{
|
||||
await HandleTextAsync(draft, msg, ct);
|
||||
}
|
||||
}
|
||||
catch (WizardStorageException)
|
||||
{
|
||||
// Surface storage failure; do not crash the update loop.
|
||||
if (update.CallbackQuery is { } cb2)
|
||||
{
|
||||
await _messenger.AnswerCallbackAsync(cb2.Id, "💥 Ошибка хранилища, попробуйте /newsession", ct);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Wizard update failed for draft {DraftId}", draft.Id);
|
||||
if (update.CallbackQuery is { } cb3)
|
||||
{
|
||||
try { await _messenger.AnswerCallbackAsync(cb3.Id, "⚠️ Ошибка", ct); }
|
||||
catch { /* swallow — we're already in error path */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleCallbackAsync(WizardDraft draft, CallbackQuery cb, CancellationToken ct)
|
||||
{
|
||||
if (!WizardCallbackData.TryParse(cb.Data, out var action, out var step, out var choice))
|
||||
{
|
||||
await _messenger.AnswerCallbackAsync(cb.Id, "Неизвестная команда", ct);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case "cancel":
|
||||
await _drafts.DeleteAsync(draft.Id, ct);
|
||||
await _messenger.EditMessageTextAsync(
|
||||
draft.ChatId, draft.MessageThreadId, draft.DraftMessageId ?? 0,
|
||||
"❌ Мастер отменён.", EmptyKeyboard, ct);
|
||||
await _messenger.AnswerCallbackAsync(cb.Id, null, ct);
|
||||
return;
|
||||
|
||||
case "back":
|
||||
ApplyBack(draft, step);
|
||||
await PersistAndRenderAsync(draft, cb.Id, ct);
|
||||
return;
|
||||
|
||||
case "create":
|
||||
// Routed by CreateSessionHandler, not here.
|
||||
await _messenger.AnswerCallbackAsync(cb.Id, null, ct);
|
||||
return;
|
||||
|
||||
default:
|
||||
// For "Choice" callbacks, action == step.
|
||||
await ApplyChoiceAsync(draft, step, choice, cb.Id, ct);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleTextAsync(WizardDraft draft, Message msg, CancellationToken ct)
|
||||
{
|
||||
if (msg.Text is not { } text)
|
||||
{
|
||||
// Photo or other non-text — handle cover step only.
|
||||
if (msg.Photo is { Length: > 0 } && draft.Step == WizardStepNames.Cover)
|
||||
{
|
||||
var fileId = msg.Photo[^1].FileId;
|
||||
ApplyCoverPhoto(draft, fileId);
|
||||
await PersistAndRenderAsync(draft, null, ct);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var (nextStep, error, payload) = ApplyText(draft, text);
|
||||
if (payload is { } p) SavePayload(draft, p);
|
||||
if (error is { } errMsg && draft.DraftMessageId is { } mid)
|
||||
{
|
||||
// Re-render the same step with ⚠️ prefix.
|
||||
var (rendered, kb) = WizardStep.Render(draft, LoadPayload(draft), null);
|
||||
await _messenger.EditMessageTextAsync(
|
||||
draft.ChatId, draft.MessageThreadId, mid,
|
||||
"⚠️ " + errMsg + "\n\n" + rendered, kb, ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextStep is { } step)
|
||||
{
|
||||
draft.Step = step;
|
||||
}
|
||||
await PersistAndRenderAsync(draft, null, ct);
|
||||
}
|
||||
|
||||
private async Task ApplyChoiceAsync(WizardDraft draft, string step, string choice, string callbackId, CancellationToken ct)
|
||||
{
|
||||
var (nextStep, error, payload) = ApplyChoice(draft, step, choice);
|
||||
if (error is { } err)
|
||||
{
|
||||
await _messenger.AnswerCallbackAsync(callbackId, err, ct);
|
||||
return;
|
||||
}
|
||||
if (payload is { } p) SavePayload(draft, p);
|
||||
if (nextStep is { } s)
|
||||
{
|
||||
draft.Step = s;
|
||||
}
|
||||
await PersistAndRenderAsync(draft, callbackId, ct);
|
||||
}
|
||||
|
||||
private async Task PersistAndRenderAsync(WizardDraft draft, string? callbackId, CancellationToken ct)
|
||||
{
|
||||
draft.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await _drafts.UpsertAsync(draft, ct);
|
||||
var payload = LoadPayload(draft);
|
||||
IReadOnlyList<WizardClubOption>? clubs = null;
|
||||
if (draft.Step == WizardStepNames.PickClub)
|
||||
{
|
||||
clubs = await _messenger.GetGmClubsAsync(draft.OwnerTelegramId, ct);
|
||||
}
|
||||
var (text, kb) = WizardStep.Render(draft, payload, clubs);
|
||||
await _messenger.EditMessageTextAsync(
|
||||
draft.ChatId, draft.MessageThreadId, draft.DraftMessageId ?? 0,
|
||||
text, kb, ct);
|
||||
if (callbackId is { } id)
|
||||
{
|
||||
await _messenger.AnswerCallbackAsync(id, null, ct);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Text input dispatcher ─────────────────────────────────────────
|
||||
private static (string? nextStep, string? error, WizardPayload payload) ApplyText(WizardDraft draft, string input)
|
||||
{
|
||||
var payload = LoadPayload(draft);
|
||||
switch (draft.Step)
|
||||
{
|
||||
case WizardStepNames.Title:
|
||||
return ValidateText(input, WizardStep.MaxTitleLength, "Название не может быть пустым", "Слишком длинное название", out var title)
|
||||
? (WizardStepNames.Description, SetTitle(payload, title), payload)
|
||||
: (null, title, payload);
|
||||
|
||||
case WizardStepNames.Description:
|
||||
if (input == "-") return (WizardStepNames.Cover, SetDescription(payload, null), payload);
|
||||
return ValidateText(input, WizardStep.MaxDescriptionLength, "Описание не может быть пустым", "Слишком длинное описание", out var desc)
|
||||
? (WizardStepNames.Cover, SetDescription(payload, desc), payload)
|
||||
: (null, desc, payload);
|
||||
|
||||
case WizardStepNames.Cover:
|
||||
if (input == "-") return (NextAfterCover(payload), SetImageUrl(payload, null), payload);
|
||||
if (Uri.TryCreate(input, UriKind.Absolute, out var uri) && (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
|
||||
return (NextAfterCover(payload), SetImageUrl(payload, input), payload);
|
||||
return (null, "Некорректный URL", payload);
|
||||
|
||||
case WizardStepNames.System when payload.System is null:
|
||||
// "Other" branch — only active if free-text was offered.
|
||||
return ValidateText(input, WizardStep.MaxSystemLength, "Слишком длинное название системы", "Слишком длинное название системы", out var sys)
|
||||
? (WizardStepNames.Duration, SetSystem(payload, sys), payload)
|
||||
: (null, sys, payload);
|
||||
|
||||
case WizardStepNames.Duration when payload.DurationMinutes is null:
|
||||
return TryParseHours(input, out var durMin)
|
||||
? (WizardStepNames.DateTime, SetDurationMinutes(payload, durMin), payload)
|
||||
: (null, "Неверная длительность (1..12 ч)", payload);
|
||||
|
||||
case WizardStepNames.DateTime:
|
||||
return MoscowTime.TryParseMoscow(input, out var dt) && dt > DateTimeOffset.UtcNow
|
||||
? (WizardStepNames.Capacity, SetScheduledAt(payload, dt), payload)
|
||||
: (null, dt == default ? "Не удалось разобрать дату" : "Дата в прошлом", payload);
|
||||
|
||||
case WizardStepNames.Capacity when payload.Single?.MaxPlayers is null:
|
||||
return int.TryParse(input, out var cap) && cap >= WizardStep.MinCapacity && cap <= WizardStep.MaxCapacity
|
||||
? (WizardStepNames.Visibility, SetMaxPlayers(payload, cap), payload)
|
||||
: (null, "Лимит должен быть 1..50", payload);
|
||||
|
||||
case WizardStepNames.PoolSystemDuration when payload.System is null:
|
||||
return ValidateText(input, WizardStep.MaxSystemLength, "Слишком длинное название системы", "Слишком длинное название системы", out var psys)
|
||||
? (WizardStepNames.PoolSystemDuration, SetSystem(payload, psys), payload)
|
||||
: (null, psys, payload);
|
||||
|
||||
case WizardStepNames.PoolSystemDuration when payload.DurationMinutes is null:
|
||||
return TryParseHours(input, out var pdur)
|
||||
? (WizardStepNames.Visibility, SetDurationMinutes(payload, pdur), payload)
|
||||
: (null, "Неверная длительность (1..12 ч)", payload);
|
||||
|
||||
case WizardStepNames.PoolSlotDateTime:
|
||||
return MoscowTime.TryParseMoscow(input, out var slotDt) && slotDt > DateTimeOffset.UtcNow
|
||||
? (WizardStepNames.PoolSlotCapacity, SetCurrentSlotDateTime(payload, slotDt), payload)
|
||||
: (null, slotDt == default ? "Не удалось разобрать дату" : "Дата в прошлом", payload);
|
||||
|
||||
case WizardStepNames.PoolSlotCapacity:
|
||||
return int.TryParse(input, out var slotCap) && slotCap >= WizardStep.MinCapacity && slotCap <= WizardStep.MaxCapacity
|
||||
? (WizardStepNames.PoolAddSlots, SetCurrentSlotMaxPlayers(payload, slotCap), payload)
|
||||
: (null, "Лимит должен быть 1..50", payload);
|
||||
|
||||
default:
|
||||
return (null, "Ожидается выбор кнопкой", payload);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Callback (button) dispatcher ──────────────────────────────────
|
||||
private static (string? nextStep, string? error, WizardPayload payload) ApplyChoice(WizardDraft draft, string step, string choice)
|
||||
{
|
||||
var payload = LoadPayload(draft);
|
||||
var (next, err) = step switch
|
||||
{
|
||||
WizardStepNames.Type => ApplyTypeChoice(payload, choice),
|
||||
WizardStepNames.System => ApplySystemChoice(payload, choice),
|
||||
WizardStepNames.Duration => ApplyDurationChoice(payload, choice),
|
||||
WizardStepNames.Capacity => ApplyCapacityChoice(payload, choice),
|
||||
WizardStepNames.Visibility => ApplyVisibilityChoice(payload, choice),
|
||||
WizardStepNames.PickClub => ApplyPickClubChoice(payload, choice),
|
||||
WizardStepNames.Publish => ApplyPublishChoice(payload, choice),
|
||||
WizardStepNames.PoolSystemDuration => ApplyPoolSystemDurationChoice(payload, choice),
|
||||
WizardStepNames.PoolAddSlots => ApplyPoolAddSlotsChoice(payload, choice),
|
||||
WizardStepNames.PoolSlotCapacity => ApplyPoolSlotCapacityChoice(payload, choice),
|
||||
_ => (null, "Неизвестный шаг"),
|
||||
};
|
||||
return (next, err, payload);
|
||||
}
|
||||
|
||||
private static (string?, string?) ApplyTypeChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"single" => (WizardStepNames.Title, SetType(p, WizardCreationType.Single)),
|
||||
"pool" => (WizardStepNames.Title, SetType(p, WizardCreationType.Pool)),
|
||||
_ => (null, "Неизвестный выбор"),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplySystemChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"_other" => (WizardStepNames.System, null), // stay, await text
|
||||
"_skip" => (NextAfterSystem(p), SetSystem(p, null)),
|
||||
{ } code => (WizardStepNames.Duration, SetSystem(p, code)),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplyDurationChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"_other" => (WizardStepNames.Duration, null),
|
||||
"_skip" => (NextAfterDuration(p), SetDurationMinutes(p, null)),
|
||||
{ } d => int.TryParse(d, out var min)
|
||||
? (NextAfterDuration(p), SetDurationMinutes(p, min))
|
||||
: (null, "Неверная длительность"),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplyCapacityChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"waitlist:on" => (WizardStepNames.Visibility, SetWaitlist(p, true)),
|
||||
"waitlist:off" => (WizardStepNames.Visibility, SetWaitlist(p, false)),
|
||||
_ => (null, "Неизвестный выбор"),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplyVisibilityChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"public" => (NextAfterVisibility(p), SetVisibility(p, WizardVisibility.Public)),
|
||||
"club" => (WizardStepNames.PickClub, SetVisibility(p, WizardVisibility.Club)),
|
||||
"members" => (WizardStepNames.PickClub, SetVisibility(p, WizardVisibility.Members)),
|
||||
"pickclub" => (WizardStepNames.PickClub, null),
|
||||
_ => (null, "Неизвестный выбор"),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplyPickClubChoice(WizardPayload p, string choice)
|
||||
=> Guid.TryParse(choice, out var id)
|
||||
? (NextAfterVisibility(p), SetClubId(p, id))
|
||||
: (null, "Неверный идентификатор клуба");
|
||||
|
||||
private static (string?, string?) ApplyPublishChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"yes" => (WizardStepNames.Confirm, SetPublishInShowcase(p, true)),
|
||||
"no" => (WizardStepNames.Confirm, SetPublishInShowcase(p, false)),
|
||||
_ => (null, "Неизвестный выбор"),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplyPoolSystemDurationChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"_custom" => (WizardStepNames.PoolSystemDuration, null),
|
||||
{ } c when c.Contains(':') => SplitSystemDuration(c) is (var sys, var dur)
|
||||
? (WizardStepNames.Visibility, SetSystem(p, sys) ?? SetDurationMinutes(p, dur))
|
||||
: (null, "Неверный выбор"),
|
||||
_ => (null, "Неизвестный выбор"),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplyPoolAddSlotsChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"add" => BeginNewPoolSlot(p),
|
||||
"done" => p.Pool?.Slots.Count > 0
|
||||
? (WizardStepNames.PoolConfirm, null)
|
||||
: (null, "Добавьте хотя бы один слот"),
|
||||
_ => (null, "Неизвестный выбор"),
|
||||
};
|
||||
|
||||
private static (string?, string?) ApplyPoolSlotCapacityChoice(WizardPayload p, string choice) => choice switch
|
||||
{
|
||||
"waitlist:on" => (WizardStepNames.PoolAddSlots, CommitCurrentPoolSlot(p, true)),
|
||||
"waitlist:off" => (WizardStepNames.PoolAddSlots, CommitCurrentPoolSlot(p, false)),
|
||||
_ => (null, "Неизвестный выбор"),
|
||||
};
|
||||
|
||||
// ── Back navigation ───────────────────────────────────────────────
|
||||
private static void ApplyBack(WizardDraft draft, string fromStep)
|
||||
{
|
||||
// The callback's "step" portion is the step the user is currently on (e.g. the
|
||||
// Confirm button emits `wizard:back` with no step, in which case we fall back to
|
||||
// the draft's current step). Both should produce the same result.
|
||||
var current = string.IsNullOrEmpty(fromStep) ? draft.Step : fromStep;
|
||||
var payload = LoadPayload(draft);
|
||||
var previous = PreviousStep(current, payload);
|
||||
if (previous is { } step) draft.Step = step;
|
||||
}
|
||||
|
||||
private static string? PreviousStep(string step, WizardPayload p) => step switch
|
||||
{
|
||||
WizardStepNames.Title => null, // first step
|
||||
WizardStepNames.Description => WizardStepNames.Title,
|
||||
WizardStepNames.Cover => WizardStepNames.Description,
|
||||
WizardStepNames.System => WizardStepNames.Cover,
|
||||
WizardStepNames.Duration => WizardStepNames.System,
|
||||
WizardStepNames.DateTime => WizardStepNames.Duration,
|
||||
WizardStepNames.Capacity => WizardStepNames.DateTime,
|
||||
WizardStepNames.Visibility => WizardStepNames.Capacity,
|
||||
WizardStepNames.PickClub => WizardStepNames.Visibility,
|
||||
WizardStepNames.Publish => WizardStepNames.PickClub,
|
||||
WizardStepNames.Confirm => WizardStepNames.Publish,
|
||||
|
||||
WizardStepNames.PoolSystemDuration => null, // first pool step
|
||||
WizardStepNames.PoolAddSlots => WizardStepNames.PoolSystemDuration,
|
||||
WizardStepNames.PoolSlotDateTime => WizardStepNames.PoolAddSlots,
|
||||
WizardStepNames.PoolSlotCapacity => WizardStepNames.PoolSlotDateTime,
|
||||
WizardStepNames.PoolConfirm => WizardStepNames.PoolAddSlots,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// ── Payload I/O ───────────────────────────────────────────────────
|
||||
internal static WizardPayload LoadPayload(WizardDraft draft)
|
||||
{
|
||||
if (string.IsNullOrEmpty(draft.PayloadJson)) return new WizardPayload();
|
||||
return System.Text.Json.JsonSerializer.Deserialize(
|
||||
draft.PayloadJson, WizardPayloadJsonContext.Default.WizardPayload) ?? new WizardPayload();
|
||||
}
|
||||
|
||||
private static void SavePayload(WizardDraft draft, WizardPayload payload)
|
||||
{
|
||||
draft.PayloadJson = System.Text.Json.JsonSerializer.Serialize(
|
||||
payload, WizardPayloadJsonContext.Default.WizardPayload);
|
||||
}
|
||||
|
||||
// Mutators — return the error message if any (kept here to centralise flow).
|
||||
private static string? SetTitle(WizardPayload p, string v) { p.Title = v; return null; }
|
||||
private static string? SetDescription(WizardPayload p, string? v) { p.Description = v; return null; }
|
||||
private static string? SetImageUrl(WizardPayload p, string? v) { p.ImageUrl = v; p.ImageFileId = null; return null; }
|
||||
private static void ApplyCoverPhoto(WizardDraft d, string fileId)
|
||||
{
|
||||
var p = LoadPayload(d);
|
||||
p.ImageFileId = fileId;
|
||||
p.ImageUrl = null;
|
||||
SavePayload(d, p);
|
||||
var next = NextAfterCover(p);
|
||||
if (next is { } s) d.Step = s;
|
||||
}
|
||||
private static string? SetSystem(WizardPayload p, string? v) { p.System = v; return null; }
|
||||
private static string? SetDurationMinutes(WizardPayload p, int? v) { p.DurationMinutes = v; return null; }
|
||||
private static string? SetScheduledAt(WizardPayload p, DateTimeOffset v)
|
||||
{ p.Single ??= new WizardSingleInput(); p.Single.ScheduledAt = v; return null; }
|
||||
private static string? SetMaxPlayers(WizardPayload p, int v)
|
||||
{ p.Single ??= new WizardSingleInput(); p.Single.MaxPlayers = v; return null; }
|
||||
private static string? SetWaitlist(WizardPayload p, bool v) { p.Waitlist = v; return null; }
|
||||
private static string? SetVisibility(WizardPayload p, WizardVisibility? v) { p.Visibility = v; return null; }
|
||||
private static string? SetClubId(WizardPayload p, Guid v) { p.ClubId = v; return null; }
|
||||
private static string? SetType(WizardPayload p, WizardCreationType v) { p.Type = v; return null; }
|
||||
private static string? SetPublishInShowcase(WizardPayload p, bool v) { p.PublishInShowcase = v; return null; }
|
||||
|
||||
private static string? SetCurrentSlotDateTime(WizardPayload p, DateTimeOffset v)
|
||||
{
|
||||
p.Pool ??= new WizardPoolInput();
|
||||
var current = EnsureCurrentPoolSlot(p);
|
||||
current.ScheduledAt = v;
|
||||
return null;
|
||||
}
|
||||
private static string? SetCurrentSlotMaxPlayers(WizardPayload p, int v)
|
||||
{
|
||||
p.Pool ??= new WizardPoolInput();
|
||||
var current = EnsureCurrentPoolSlot(p);
|
||||
current.MaxPlayers = v;
|
||||
return null;
|
||||
}
|
||||
private static string? CommitCurrentPoolSlot(WizardPayload p, bool waitlist)
|
||||
{
|
||||
p.Pool ??= new WizardPoolInput();
|
||||
var current = EnsureCurrentPoolSlot(p);
|
||||
current.Waitlist = waitlist;
|
||||
return null;
|
||||
}
|
||||
private static (string? nextStep, string? error) BeginNewPoolSlot(WizardPayload p)
|
||||
{
|
||||
p.Pool ??= new WizardPoolInput();
|
||||
p.Pool.Slots.Add(new WizardSlotInput());
|
||||
return (WizardStepNames.PoolSlotDateTime, null);
|
||||
}
|
||||
private static WizardSlotInput EnsureCurrentPoolSlot(WizardPayload p)
|
||||
{
|
||||
// Slots added via BeginNewPoolSlot are always committed before they leave the
|
||||
// PoolSlotCapacity step (CommitCurrentPoolSlot). If we somehow get here without
|
||||
// a slot, start a new one to keep the flow recoverable.
|
||||
p.Pool ??= new WizardPoolInput();
|
||||
var last = p.Pool.Slots.LastOrDefault();
|
||||
if (last is not null && last.MaxPlayers == 0) return last;
|
||||
p.Pool.Slots.Add(new WizardSlotInput());
|
||||
return p.Pool.Slots[^1];
|
||||
}
|
||||
|
||||
// ── Flow helpers ──────────────────────────────────────────────────
|
||||
private static string? NextAfterCover(WizardPayload p) => p.Type == WizardCreationType.Pool
|
||||
? WizardStepNames.PoolSystemDuration : WizardStepNames.System;
|
||||
private static string? NextAfterSystem(WizardPayload p) => WizardStepNames.Duration;
|
||||
private static string? NextAfterDuration(WizardPayload p)
|
||||
{
|
||||
if (p.Type == WizardCreationType.Pool) return WizardStepNames.Visibility;
|
||||
return p.Single?.MaxPlayers is not null ? WizardStepNames.Visibility : WizardStepNames.DateTime;
|
||||
}
|
||||
private static string? NextAfterVisibility(WizardPayload p)
|
||||
{
|
||||
if (p.Visibility is WizardVisibility.Club or WizardVisibility.Members)
|
||||
{
|
||||
if (p.ClubId is null) return WizardStepNames.PickClub;
|
||||
}
|
||||
return p.Type == WizardCreationType.Pool ? WizardStepNames.PoolAddSlots : WizardStepNames.Publish;
|
||||
}
|
||||
|
||||
private static (string? sys, int? dur) SplitSystemDuration(string s)
|
||||
{
|
||||
var idx = s.IndexOf(':');
|
||||
if (idx <= 0 || idx >= s.Length - 1) return (null, null);
|
||||
var sys = s.Substring(0, idx);
|
||||
if (!int.TryParse(s.Substring(idx + 1), out var durMin)) return (null, null);
|
||||
return (sys, durMin);
|
||||
}
|
||||
|
||||
private static bool ValidateText(
|
||||
string input, int maxLength, string emptyMsg, string tooLongMsg, out string trimmed)
|
||||
{
|
||||
trimmed = input.Trim();
|
||||
if (string.IsNullOrEmpty(trimmed))
|
||||
{
|
||||
trimmed = emptyMsg;
|
||||
return false;
|
||||
}
|
||||
if (trimmed.Length > maxLength)
|
||||
{
|
||||
trimmed = tooLongMsg;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryParseHours(string input, out int minutes)
|
||||
{
|
||||
minutes = 0;
|
||||
var s = input.Trim();
|
||||
if (s.EndsWith("h", StringComparison.OrdinalIgnoreCase)) s = s.Substring(0, s.Length - 1);
|
||||
if (s.EndsWith("ч", StringComparison.OrdinalIgnoreCase)) s = s.Substring(0, s.Length - 1);
|
||||
if (!double.TryParse(s, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var hours)) return false;
|
||||
if (hours < WizardStep.MinDurationHours || hours > WizardStep.MaxDurationHours) return false;
|
||||
minutes = (int)Math.Round(hours * 60);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static readonly InlineKeyboardMarkup EmptyKeyboard = new(Array.Empty<InlineKeyboardButton[]>());
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
public sealed record WizardClubOption(Guid ClubId, string Name);
|
||||
|
||||
public interface ITelegramWizardMessenger
|
||||
{
|
||||
Task<long> EditMessageTextAsync(long chatId, int? messageThreadId, long messageId, string text, Telegram.Bot.Types.ReplyMarkups.InlineKeyboardMarkup keyboard, CancellationToken ct);
|
||||
Task<long> SendGroupMessageAsync(long chatId, int? messageThreadId, string text, Telegram.Bot.Types.ReplyMarkups.InlineKeyboardMarkup keyboard, CancellationToken ct);
|
||||
Task AnswerCallbackAsync(string callbackId, string? text, CancellationToken ct);
|
||||
Task<IReadOnlyList<WizardClubOption>> GetGmClubsAsync(long ownerTelegramId, CancellationToken ct);
|
||||
}
|
||||
@@ -3,48 +3,79 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession.Wizard;
|
||||
using Npgsql;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
/// <summary>
|
||||
/// Telegram-side implementation of <see cref="IWizardMessenger"/>.
|
||||
/// Translates the platform-neutral wizard contracts into the
|
||||
/// <c>Telegram.Bot</c> SDK calls. All Telegram-specific behaviour
|
||||
/// (message editing, callback ack, group lookup) lives behind the
|
||||
/// interface so the wizard core stays in <c>GmRelay.Shared</c>.
|
||||
/// </summary>
|
||||
public sealed class TelegramWizardMessenger(
|
||||
ITelegramBotClient bot,
|
||||
NpgsqlDataSource dataSource) : ITelegramWizardMessenger
|
||||
NpgsqlDataSource dataSource) : IWizardMessenger
|
||||
{
|
||||
public async Task<long> EditMessageTextAsync(
|
||||
long chatId, int? messageThreadId, long messageId, string text,
|
||||
InlineKeyboardMarkup keyboard, CancellationToken ct)
|
||||
public async Task<string> EditDraftMessageAsync(
|
||||
WizardDraft draft,
|
||||
string text,
|
||||
IReadOnlyList<WizardAction> keyboard,
|
||||
CancellationToken ct)
|
||||
{
|
||||
if (!TryParseChatId(draft.ChatId, out var chatId))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Wizard draft {draft.Id} has un-parseable chat id '{draft.ChatId}'.");
|
||||
}
|
||||
if (!TryParseMessageId(draft.DraftMessageId, out var messageId))
|
||||
{
|
||||
// No draft message recorded yet — fall back to sending a new one.
|
||||
return await SendDraftMessageAsync(draft, text, keyboard, ct);
|
||||
}
|
||||
var msg = await bot.EditMessageText(
|
||||
chatId: chatId,
|
||||
messageId: (int)messageId,
|
||||
messageId: messageId,
|
||||
text: text,
|
||||
replyMarkup: keyboard,
|
||||
replyMarkup: WizardStep.ToInlineKeyboard(keyboard),
|
||||
cancellationToken: ct);
|
||||
return msg.MessageId;
|
||||
return msg.MessageId.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public async Task<long> SendGroupMessageAsync(
|
||||
long chatId, int? messageThreadId, string text,
|
||||
InlineKeyboardMarkup keyboard, CancellationToken ct)
|
||||
public async Task<string> SendDraftMessageAsync(
|
||||
WizardDraft draft,
|
||||
string text,
|
||||
IReadOnlyList<WizardAction> keyboard,
|
||||
CancellationToken ct)
|
||||
{
|
||||
if (!TryParseChatId(draft.ChatId, out var chatId))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Wizard draft {draft.Id} has un-parseable chat id '{draft.ChatId}'.");
|
||||
}
|
||||
int? threadId = TryParseThreadId(draft.MessageThreadId, out var parsedThread)
|
||||
? parsedThread
|
||||
: null;
|
||||
|
||||
var msg = await bot.SendMessage(
|
||||
chatId: chatId,
|
||||
text: text,
|
||||
messageThreadId: messageThreadId,
|
||||
replyMarkup: keyboard,
|
||||
messageThreadId: threadId,
|
||||
replyMarkup: WizardStep.ToInlineKeyboard(keyboard),
|
||||
cancellationToken: ct);
|
||||
return msg.MessageId;
|
||||
return msg.MessageId.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public async Task AnswerCallbackAsync(string callbackId, string? text, CancellationToken ct)
|
||||
public Task AnswerInteractionAsync(string interactionId, string? text, CancellationToken ct)
|
||||
{
|
||||
await bot.AnswerCallbackQuery(callbackId, text: text, cancellationToken: ct);
|
||||
return bot.AnswerCallbackQuery(interactionId, text: text, cancellationToken: ct);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<WizardClubOption>> GetGmClubsAsync(long ownerTelegramId, CancellationToken ct)
|
||||
public async Task<IReadOnlyList<WizardClubOption>> GetOwnerClubsAsync(string ownerId, CancellationToken ct)
|
||||
{
|
||||
// Adjusted from the plan: this codebase models "clubs" as game_groups
|
||||
// (V001 created game_groups; V026 added public_slug; no `clubs` table exists,
|
||||
@@ -57,14 +88,49 @@ public sealed class TelegramWizardMessenger(
|
||||
FROM game_groups g
|
||||
JOIN group_managers gm ON gm.group_id = g.id
|
||||
JOIN players p ON p.id = gm.player_id
|
||||
WHERE p.platform = 'Telegram'
|
||||
WHERE p.platform = @Platform
|
||||
AND p.external_user_id = @ExternalId
|
||||
GROUP BY g.id, g.name
|
||||
ORDER BY g.name
|
||||
""";
|
||||
await using var connection = await dataSource.OpenConnectionAsync(ct);
|
||||
var rows = await connection.QueryAsync<WizardClubOption>(
|
||||
new CommandDefinition(sql, new { ExternalId = ownerTelegramId.ToString() }, cancellationToken: ct));
|
||||
new CommandDefinition(
|
||||
sql,
|
||||
new { Platform = "Telegram", ExternalId = ownerId },
|
||||
cancellationToken: ct));
|
||||
return rows.AsList();
|
||||
}
|
||||
|
||||
private static bool TryParseChatId(string raw, out long chatId)
|
||||
{
|
||||
if (long.TryParse(raw, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out chatId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
chatId = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryParseMessageId(string? raw, out int messageId)
|
||||
{
|
||||
if (raw is not null &&
|
||||
int.TryParse(raw, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out messageId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
messageId = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryParseThreadId(string? raw, out int threadId)
|
||||
{
|
||||
if (raw is not null &&
|
||||
int.TryParse(raw, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out threadId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
threadId = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
public static class WizardCallbackData
|
||||
{
|
||||
public const string Prefix = "wizard";
|
||||
|
||||
public static string Choice(string step, string choice) => $"{Prefix}:{step}:{choice}";
|
||||
public static string Back() => $"{Prefix}:back";
|
||||
public static string Cancel() => $"{Prefix}:cancel";
|
||||
public static string Create() => $"{Prefix}:create";
|
||||
|
||||
public static bool TryParse(string? data, out string action, out string step, out string choice)
|
||||
{
|
||||
action = step = choice = string.Empty;
|
||||
if (string.IsNullOrEmpty(data)) return false;
|
||||
var parts = data.Split(':', 3);
|
||||
if (parts.Length < 2 || parts[0] != Prefix) return false;
|
||||
action = parts[1];
|
||||
step = parts.Length >= 3 ? parts[1] : string.Empty;
|
||||
choice = parts.Length >= 3 ? parts[2] : string.Empty;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession.Wizard;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Telegram <see cref="Update"/> into the
|
||||
/// platform-neutral <see cref="WizardInteraction"/> consumed by
|
||||
/// <see cref="GameCreationWizard"/>. The mapping is the only place in
|
||||
/// the bot that knows about both <c>Telegram.Bot.Types</c> and the
|
||||
/// shared wizard contract, so a future Discord adapter can do the same
|
||||
/// for its native event without changing the wizard core.
|
||||
/// </summary>
|
||||
public static class WizardInteractionMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns <c>true</c> if <paramref name="update"/> carries a
|
||||
/// wizard-relevant interaction (text message, photo, or
|
||||
/// callback). Side-effect-free: the wizard state is not touched.
|
||||
/// </summary>
|
||||
public static bool TryMap(Update update, out WizardInteraction interaction)
|
||||
{
|
||||
interaction = default!;
|
||||
if (update.CallbackQuery is { } cb && cb.From is not null)
|
||||
{
|
||||
interaction = new WizardInteraction(
|
||||
OwnerId: cb.From.Id.ToString(CultureInfo.InvariantCulture),
|
||||
Text: null,
|
||||
CallbackPayload: cb.Data,
|
||||
PhotoFileId: null,
|
||||
PhotoUrl: null,
|
||||
InteractionId: cb.Id);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (update.Message is { From: not null } msg)
|
||||
{
|
||||
// The original Telegram wizard dispatched on
|
||||
// `msg.Text is null` to identify a non-text update (photo,
|
||||
// document, sticker, …) and only ran the text pipeline
|
||||
// otherwise. We preserve that semantic: a message that
|
||||
// carries a photo is a photo interaction even if it has a
|
||||
// caption. Text is null for photos; the wizard checks
|
||||
// PhotoFileId separately when Text is null.
|
||||
//
|
||||
// Note: `Message.MessageId` is exposed as a read-only
|
||||
// property in Telegram.Bot, so the mapper cannot embed the
|
||||
// numeric id in the interaction. Text interactions never
|
||||
// need an ack, so the InteractionId is unused for them —
|
||||
// we just emit a stable sentinel.
|
||||
var hasPhoto = msg.Photo is { Length: > 0 };
|
||||
var text = hasPhoto ? null : msg.Text;
|
||||
var photoFileId = hasPhoto ? msg.Photo![^1].FileId : null;
|
||||
interaction = new WizardInteraction(
|
||||
OwnerId: msg.From!.Id.ToString(CultureInfo.InvariantCulture),
|
||||
Text: text,
|
||||
CallbackPayload: null,
|
||||
PhotoFileId: photoFileId,
|
||||
PhotoUrl: null,
|
||||
InteractionId: "msg");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,253 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GmRelay.Shared.Domain;
|
||||
using System.Linq;
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession.Wizard;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
/// <summary>
|
||||
/// Telegram-side renderer for wizard keyboards. Acts as the adapter
|
||||
/// between the platform-neutral <see cref="WizardAction"/> list
|
||||
/// produced by <see cref="WizardStepViewBuilder"/> and Telegram's
|
||||
/// <see cref="InlineKeyboardMarkup"/>. Each <see cref="WizardAction"/>
|
||||
/// becomes its own row (matching the pre-refactor Telegram layout).
|
||||
/// <see cref="WizardActionStyle"/> is currently ignored by Telegram
|
||||
/// because the platform has no native primary/danger/success button
|
||||
/// colours.
|
||||
/// </summary>
|
||||
public static class WizardStep
|
||||
{
|
||||
public const int MaxTitleLength = 200;
|
||||
public const int MaxDescriptionLength = 4000;
|
||||
public const int MaxSystemLength = 100;
|
||||
public const int MaxCapacity = 50;
|
||||
public const int MinCapacity = 1;
|
||||
public const int MinDurationHours = 1;
|
||||
public const int MaxDurationHours = 12;
|
||||
public const int MaxTitleLength = WizardStepLimits.MaxTitleLength;
|
||||
public const int MaxDescriptionLength = WizardStepLimits.MaxDescriptionLength;
|
||||
public const int MaxSystemLength = WizardStepLimits.MaxSystemLength;
|
||||
public const int MaxCapacity = WizardStepLimits.MaxCapacity;
|
||||
public const int MinCapacity = WizardStepLimits.MinCapacity;
|
||||
public const int MinDurationHours = WizardStepLimits.MinDurationHours;
|
||||
public const int MaxDurationHours = WizardStepLimits.MaxDurationHours;
|
||||
|
||||
public static (string text, InlineKeyboardMarkup keyboard) Render(
|
||||
/// <summary>
|
||||
/// Render the platform-neutral view into a (text, Telegram keyboard)
|
||||
/// pair. Used by the wizard's surrounding code (router, create
|
||||
/// handler) when it needs to send a fresh draft message or render
|
||||
/// the resume/reset menu.
|
||||
/// </summary>
|
||||
public static (string Text, InlineKeyboardMarkup Keyboard) Render(
|
||||
WizardDraft draft,
|
||||
WizardPayload payload,
|
||||
IReadOnlyList<WizardClubOption>? clubs = null)
|
||||
{
|
||||
return draft.Step switch
|
||||
{
|
||||
WizardStepNames.Type => RenderType(),
|
||||
WizardStepNames.Title => RenderTitle(),
|
||||
WizardStepNames.Description => RenderDescription(),
|
||||
WizardStepNames.Cover => RenderCover(),
|
||||
WizardStepNames.System => RenderSystem(),
|
||||
WizardStepNames.Duration => RenderDuration(),
|
||||
WizardStepNames.DateTime => RenderDateTime(),
|
||||
WizardStepNames.Capacity => RenderCapacity(),
|
||||
WizardStepNames.Visibility => RenderVisibility(),
|
||||
WizardStepNames.PickClub => RenderPickClub(clubs ?? Array.Empty<WizardClubOption>()),
|
||||
WizardStepNames.Publish => RenderPublish(),
|
||||
WizardStepNames.Confirm => RenderSingleConfirm(payload),
|
||||
|
||||
WizardStepNames.PoolSystemDuration => RenderPoolSystemDuration(),
|
||||
WizardStepNames.PoolAddSlots => RenderPoolAddSlots(payload),
|
||||
WizardStepNames.PoolSlotDateTime => RenderPoolSlotDateTime(),
|
||||
WizardStepNames.PoolSlotCapacity => RenderPoolSlotCapacity(),
|
||||
WizardStepNames.PoolConfirm => RenderPoolConfirm(payload),
|
||||
|
||||
_ => throw new InvalidOperationException($"Unknown wizard step: {draft.Step}"),
|
||||
};
|
||||
var (text, actions) = WizardStepViewBuilder.Build(draft, payload, clubs);
|
||||
return (text, ToInlineKeyboard(actions));
|
||||
}
|
||||
|
||||
// ── Single-game renderers ──────────────────────────────────────────
|
||||
private static (string, InlineKeyboardMarkup) RenderType() => (
|
||||
"🎲 Создание новой игровой сессии\n\nЧто создаём?",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("🎯 Одну игру", WizardCallbackData.Choice(WizardStepNames.Type, "single")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("📅 Пул игр", WizardCallbackData.Choice(WizardStepNames.Type, "pool")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Отмена", WizardCallbackData.Cancel()) },
|
||||
}));
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderTitle() => (
|
||||
"📝 Введите название игры одним сообщением.",
|
||||
BackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderDescription() => (
|
||||
"📄 Введите описание (или «-», чтобы пропустить).",
|
||||
SkipBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderCover() => (
|
||||
"🖼 Пришлите картинку как вложение или URL (или «-»).",
|
||||
SkipBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderSystem()
|
||||
/// <summary>
|
||||
/// Convert a flat list of <see cref="WizardAction"/>s into a
|
||||
/// Telegram keyboard. Each action is placed in its own row to
|
||||
/// preserve the pre-refactor visual layout.
|
||||
/// </summary>
|
||||
public static InlineKeyboardMarkup ToInlineKeyboard(IReadOnlyList<WizardAction> actions)
|
||||
{
|
||||
var buttons = new List<InlineKeyboardButton[]>
|
||||
if (actions.Count == 0)
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("D&D 5e", WizardCallbackData.Choice(WizardStepNames.System, "Dnd5e")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Pathfinder 2e", WizardCallbackData.Choice(WizardStepNames.System, "Pathfinder2e")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Call of Cthulhu",WizardCallbackData.Choice(WizardStepNames.System, "CallOfCthulhu7e")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("GURPS", WizardCallbackData.Choice(WizardStepNames.System, "GURPS")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Fate", WizardCallbackData.Choice(WizardStepNames.System, "Fate")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Другое… ✏️", WizardCallbackData.Choice(WizardStepNames.System, "_other")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("⏭ Пропустить", WizardCallbackData.Choice(WizardStepNames.System, "_skip")) },
|
||||
};
|
||||
return ("🎲 Выберите систему.", new InlineKeyboardMarkup(buttons).AppendBackCancel());
|
||||
}
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderDuration() => (
|
||||
"⏱ Выберите длительность.",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("3 часа", WizardCallbackData.Choice(WizardStepNames.Duration, "180")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("4 часа", WizardCallbackData.Choice(WizardStepNames.Duration, "240")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("5 часов", WizardCallbackData.Choice(WizardStepNames.Duration, "300")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("6 часов", WizardCallbackData.Choice(WizardStepNames.Duration, "360")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Другое… ✏️", WizardCallbackData.Choice(WizardStepNames.Duration, "_other")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("⏭ Пропустить", WizardCallbackData.Choice(WizardStepNames.Duration, "_skip")) },
|
||||
}).AppendBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderDateTime() => (
|
||||
"📅 Введите дату и время в формате ДД.ММ.ГГГГ ЧЧ:ММ (Москва).",
|
||||
BackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderCapacity() => (
|
||||
"👥 Введите лимит мест (1..50) одним числом.\nЗатем нажмите кнопку waitlist.",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("✅ Waitlist вкл", WizardCallbackData.Choice(WizardStepNames.Capacity, "waitlist:on")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Без waitlist", WizardCallbackData.Choice(WizardStepNames.Capacity, "waitlist:off")) },
|
||||
}).AppendBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderVisibility() => (
|
||||
"🔒 Выберите видимость.",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("🌐 Публичная в общем showcase", WizardCallbackData.Choice(WizardStepNames.Visibility, "public")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("🏠 Публичная в витрине клуба", WizardCallbackData.Choice(WizardStepNames.Visibility, "club")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("🔐 Только для членов клуба", WizardCallbackData.Choice(WizardStepNames.Visibility, "members")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("🏷 Выбрать клуб…", WizardCallbackData.Choice(WizardStepNames.Visibility, "pickclub")) },
|
||||
}).AppendBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderPickClub(IReadOnlyList<WizardClubOption> clubs)
|
||||
{
|
||||
if (clubs.Count == 0)
|
||||
{
|
||||
return (
|
||||
"🏷 У вас нет клубов. Создайте клуб в Web dashboard и вернитесь.",
|
||||
BackCancel());
|
||||
return new InlineKeyboardMarkup(Array.Empty<InlineKeyboardButton[]>());
|
||||
}
|
||||
var rows = new List<InlineKeyboardButton[]>();
|
||||
foreach (var club in clubs)
|
||||
var rows = new InlineKeyboardButton[actions.Count][];
|
||||
for (var i = 0; i < actions.Count; i++)
|
||||
{
|
||||
rows.Add(new[]
|
||||
rows[i] = new[]
|
||||
{
|
||||
InlineKeyboardButton.WithCallbackData(club.Name, WizardCallbackData.Choice(WizardStepNames.PickClub, club.ClubId.ToString()))
|
||||
});
|
||||
InlineKeyboardButton.WithCallbackData(actions[i].Label, actions[i].Payload),
|
||||
};
|
||||
}
|
||||
return ("🏷 Выберите клуб:", new InlineKeyboardMarkup(rows).AppendBackCancel());
|
||||
return new InlineKeyboardMarkup(rows);
|
||||
}
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderPublish() => (
|
||||
"✨ Опубликовать в витрине сейчас?",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("✅ Опубликовать", WizardCallbackData.Choice(WizardStepNames.Publish, "yes")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("📝 Только в чате", WizardCallbackData.Choice(WizardStepNames.Publish, "no")) },
|
||||
}).AppendBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderSingleConfirm(WizardPayload p)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("👀 Проверьте перед созданием:");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"🎲 {p.Title}");
|
||||
if (!string.IsNullOrEmpty(p.Description)) sb.AppendLine($"📄 {p.Description}");
|
||||
if (!string.IsNullOrEmpty(p.System)) sb.AppendLine($"🎲 Система: {p.System}");
|
||||
if (p.DurationMinutes.HasValue) sb.AppendLine($"⏱ Длительность: {p.DurationMinutes / 60} ч");
|
||||
if (p.Single?.ScheduledAt is { } at) sb.AppendLine($"📅 {at.FormatMoscow()} (МСК)");
|
||||
if (p.Single?.MaxPlayers is { } mp) sb.AppendLine($"👥 Мест: {mp}, waitlist {(p.Waitlist == true ? "вкл" : "выкл")}");
|
||||
sb.AppendLine($"🔒 Видимость: {RenderVisibilityText(p.Visibility)}");
|
||||
return (sb.ToString(), new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("✅ Создать", WizardCallbackData.Create()) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("⬅️ Назад", WizardCallbackData.Back()) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Отмена", WizardCallbackData.Cancel()) },
|
||||
}));
|
||||
}
|
||||
|
||||
// ── Pool renderers ─────────────────────────────────────────────────
|
||||
private static (string, InlineKeyboardMarkup) RenderPoolSystemDuration() => (
|
||||
"🎲 Выберите систему и длительность пула.",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("D&D 5e · 4 ч", WizardCallbackData.Choice(WizardStepNames.PoolSystemDuration, "Dnd5e:240")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Pathfinder 2e · 4 ч", WizardCallbackData.Choice(WizardStepNames.PoolSystemDuration, "Pathfinder2e:240")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Call of Cthulhu · 3 ч",WizardCallbackData.Choice(WizardStepNames.PoolSystemDuration, "CallOfCthulhu7e:180")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("GURPS · 4 ч", WizardCallbackData.Choice(WizardStepNames.PoolSystemDuration, "GURPS:240")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("Другое… ✏️", WizardCallbackData.Choice(WizardStepNames.PoolSystemDuration, "_custom")) },
|
||||
}).AppendBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderPoolAddSlots(WizardPayload p) => (
|
||||
$"📅 Слоты пула «{p.Title}»\n\nДобавлено: {(p.Pool?.Slots.Count ?? 0)}",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("➕ Добавить слот", WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "add")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("✅ Готово, к превью", WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "done")) },
|
||||
}).AppendBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderPoolSlotDateTime() => (
|
||||
"📅 Введите дату/время слота (ДД.ММ.ГГГГ ЧЧ:ММ).",
|
||||
BackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderPoolSlotCapacity() => (
|
||||
"👥 Введите лимит мест (1..50) и выберите waitlist.",
|
||||
new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("✅ Waitlist вкл", WizardCallbackData.Choice(WizardStepNames.PoolSlotCapacity, "waitlist:on")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Без waitlist", WizardCallbackData.Choice(WizardStepNames.PoolSlotCapacity, "waitlist:off")) },
|
||||
}).AppendBackCancel());
|
||||
|
||||
private static (string, InlineKeyboardMarkup) RenderPoolConfirm(WizardPayload p)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("👀 Проверьте пул перед созданием:");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"📝 {p.Title}");
|
||||
if (!string.IsNullOrEmpty(p.Description)) sb.AppendLine($"📄 {p.Description}");
|
||||
if (!string.IsNullOrEmpty(p.System)) sb.AppendLine($"🎲 Система: {p.System}");
|
||||
if (p.DurationMinutes.HasValue) sb.AppendLine($"⏱ Длительность: {p.DurationMinutes / 60} ч");
|
||||
sb.AppendLine($"🔒 Видимость: {RenderVisibilityText(p.Visibility)}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"Слоты ({p.Pool?.Slots.Count ?? 0}):");
|
||||
if (p.Pool is not null)
|
||||
{
|
||||
foreach (var s in p.Pool.Slots)
|
||||
{
|
||||
sb.AppendLine($" • {s.ScheduledAt.FormatMoscow()} — мест {s.MaxPlayers}, waitlist {(s.Waitlist ? "вкл" : "выкл")}");
|
||||
}
|
||||
}
|
||||
return (sb.ToString(), new InlineKeyboardMarkup(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("✅ Создать пул", WizardCallbackData.Create()) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("⬅️ Назад", WizardCallbackData.Back()) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Отмена", WizardCallbackData.Cancel()) },
|
||||
}));
|
||||
}
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────
|
||||
private static InlineKeyboardMarkup BackCancel() => new(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("⬅️ Назад", WizardCallbackData.Back()) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Отмена", WizardCallbackData.Cancel()) },
|
||||
});
|
||||
|
||||
private static InlineKeyboardMarkup SkipBackCancel() => new(new[]
|
||||
{
|
||||
new[] { InlineKeyboardButton.WithCallbackData("⏭ Пропустить", WizardCallbackData.Choice("Skip", "1")) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("⬅️ Назад", WizardCallbackData.Back()) },
|
||||
new[] { InlineKeyboardButton.WithCallbackData("❌ Отмена", WizardCallbackData.Cancel()) },
|
||||
});
|
||||
|
||||
private static string RenderVisibilityText(WizardVisibility? v) => v switch
|
||||
{
|
||||
WizardVisibility.Public => "публичная в общем showcase",
|
||||
WizardVisibility.Club => "публичная в витрине клуба",
|
||||
WizardVisibility.Members => "только для членов клуба",
|
||||
_ => "не задана",
|
||||
};
|
||||
}
|
||||
|
||||
internal static class InlineKeyboardMarkupExtensions
|
||||
{
|
||||
public static InlineKeyboardMarkup AppendBackCancel(this InlineKeyboardMarkup kb) => kb;
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
public static class WizardStepNames
|
||||
{
|
||||
public const string Type = "Type";
|
||||
public const string Title = "Title";
|
||||
public const string Description = "Description";
|
||||
public const string Cover = "Cover";
|
||||
public const string System = "System";
|
||||
public const string Duration = "Duration";
|
||||
public const string DateTime = "DateTime";
|
||||
public const string Capacity = "Capacity";
|
||||
public const string Visibility = "Visibility";
|
||||
public const string PickClub = "PickClub";
|
||||
public const string Publish = "Publish";
|
||||
public const string Confirm = "Confirm";
|
||||
|
||||
// Pool steps
|
||||
public const string PoolSystemDuration = "PoolSystemDuration";
|
||||
public const string PoolAddSlots = "PoolAddSlots";
|
||||
public const string PoolSlotDateTime = "PoolSlotDateTime";
|
||||
public const string PoolSlotCapacity = "PoolSlotCapacity";
|
||||
public const string PoolConfirm = "PoolConfirm";
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
public sealed class WizardStorageException : Exception
|
||||
{
|
||||
public WizardStorageException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
Reference in New Issue
Block a user