Added more logging

This commit is contained in:
mahdium committed 2024-12-03 18:05:24 +03:30
1 parent 3e73caade3
commit 321f48660d
1 file changed
+14 -5
+14 -5
View File
@@ -45,8 +45,7 @@ namespace mstdnCats.Services
if (mediaAttachment != null) if (mediaAttachment != null)
{ {
// Check if the media attachment is already approved // Check if the media attachment is already approved
bool isAlreadyApproved = mediaAttachment.Approved; if (mediaAttachment.Approved){
if (isAlreadyApproved){
await _bot.AnswerCallbackQuery(callbackQuery.Id, "Media attachment is already approved.",true); await _bot.AnswerCallbackQuery(callbackQuery.Id, "Media attachment is already approved.",true);
return; return;
} }
@@ -57,16 +56,26 @@ namespace mstdnCats.Services
if (updated) if (updated)
{
try
{ {
// Send the media attachment to the channel // Send the media attachment to the channel
await _bot.SendPhoto(config.CHANNEL_NUMID, allMediaAttachments.First(m => m.MediaId == mediaId).Url, caption: $"Post from " + $"<a href=\"" + post.Account.Url + "\">" + post.Account.DisplayName + " </a>", parseMode: ParseMode.Html await _bot.SendPhoto(config.CHANNEL_NUMID,
allMediaAttachments.First(m => m.MediaId == mediaId).Url,
caption: $"Post from " + $"<a href=\"" + post.Account.Url + "\">" +
post.Account.DisplayName + " </a>", parseMode: ParseMode.Html
, replyMarkup: new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl("View on Mastodon", post.Url))); , replyMarkup: new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl("View on Mastodon", post.Url)));
await _bot.AnswerCallbackQuery(callbackQuery.Id, "Media attachment approved and sent to channel."); await _bot.AnswerCallbackQuery(callbackQuery.Id,
"Media attachment approved and sent to channel.");
await _bot.DeleteMessage(callbackQuery.Message.Chat.Id, callbackQuery.Message.Id); await _bot.DeleteMessage(callbackQuery.Message.Chat.Id, callbackQuery.Message.Id);
logger?.LogTrace($"Media attachment {mediaId} approved."); logger?.LogTrace($"Media attachment {mediaId} approved.");
}
catch (Exception e)
{
logger?.LogError($"Error while sending image to the channel:{e}");
}
} }
else else
{ {