Merge remote-tracking branch 'origin/main'

This commit is contained in:
2024-09-14 22:10:56 +03:30
4 changed files with 15 additions and 12 deletions

View File

@@ -7,12 +7,13 @@ namespace mstdnCats.Services
public sealed class PostResolver
{
public static async Task<List<Post>?> GetPostsAsync(string tag, ILogger<MastodonBot>? logger, string instance = "https://haminoa.net")
public static async Task<List<Post>?> GetPostsAsync(string tag, ILogger<MastodonBot>? logger, string instance)
{
// Get posts
HttpClient _httpClient = new HttpClient();
// Get posts from mastodon api (40 latest posts)
var response = await _httpClient.GetAsync($"{instance}/api/v1/timelines/tag/{tag}?limit=40");
string requestUrl = $"{instance}/api/v1/timelines/tag/{tag}?limit=40";
var response = await _httpClient.GetAsync(requestUrl);
// Print out ratelimit info
logger?.LogInformation("Remaining requests: " + response.Headers.GetValues("X-RateLimit-Remaining").First() + "time to reset: " + response.Headers.GetValues("X-RateLimit-Reset").First());

View File

@@ -7,13 +7,13 @@ namespace mstdnCats.Services
{
public class RunCheck
{
public static async Task<bool> runAsync(IDocumentCollection<Post> _db, TelegramBotClient _bot, string _tag, ILogger<MastodonBot>? logger, string _instance = "https://haminoa.net")
public static async Task<bool> runAsync(IDocumentCollection<Post> _db, TelegramBotClient _bot, string _tag, ILogger<MastodonBot>? logger, string _instance)
{
// Run check
try
{
//try
//{
// First get posts
var posts = await PostResolver.GetPostsAsync(_tag, logger, _instance);
var posts = await PostResolver.GetPostsAsync(_tag, logger, _instance??"https://haminoa.net");
if (posts == null)
{
@@ -22,11 +22,12 @@ namespace mstdnCats.Services
// Then process them
await ProcessPosts.checkAndInsertPostsAsync(_db, _bot, posts, logger);
}
catch (Exception ex)
{
logger?.LogCritical("Error while running check: " + ex.Message);
}
//}
//catch (Exception ex)
//{
// logger?.LogCritical("Error while running check: " + ex.Message);
// throw new Exception("Error while running check: " + ex.Message);
//}
return true;
}
}