mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Unavailable store item message (#31)
This commit is contained in:
@@ -106,12 +106,32 @@ public class Store : BotEventHandler
|
||||
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);
|
||||
await Bot.EditMessageTextAsync(Chat.Id,
|
||||
messageId,
|
||||
$"<b>{From.ToHtml()} ({reputation})</b> купил \"{storeItem.Name}\".",
|
||||
ParseMode.Html);
|
||||
}
|
||||
|
||||
await AnswerQuery(query.Id, answer);
|
||||
}
|
||||
|
||||
private async Task PerformPurchase(IRandomMediaService mediaService, int messageId)
|
||||
{
|
||||
var randomMedia = await mediaService!.GetRandomMediaAsync();
|
||||
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)
|
||||
{
|
||||
mediaService = _provider.GetServices<IRandomMediaService>()
|
||||
|
||||
Reference in New Issue
Block a user