Unavailable store item message (#31)

This commit is contained in:
2023-05-17 23:12:15 +03:00
committed by GitHub
parent aef13b1883
commit d63113f58c
+20 -3
View File
@@ -106,12 +106,32 @@ public class Store : BotEventHandler
return; return;
} }
try
{
await PerformPurchase(mediaService, messageId);
}
catch (Exception e)
{
answer = "Товар недоступен";
await Bot.EditMessageTextAsync(Chat.Id,
messageId,
$"<b>{From.ToHtml()} попытался купить \"{storeItem.Name}\", но товара в наличии не оказалось.");
await AnswerQuery(query.Id, answer);
return;
}
reputation = await _reputation.SetUserReputationAsync(Chat, From, reputation - storeItem.Price); reputation = await _reputation.SetUserReputationAsync(Chat, From, reputation - storeItem.Price);
await Bot.EditMessageTextAsync(Chat.Id, await Bot.EditMessageTextAsync(Chat.Id,
messageId, messageId,
$"<b>{From.ToHtml()} ({reputation})</b> купил \"{storeItem.Name}\".", $"<b>{From.ToHtml()} ({reputation})</b> купил \"{storeItem.Name}\".",
ParseMode.Html); ParseMode.Html);
}
await AnswerQuery(query.Id, answer);
}
private async Task PerformPurchase(IRandomMediaService mediaService, int messageId)
{
var randomMedia = await mediaService!.GetRandomMediaAsync(); var randomMedia = await mediaService!.GetRandomMediaAsync();
var file = randomMedia.File; var file = randomMedia.File;
@@ -136,9 +156,6 @@ public class Store : BotEventHandler
} }
} }
await AnswerQuery(query.Id, answer);
}
private bool TryGetMediaService(string name, out IRandomMediaService? mediaService) private bool TryGetMediaService(string name, out IRandomMediaService? mediaService)
{ {
mediaService = _provider.GetServices<IRandomMediaService>() mediaService = _provider.GetServices<IRandomMediaService>()