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,38 +106,55 @@ 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);
|
||||||
|
|
||||||
var randomMedia = await mediaService!.GetRandomMediaAsync();
|
|
||||||
var file = randomMedia.File;
|
|
||||||
|
|
||||||
switch (randomMedia.Type)
|
|
||||||
{
|
|
||||||
case InputMediaType.Photo:
|
|
||||||
await Bot.SendPhotoAsync(Chat.Id, file,
|
|
||||||
caption: randomMedia.Caption,
|
|
||||||
replyToMessageId: messageId,
|
|
||||||
parseMode: ParseMode.Html,
|
|
||||||
hasSpoiler: randomMedia.Nsfw
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case InputMediaType.Video:
|
|
||||||
await Bot.SendVideoAsync(Chat.Id, file,
|
|
||||||
caption: randomMedia.Caption,
|
|
||||||
replyToMessageId: messageId,
|
|
||||||
parseMode: ParseMode.Html,
|
|
||||||
hasSpoiler: randomMedia.Nsfw
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await AnswerQuery(query.Id, answer);
|
await AnswerQuery(query.Id, answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task PerformPurchase(IRandomMediaService mediaService, int messageId)
|
||||||
|
{
|
||||||
|
var randomMedia = await mediaService!.GetRandomMediaAsync();
|
||||||
|
var file = randomMedia.File;
|
||||||
|
|
||||||
|
switch (randomMedia.Type)
|
||||||
|
{
|
||||||
|
case InputMediaType.Photo:
|
||||||
|
await Bot.SendPhotoAsync(Chat.Id, file,
|
||||||
|
caption: randomMedia.Caption,
|
||||||
|
replyToMessageId: messageId,
|
||||||
|
parseMode: ParseMode.Html,
|
||||||
|
hasSpoiler: randomMedia.Nsfw
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case InputMediaType.Video:
|
||||||
|
await Bot.SendVideoAsync(Chat.Id, file,
|
||||||
|
caption: randomMedia.Caption,
|
||||||
|
replyToMessageId: messageId,
|
||||||
|
parseMode: ParseMode.Html,
|
||||||
|
hasSpoiler: randomMedia.Nsfw
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetMediaService(string name, out IRandomMediaService? mediaService)
|
private bool TryGetMediaService(string name, out IRandomMediaService? mediaService)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user